1 module gccbuild.patch;
2 
3 import scriptlike, gccbuild;
4 
5 void patchSources()
6 {
7     startSectionLog("Dumping patch directories");
8     foreach (entry; patchDirectories)
9         writeBulletPointLog(entry.toString());
10     endSectionLog();
11 
12     startSection("Patching sources");
13     foreach (name, component; build.configuredComponents)
14     {
15         patchComponent(component);
16     }
17 
18     if (!gdcSourcePath.empty && build.gcc.wasExtracted)
19     {
20         writeBulletPoint("Merging GDC into GCC");
21         auto oldCWD = pushCWD(Path(gdcSourcePath));
22         runCollectLog("./setup-gcc.sh " ~ build.gcc.sourceFolder.toString());
23         endBulletPoint();
24     }
25     endSection();
26 }
27 
28 void patchComponent(Component component)
29 {
30     if (!component.wasExtracted)
31         writeBulletPoint(component.baseDirName.toString() ~ "... (skipped)");
32     else
33     {
34         writeBulletPoint(component.baseDirName.toString());
35         auto patches = getPatchList(component);
36 
37         auto oldCWD = pushCWD(component.sourceFolder);
38         foreach (entry; patches)
39             runCollectLog("patch -p1 -i " ~ entry);
40         endBulletPoint();
41     }
42 }
43 
44 string[] getPatchList(Component component)
45 {
46     string[string] patches;
47 
48     foreach (patchDir; patchDirectories)
49     {
50         patchDir = patchDir ~ component.baseDirName;
51         if (!patchDir.exists)
52             continue;
53 
54         foreach (entry; patchDir.dirEntries(SpanMode.shallow))
55         {
56             // Allow later directories to overwrite patch
57             patches[entry.baseName] = entry;
58         }
59     }
60 
61     auto sorted = patches.values.dup;
62     sorted.sort!((a, b) => a.baseName < b.baseName);
63 
64     yapFunc(sorted);
65     return sorted;
66 }