@@ -63,30 +63,41 @@ All unknown options are passed to the compiler.
63
63
text = genChangelogVersion(inputFile, text);
64
64
text = genSwitches(text);
65
65
66
- if (inputFile.endsWith(" .d" ))
66
+ // Phobos index.d should have been named index.dd
67
+ if (inputFile.endsWith(" .d" ) && ! inputFile.endsWith(" index.d" ))
67
68
text = assertWritelnModule(text);
68
69
69
- // inject custom, "dynamic" macros
70
- if (inputFile.endsWith(" .dd" , " index.d" ))
71
- text ~= " \n SRC_FILENAME=%s\n " .format(inputFile.buildNormalizedPath);
72
- else if (inputFile.endsWith(" .d" ))
73
- text ~= " /**\n Macros:\n\n SRC_FILENAME=%s\n */" .format(inputFile.buildNormalizedPath);
74
- return compile (text, args);
70
+ string [string ] macros;
71
+ macros[" SRC_FILENAME" ] = " %s\n " .format(inputFile.buildNormalizedPath);
72
+ return compile (text, args, macros);
75
73
}
76
74
77
- auto compile (R)(R buffer, string [] arguments)
75
+ static auto createTmpFile (string buffer = null , string extension = " .d" )
76
+ {
77
+ import std.uuid : randomUUID;
78
+ auto name = tempDir.buildPath(" ddoc_preprocessor_" ~ randomUUID.toString.replace(" -" , " " ) ~ extension);
79
+ if (buffer ! is null )
80
+ std.file.write (name, buffer);
81
+ return name;
82
+ }
83
+
84
+ auto compile (R)(R buffer, string [] arguments, string [string ] macros = null )
78
85
{
79
86
import core.time : usecs;
80
87
import core.thread : Thread ;
81
88
import std.process : pipeProcess, Redirect, wait;
82
89
auto args = [config.dmdBinPath] ~ arguments;
83
90
84
- import std.file : write, tempDir;
85
- import std.uuid : randomUUID;
86
- auto fileName = tempDir.buildPath(" ddoc_preprocessor_" ~ randomUUID.toString.replace(" -" , " " ) ~ " .d" );
87
- std.file.write (fileName, buffer);
88
- scope (exit) fileName.remove;
89
- args = args.replace(" -" , fileName);
91
+ string [] tmpFiles = [createTmpFile(buffer, " .d" )];
92
+ args = args.replace(" -" , tmpFiles[$ - 1 ]);
93
+ scope (exit) tmpFiles.each! remove;
94
+
95
+ if (macros ! is null )
96
+ {
97
+ auto macroString = macros.byPair.map! (a => " %s=%s" .format(a[0 ], a[1 ])).join(" \n " );
98
+ args ~= createTmpFile(macroString, " .ddoc" );
99
+ tmpFiles ~= args[$ - 1 ];
100
+ }
90
101
91
102
foreach (arg; [" -c" , " -o-" ])
92
103
{
0 commit comments