Skip to content

Commit

Permalink
allow to specify ddox tool
Browse files Browse the repository at this point in the history
- can be used to customize the ddox tool (and it's output)
- assumes similar commands/behavior
  • Loading branch information
MartinNowak committed Sep 30, 2015
1 parent 79c4c6e commit d2549f8
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 40 deletions.
72 changes: 35 additions & 37 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -734,54 +734,52 @@ class Dub {
{
if (m_dryRun) return;

auto ddox_pack = m_packageManager.getBestPackage("ddox", ">=0.0.0");
if (!ddox_pack) ddox_pack = m_packageManager.getBestPackage("ddox", "~master");
if (!ddox_pack) {
logInfo("DDOX is not present, getting it and storing user wide");
ddox_pack = fetch("ddox", Dependency(">=0.0.0"), defaultPlacementLocation, FetchOptions.none);
// allow to choose a custom ddox tool
auto tool = m_project.rootPackage.info.ddoxTool;
if (tool.empty) tool = "ddox";

auto tool_pack = m_packageManager.getBestPackage(tool, ">=0.0.0");
if (!tool_pack) tool_pack = m_packageManager.getBestPackage(tool, "~master");
if (!tool_pack) {
logInfo("% is not present, getting and storing it user wide", tool);
tool_pack = fetch(tool, Dependency(">=0.0.0"), defaultPlacementLocation, FetchOptions.none);
}

version(Windows) auto ddox_exe = "ddox.exe";
else auto ddox_exe = "ddox";
auto ddox_dub = new Dub(m_packageSuppliers);
ddox_dub.loadPackage(tool_pack.path);
ddox_dub.upgrade(UpgradeOptions.select);

if( !existsFile(ddox_pack.path~ddox_exe) ){
logInfo("DDOX in %s is not built, performing build now.", ddox_pack.path.toNativeString());
auto compiler_binary = this.defaultCompiler;

auto ddox_dub = new Dub(m_packageSuppliers);
ddox_dub.loadPackage(ddox_pack.path);
ddox_dub.upgrade(UpgradeOptions.select);
GeneratorSettings settings;
settings.config = "application";
settings.compiler = getCompiler(compiler_binary); // TODO: not using --compiler ???
settings.platform = settings.compiler.determinePlatform(settings.buildSettings, compiler_binary);
settings.buildType = "debug";
settings.run = true;

auto compiler_binary = this.defaultCompiler;

GeneratorSettings settings;
settings.config = "application";
settings.compiler = getCompiler(compiler_binary);
settings.platform = settings.compiler.determinePlatform(settings.buildSettings, compiler_binary);
settings.buildType = "debug";
ddox_dub.generateProject("build", settings);
auto filterargs = m_project.rootPackage.info.ddoxFilterArgs.dup;
if (filterargs.empty) filterargs = ["--min-protection=Protected", "--only-documented"];

//runCommands(["cd "~ddox_pack.path.toNativeString()~" && dub build -v"]);
}
settings.runArgs = "filter" ~ filterargs ~ "docs.json";
ddox_dub.generateProject("build", settings);

auto p = ddox_pack.path;
auto p = tool_pack.path;
p.endsWithSlash = true;
auto dub_path = p.toNativeString();

string[] commands;
string[] filterargs = m_project.rootPackage.info.ddoxFilterArgs.dup;
if (filterargs.empty) filterargs = ["--min-protection=Protected", "--only-documented"];
commands ~= dub_path~"ddox filter "~filterargs.join(" ")~" docs.json";
if (!run) {
commands ~= dub_path~"ddox generate-html --navigation-type=ModuleTree docs.json docs";
version(Windows) commands ~= "xcopy /S /D "~dub_path~"public\\* docs\\";
else commands ~= "rsync -ru '"~dub_path~"public/' docs/";
}
runCommands(commands);
auto tool_path = p.toNativeString();

if (run) {
auto proc = spawnProcess([dub_path~"ddox", "serve-html", "--navigation-type=ModuleTree", "docs.json", "--web-file-dir="~dub_path~"public"]);
settings.runArgs = ["serve-html", "--navigation-type=ModuleTree", "docs.json", "--web-file-dir="~tool_path~"public"];
browse("http://127.0.0.1:8080/");
wait(proc);
} else {
settings.runArgs = ["generate-html", "--navigation-type=ModuleTree", "docs.json", "docs"];
}
ddox_dub.generateProject("build", settings);

if (!run) {
// TODO: ddox should copy those files itself
version(Windows) runCommand("xcopy /S /D "~tool_path~"public\\* docs\\");
else runCommand("rsync -ru '"~tool_path~"public/' docs/");
}
}

Expand Down
5 changes: 5 additions & 0 deletions source/dub/internal/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ bool existsDirectory(Path path) {
return fi.isDirectory;
}

void runCommand(string command, string[string] env = null)
{
runCommands((&command)[0 .. 1], env);
}

void runCommands(in string[] commands, string[string] env = null)
{
import std.stdio : stdin, stdout, stderr, File;
Expand Down
1 change: 1 addition & 0 deletions source/dub/recipe/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void parseJson(ref PackageRecipe recipe, Json json, string parent_name)
}
break;
case "-ddoxFilterArgs": recipe.ddoxFilterArgs = deserializeJson!(string[])(value); break;
case "-ddoxTool": recipe.ddoxTool = value.get!string; break;
}
}

Expand Down
1 change: 1 addition & 0 deletions source/dub/recipe/packagerecipe.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct PackageRecipe {
string copyright;
string license;
string[] ddoxFilterArgs;
string ddoxTool;
BuildSettingsTemplate buildSettings;
ConfigurationInfo[] configurations;
BuildSettingsTemplate[string] buildTypes;
Expand Down
7 changes: 4 additions & 3 deletions source/dub/recipe/sdl.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void parseSDL(ref PackageRecipe recipe, Tag sdl, string parent_name)
recipe.buildTypes[name] = bt;
break;
case "x:ddoxFilterArgs": recipe.ddoxFilterArgs ~= n.stringArrayTagValue; break;
case "x:ddoxTool": recipe.ddoxTool = n.stringTagValue; break;
}
}

