@@ -53,7 +53,7 @@ All unknown options are passed to the compiler.
53
53
auto text = inputFile.readText;
54
54
55
55
// for now only non-package modules are supported
56
- if (! inputFile.endsWith(" package.d " , " index.d" ))
56
+ if (! inputFile.endsWith(" index.d" ))
57
57
// replace only works with 2.078.1, see: https://github.com/dlang/phobos/pull/6017
58
58
args = args[0 .. pos].chain(" -" .only, args[pos.. $].dropOne).array;
59
59
@@ -69,34 +69,39 @@ All unknown options are passed to the compiler.
69
69
70
70
string [string ] macros;
71
71
macros[" SRC_FILENAME" ] = " %s\n " .format(inputFile.buildNormalizedPath);
72
- return compile (text, args, macros);
72
+ return compile (text, args, inputFile, macros);
73
73
}
74
74
75
- static auto createTmpFile ( string buffer = null , string extension = " .d " )
75
+ auto createTmpDir ( )
76
76
{
77
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;
78
+ auto dir = tempDir.buildPath(" ddoc_preprocessor_" ~ randomUUID.toString.replace(" -" , " " ));
79
+ mkdir(dir);
80
+ return dir;
82
81
}
83
82
84
- auto compile (R)(R buffer, string [] arguments, string [string ] macros = null )
83
+ auto compile (R)(R buffer, string [] arguments, string inputFile, string [string ] macros = null )
85
84
{
86
85
import core.time : usecs;
87
86
import core.thread : Thread ;
88
87
import std.process : pipeProcess, Redirect, wait;
89
88
auto args = [config.dmdBinPath] ~ arguments;
90
89
91
- string [] tmpFiles = [createTmpFile(buffer, " .d" )];
92
- args = args.replace(" -" , tmpFiles[$ - 1 ]);
93
- scope (exit) tmpFiles.each! remove;
90
+ // Note: ideally we could pass in files directly on stdin.
91
+ // However, for package.d files, we need to imitate package directory layout to avoid conflicts
92
+ auto tmpDir = createTmpDir;
93
+ auto inputTmpFile = tmpDir.buildPath(inputFile);
94
+ inputTmpFile.dirName.mkdirRecurse;
95
+ std.file.write (inputTmpFile, buffer);
96
+ args = args.replace(" -" , inputTmpFile);
97
+ scope (exit) tmpDir.rmdirRecurse;
94
98
95
99
if (macros ! is null )
96
100
{
97
101
auto macroString = macros.byPair.map! (a => " %s=%s" .format(a[0 ], a[1 ])).join(" \n " );
98
- args ~= createTmpFile(macroString, " .ddoc" );
99
- tmpFiles ~= args[$ - 1 ];
102
+ auto macroFile = tmpDir.buildPath(" macros.ddoc" );
103
+ std.file.write (macroFile, macroString);
104
+ args ~= macroFile;
100
105
}
101
106
102
107
foreach (arg; [" -c" , " -o-" ])
0 commit comments