| 1 |
#!/usr/bin/env dub |
| 2 |
/++dub.sdl: |
| 3 |
name "gen_druntime_sources" |
| 4 |
+/ |
| 5 |
// Written in the D programming language. |
| 6 |
import std.stdio; |
| 7 |
import std.file; |
| 8 |
import std.path; |
| 9 |
import std.range; |
| 10 |
import std.string; |
| 11 |
import std.algorithm; |
| 12 |
|
| 13 |
string[] filterList = [ |
| 14 |
"./Makefile.in", "./Makefile.am", |
| 15 |
"./gcc/config.d.in", "./gcc/libbacktrace.d.in", "./gcc/drtstuff.c", |
| 16 |
"./LICENSE.txt", "./MERGE", |
| 17 |
"./rt/dylib_fixes.c" |
| 18 |
]; |
| 19 |
|
| 20 |
struct Files |
| 21 |
{ |
| 22 |
string[] baseList, cppList; |
| 23 |
string[][string] sysList; |
| 24 |
} |
| 25 |
|
| 26 |
void main(string[] args) |
| 27 |
{ |
| 28 |
Files[string] fileMap; |
| 29 |
|
| 30 |
foreach(entry; ".".dirEntries(SpanMode.depth).filter!(a => !filterList.canFind(a))) |
| 31 |
{ |
| 32 |
if (entry.name.startsWith("./config/")) |
| 33 |
continue; |
| 34 |
|
| 35 |
if(entry.isFile) |
| 36 |
{ |
| 37 |
auto ext = entry.extension.empty ? "" : entry.extension[1 .. $]; |
| 38 |
if(!(ext in fileMap)) |
| 39 |
fileMap[ext] = Files.init; |
| 40 |
|
| 41 |
string sentry = entry[2 .. $]; |
| 42 |
|
| 43 |
if(entry.name.startsWith("./core/stdcpp/")) |
| 44 |
fileMap[ext].cppList ~= sentry; |
| 45 |
else if(entry.name.startsWith("./core/sys/")) |
| 46 |
{ |
| 47 |
auto components = entry.pathSplitter; |
| 48 |
components.popFrontN(3); |
| 49 |
fileMap[ext].sysList[components.front] ~= sentry; |
| 50 |
} |
| 51 |
else |
| 52 |
fileMap[ext].baseList ~= sentry; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
foreach(extEntry; fileMap.byKeyValue.array.sort!"a.key < b.key") |
| 57 |
{ |
| 58 |
auto ext = extEntry.key; |
| 59 |
auto value = extEntry.value; |
| 60 |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES", value.baseList); |
| 61 |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES_STDCXX", value.cppList); |
| 62 |
foreach(entry; value.sysList.byKeyValue.array.sort!"a.key < b.key") |
| 63 |
{ |
| 64 |
writeList("DRUNTIME_" ~ ext.toUpper() ~ "SOURCES_" ~ entry.key.toUpper(), entry.value); |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
void writeList(string name, string[] values, bool force = false) |
| 70 |
{ |
| 71 |
if (!force && values.empty) |
| 72 |
return; |
| 73 |
|
| 74 |
values = sort(values).array(); |
| 75 |
writeln(); |
| 76 |
writef("%s =", name); |
| 77 |
size_t line = name.length + 3; |
| 78 |
foreach(entry; values) |
| 79 |
{ |
| 80 |
if(line + entry.length > 70) |
| 81 |
{ |
| 82 |
line = 0; |
| 83 |
writeln(` \`); |
| 84 |
write('\t'); |
| 85 |
} |
| 86 |
else |
| 87 |
write(" "); |
| 88 |
write(entry); |
| 89 |
line += entry.length + 1; |
| 90 |
} |
| 91 |
writeln(); |
| 92 |
} |