Last active
November 12, 2023 11:03
-
-
Save jpf91/8ad1dbc9902d6ad876313f134c6527d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio, std.file, std.path, std.range, std.string, std.algorithm ; | |
string[] filterList = ["./test_runner.d", "./Makefile.in", "./gcc/config.d.in", "./gcc/libbacktrace.d.in", "./phobos-ver-syms.in", | |
"./Makefile.am", "./LICENSE_1_0.txt", "./README.txt", "./rt/dylib_fixes.c"]; | |
struct Files | |
{ | |
string[] baseList, gcList, gcStubList; | |
string[][string] sysList; | |
} | |
void main(string[] args) | |
{ | |
Files[string] fileMap; | |
foreach(entry; ".".dirEntries(SpanMode.depth).filter!(a => !filterList.canFind(a))) | |
{ | |
if(entry.isFile) | |
{ | |
auto ext = entry.extension.empty ? "" : entry.extension[1 .. $]; | |
if(!(ext in fileMap)) | |
fileMap[ext] = Files.init; | |
string sentry = entry[2 .. $]; | |
if(entry.name.startsWith("./gc/")) | |
fileMap[ext].gcList ~= sentry; | |
else if(entry.name.startsWith("./gcstub/")) | |
fileMap[ext].gcStubList ~= sentry; | |
else if(entry.name.startsWith("./core/sys/")) | |
{ | |
auto components = entry.pathSplitter; | |
components.popFrontN(3); | |
fileMap[ext].sysList[components.front] ~= sentry; | |
} | |
else | |
fileMap[ext].baseList ~= sentry; | |
} | |
} | |
foreach(extEntry; fileMap.byKeyValue) | |
{ | |
auto ext = extEntry.key; | |
auto value = extEntry.value; | |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES", value.baseList); | |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES_GC", value.gcList); | |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES_GCSTUB", value.gcStubList); | |
foreach(entry; value.sysList.byKeyValue) | |
{ | |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES_" ~ entry.key.toUpper(), entry.value); | |
} | |
} | |
} | |
void writeList(string name, string[] values) | |
{ | |
if(values.empty) | |
return; | |
values = sort(values).array(); | |
writef("%s =", name); | |
size_t line = name.length + 3; | |
foreach(entry; values) | |
{ | |
if(line + entry.length > 70) | |
{ | |
line = 0; | |
writeln(` \`); | |
write('\t'); | |
} | |
else | |
write(" "); | |
write(entry); | |
line += entry.length + 1; | |
} | |
writeln(); | |
writeln(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment