@@ -53,7 +53,7 @@ All unknown options are passed to the compiler.
5353 auto text = inputFile.readText;
5454
5555 // for now only non-package modules are supported
56- if (! inputFile.endsWith(" package.d " , " index.d" ))
56+ if (! inputFile.endsWith(" index.d" ))
5757 // replace only works with 2.078.1, see: https://github.com/dlang/phobos/pull/6017
5858 args = args[0 .. pos].chain(" -" .only, args[pos.. $].dropOne).array;
5959
@@ -69,34 +69,39 @@ All unknown options are passed to the compiler.
6969
7070 string [string ] macros;
7171 macros[" SRC_FILENAME" ] = " %s\n " .format(inputFile.buildNormalizedPath);
72- return compile (text, args, macros);
72+ return compile (text, args, inputFile, macros);
7373}
7474
75- static auto createTmpFile ( string buffer = null , string extension = " .d " )
75+ auto createTmpDir ( )
7676{
7777 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;
8281}
8382
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 )
8584{
8685 import core.time : usecs;
8786 import core.thread : Thread ;
8887 import std.process : pipeProcess, Redirect, wait;
8988 auto args = [config.dmdBinPath] ~ arguments;
9089
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;
9498
9599 if (macros ! is null )
96100 {
97101 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;
100105 }
101106
102107 foreach (arg; [" -c" , " -o-" ])
0 commit comments