@@ -5,18 +5,29 @@ import std.algorithm;
5
5
import std.file ;
6
6
import std.stdio ;
7
7
import std.exception ;
8
-
8
+ import std.path ;
9
9
void compileToPath (string compileThis, string outputPath, bool loud = false )
10
10
{
11
+ import std.compiler ;
11
12
import core.stdc.stdlib ;
13
+ string [string ] contextMacros;
14
+ contextMacros[" DVER" ] = format! " %u.%03u" (version_major, version_minor);
12
15
if (outputPath.indexOf(" cozum" ) == - 1 )
13
16
{
14
- if (loud)
15
- writeln(outputPath.replace(" .html" , " .cozum.html" ));
17
+ // We need to build a little .ddoc file to set the right predefined build macros - these are context dependant.
18
+
19
+ const cozumHtml = outputPath.baseName.replace(" .html" , " .cozum.html" );
20
+ contextMacros[" COZUM_HTML" ] = cozumHtml;
16
21
// exit(0);
17
22
}
23
+ auto macroOut = File (" contextMacros.ddoc" , " w" );
18
24
19
- const compileString = format! " dmd -revert=markdown -D macros.ddoc html.ddoc dlang.org.ddoc doc.ddoc aliBook.ddoc %s -Df%s " (compileThis, outputPath);
25
+ foreach (key, value; contextMacros)
26
+ {
27
+ macroOut.writefln! " %s = %s" (key, value);
28
+ }
29
+ macroOut.flush();
30
+ const compileString = format! " dmd -revert=markdown -D contextMacros.ddoc macros.ddoc html.ddoc dlang.org.ddoc doc.ddoc aliBook.ddoc %s -Df%s " (compileThis, outputPath);
20
31
if (loud)
21
32
writefln! " %s:%s |> %s" (compileThis, outputPath, compileString);
22
33
const res = executeShell(compileString);
@@ -36,15 +47,14 @@ int main(string[] args)
36
47
const jobs = args.length == 2 ? args[1 ].to! ubyte : 1 ;
37
48
const outDir = " ../web/book" ;
38
49
writeln(" Building the book at " , outDir);
39
- // scope(failure) return 1;
40
50
41
51
enforce(executeShell(" which dmd" ).output != " " , " dmd doesn't seem to be present" );
42
52
if (outDir.exists) {
43
53
executeShell(" rm -rf " ~ outDir);
44
54
}
45
55
dirEntries(" d.en" , " *.d" , SpanMode.shallow)
46
56
.map! (dFile => tuple(dFile.name, buildPath(outDir, baseName(dFile).setExtension(" html" ))))
47
- .parallel(jobs)
57
+ // .parallel(jobs)
48
58
.each! (elem => compileToPath(elem.tupleof));
49
59
dirEntries(" d.en" , " *.png" , SpanMode.shallow)
50
60
.each! (p => copy(p, buildPath(outDir, baseName(p).setExtension(" png" ))));
0 commit comments