Skip to content

Commit 1389172

Browse files
committed
Add initial version of the Ddoc wrapper
1 parent a18fe3d commit 1389172

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

ddoc.d

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env rdmd
2+
/**
3+
A wrapper around DDoc to allow custom extensions
4+
5+
Copyright: D Language Foundation 2018
6+
7+
License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
8+
9+
Example usage:
10+
11+
---
12+
./ddoc --compiler=<path-to-dmd> --output=out.html myfile.dd
13+
---
14+
15+
Author: Sebastian Wilzbach
16+
*/
17+
import std.stdio;
18+
19+
struct Config
20+
{
21+
string dmdBinPath = "dmd";
22+
string outputFile;
23+
}
24+
Config config;
25+
26+
int main(string[] args)
27+
{
28+
import std.getopt;
29+
auto helpInformation = getopt(
30+
args,
31+
"compiler", "Compiler to use", &config.dmdBinPath,
32+
"o|output", "Output file", &config.outputFile,
33+
);
34+
35+
assert(config.outputFile, "An output file is required.");
36+
assert(args.length > 1, "An input file is required.");
37+
38+
if (helpInformation.helpWanted)
39+
{
40+
`DDoc wrapper
41+
./ddoc <file>...
42+
`.defaultGetoptPrinter(helpInformation.options);
43+
return 1;
44+
}
45+
46+
import std.file : readText;
47+
auto text = args[$ - 1].readText;
48+
return compile(text, args[1 .. $ - 1]);
49+
}
50+
51+
auto compile(R)(R buffer, string[] arguments)
52+
{
53+
import std.process : pipeProcess, Redirect, wait;
54+
auto args = [config.dmdBinPath, "-c", "-Df"~config.outputFile, "-o-"] ~ arguments;
55+
args ~= "-";
56+
auto pipes = pipeProcess(args, Redirect.stdin);
57+
pipes.stdin.write(buffer);
58+
pipes.stdin.close;
59+
return wait(pipes.pid);
60+
}

posix.mak

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ DDOC_VARS_PRERELEASE_VERBATIM=$(DDOC_VARS_PRERELEASE) \
277277
DOC_OUTPUT_DIR="$W/phobos-prerelease-verbatim" \
278278
STDDOC="$(PWD)/verbatim.ddoc"
279279

280+
################################################################################
281+
# Ddoc binaries
282+
################################################################################
283+
284+
DDOC_BIN:=$G/ddoc
285+
280286
################################################################################
281287
# Resources
282288
################################################################################
@@ -460,8 +466,8 @@ $W/changelog/pending.html : changelog/pending.dd $(CHANGELOG_PENDING_DDOC) $(DMD
460466
$W/changelog/%.html : changelog/%.dd $(CHANGELOG_DDOC) $(DMD)
461467
$(DMD) -conf= -c -o- -Df$@ $(CHANGELOG_DDOC) $<
462468

463-
$W/spec/%.html : spec/%.dd $(SPEC_DDOC) $(DMD)
464-
$(DMD) -c -o- -Df$@ $(SPEC_DDOC) $<
469+
$W/spec/%.html : spec/%.dd $(SPEC_DDOC) $(DMD) $(DDOC_BIN)
470+
$(DDOC_BIN) --compiler=$(DMD) -o$@ $(SPEC_DDOC) $<
465471

466472
$W/404.html : 404.dd $(DDOC) $(DMD)
467473
$(DMD) -conf= -c -o- -Df$@ $(DDOC) errorpage.ddoc $<
@@ -947,4 +953,15 @@ $G/contributors_list.ddoc: | $(STABLE_RDMD) $(TOOLS_DIR) $(INSTALLER_DIR)
947953
echo "D_CONTRIBUTORS=" >> $@
948954
cat $G/contributors_list.tmp >> $@
949955

956+
################################################################################
957+
# Custom DDoc wrapper
958+
# ------------------
959+
#
960+
# This allows extending Ddoc files dynamically on-the-fly.
961+
# It is currently only used for the specification pages
962+
################################################################################
963+
964+
$(DDOC_BIN): ddoc.d | $(STABLE_DMD)
965+
$(STABLE_DMD) -of$@ $<
966+
950967
.DELETE_ON_ERROR: # GNU Make directive (delete output files on error)

0 commit comments

Comments
 (0)