Expand Down Expand Up @@ -357,7 +358,7 @@ lflags "lf3"
}

unittest { // test platform identifiers
auto sdl =
auto sdl =
`name "testproject"
dflags "-a" "-b" platform="windows-x86"
dflags "-c" platform="windows-x86"
Expand Down Expand Up @@ -391,8 +392,8 @@ unittest { // test single value fields
`name "hello" {
world
}`, null, "testfile"));
assertThrown!Exception(parseSDL(rec,
assertThrown!Exception(parseSDL(rec,
`name ""
versions "hello" 10`
, null, "testfile"));
}
}
12 changes: 12 additions & 0 deletions test/ddox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e -o pipefail

(cd $CURR_DIR/ddox/default && $DUB build -b ddox)
grep -qF ddox_project $CURR_DIR/ddox/default/docs/index.html

$DUB add-local $CURR_DIR/ddox/custom-tool
(cd $CURR_DIR/ddox/custom && $DUB build -b ddox)
grep -qF custom-tool $CURR_DIR/ddox/custom/docs/custom_tool_output
diff $CURR_DIR/ddox/custom-tool/public/copied $CURR_DIR/ddox/custom/docs/copied
$DUB remove-local $CURR_DIR/ddox/custom-tool
1 change: 1 addition & 0 deletions test/ddox.sh.min_frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.065
Empty file added test/ddox/.no_build
Empty file.
6 changes: 6 additions & 0 deletions test/ddox/custom-tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dub
docs.json
__dummy.html
*.o
*.obj
custom-tool
4 changes: 4 additions & 0 deletions test/ddox/custom-tool/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name "custom-tool"
description "A minimal D application."
copyright "Copyright © 2015, dawg"
authors "dawg"
1 change: 1 addition & 0 deletions test/ddox/custom-tool/public/copied
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
9 changes: 9 additions & 0 deletions test/ddox/custom-tool/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import std.file, std.stdio, std.string;

void main(string[] args)
{
if (args[1] != "generate-html")
return;
mkdirRecurse(args[$-1]);
File(args[$-1]~"/custom_tool_output", "w").writeln(args.join(" "));
}
6 changes: 6 additions & 0 deletions test/ddox/custom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dub
docs
docs.json
__dummy.html
*.o
*.obj
2 changes: 2 additions & 0 deletions test/ddox/custom/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name "ddox-project"
x:ddoxTool "custom-tool"
5 changes: 5 additions & 0 deletions test/ddox/custom/source/ddox_project.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
///
module ddox_project;

/// docstring
int foo;
6 changes: 6 additions & 0 deletions test/ddox/default/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dub
docs
docs.json
__dummy.html
*.o
*.obj
1 change: 1 addition & 0 deletions test/ddox/default/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name "ddox-project"
5 changes: 5 additions & 0 deletions test/ddox/default/source/ddox_project.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
///
module ddox_project;

/// docstring
int foo;
2 changes: 2 additions & 0 deletions test/run-unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

for script in $(ls $CURR_DIR/*.sh); do
if [ "$script" = "$(readlink -f ${BASH_SOURCE[0]})" ]; then continue; fi
if [ -e $script.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $script.min_frontend) ]; then continue; fi
log "Running $script..."
DUB=$DUB COMPILER=$COMPILER CURR_DIR="$CURR_DIR" $script || die "Script failure."
done

for pack in $(ls -d $CURR_DIR/*/); do
if [ -e $pack/.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $pack/.min_frontend) ]; then continue; fi
# First we build the packages
if [ ! -e $pack/.no_build ]; then # For sourceLibrary
if [ -e $pack/.fail_build ]; then
Expand Down

0 comments on commit d2549f8

Please sign in to comment.