@@ -41,6 +41,30 @@ void runShell(string cmd)
41
41
}
42
42
}
43
43
44
+ alias LineTransformer = string delegate (const string line);
45
+ string patchLines (string inFile, string outFile, LineTransformer lineTransformer)
46
+ {
47
+ const lines = std.file.readText (inFile).splitLines;
48
+
49
+ bool transformed = false ;
50
+ const newLines = lines.map! ((const string line)
51
+ {
52
+ const newLine = lineTransformer(line);
53
+ if (newLine ! is line)
54
+ transformed = true ;
55
+ return newLine;
56
+ }).array;
57
+
58
+ if (! transformed)
59
+ return inFile;
60
+
61
+ version (verbose)
62
+ writeln(` Patching file "` ~ inFile ~ ` " to "` ~ outFile ~ ` "` );
63
+
64
+ std.file.write (outFile, newLines.join(" \n " ));
65
+ return outFile;
66
+ }
67
+
44
68
// Preprocesses a 'foo.def.in' file to 'foo.def'.
45
69
void generateDef (string inFile, string outFile)
46
70
{
@@ -51,47 +75,39 @@ void generateDef(string inFile, string outFile)
51
75
52
76
void sanitizeDef (string defFile)
53
77
{
54
- const lines = std.file.readText (defFile).splitLines;
55
-
56
- bool touched = false ;
57
- const newLines = lines.map! ((const string line)
78
+ patchLines(defFile, defFile, (line)
58
79
{
59
- string l = line;
60
-
61
- if (l == " LIBRARY vcruntime140_app" )
62
- l = ` LIBRARY "VCRUNTIME140.dll"` ;
80
+ if (line == " LIBRARY vcruntime140_app" )
81
+ return ` LIBRARY "vcruntime140.dll"` ;
63
82
64
83
// The MinGW-w64 .def files specify weak external symbols as 'alias == realName'.
65
- if (l .length > 1 && l [0 ] != ' ;' )
84
+ if (line .length > 1 && line [0 ] != ' ;' )
66
85
{
67
- const i = l .indexOf(" == " );
86
+ const i = line .indexOf(" == " );
68
87
if (i > 0 )
69
88
{
70
- const weakName = l[0 .. i];
71
- const realName = l[i+ 4 .. $];
72
- weakSymbols[weakName] = realName;
73
-
74
- l = " ;" ~ l;
89
+ const weakName = line[0 .. i];
90
+ const realName = line[i+ 4 .. $];
91
+
92
+ if (weakName.indexOf(' ' ) < 0 && realName.indexOf(' ' ) < 0 )
93
+ {
94
+ weakSymbols[weakName] = realName;
95
+ return " ;" ~ line;
96
+ }
75
97
}
76
98
}
77
99
78
100
// Don't export function 'atexit'; we have our own in msvc_atexit.c.
79
- if (l == " atexit" /* msvcr120 */ || l == " atexit DATA " /* < 120 */ )
80
- l = " " ;
101
+ if (line == " atexit" )
102
+ return " " ;
81
103
82
104
// Do export function '__chkstk' (ntdll.dll).
83
105
// LLVM emits calls to it to detect stack overflows with '_alloca'.
84
- if (l == " ;__chkstk" )
85
- l = " __chkstk" ;
86
-
87
- if (l ! is line)
88
- touched = true ;
89
-
90
- return l;
91
- }).array;
106
+ if (line == " ;__chkstk" )
107
+ return " __chkstk" ;
92
108
93
- if (touched)
94
- std.file.write (defFile, newLines.join( " \n " ) );
109
+ return line;
110
+ } );
95
111
}
96
112
97
113
void copyDefs (string inDir, string outDir)
0 commit comments