diff --git a/source/dub/dub.d b/source/dub/dub.d index c6f6a1635d..cd309efdc9 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -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/"); } } diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index 6b1038487d..383466a8b3 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -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; diff --git a/source/dub/recipe/json.d b/source/dub/recipe/json.d index 24cb3f7f69..91d27388bb 100644 --- a/source/dub/recipe/json.d +++ b/source/dub/recipe/json.d @@ -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; } } diff --git a/source/dub/recipe/packagerecipe.d b/source/dub/recipe/packagerecipe.d index 0a260597cf..2f49baa4cc 100644 --- a/source/dub/recipe/packagerecipe.d +++ b/source/dub/recipe/packagerecipe.d @@ -71,6 +71,7 @@ struct PackageRecipe { string copyright; string license; string[] ddoxFilterArgs; + string ddoxTool; BuildSettingsTemplate buildSettings; ConfigurationInfo[] configurations; BuildSettingsTemplate[string] buildTypes; diff --git a/source/dub/recipe/sdl.d b/source/dub/recipe/sdl.d index 8294fdd5e5..c64cd087eb 100644 --- a/source/dub/recipe/sdl.d +++ b/source/dub/recipe/sdl.d @@ -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; } } @@ -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" @@ -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")); -} \ No newline at end of file +} diff --git a/test/ddox.sh b/test/ddox.sh new file mode 100755 index 0000000000..c68e023882 --- /dev/null +++ b/test/ddox.sh @@ -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 diff --git a/test/ddox.sh.min_frontend b/test/ddox.sh.min_frontend new file mode 100644 index 0000000000..1d78bbaaf3 --- /dev/null +++ b/test/ddox.sh.min_frontend @@ -0,0 +1 @@ +2.065 diff --git a/test/ddox/.no_build b/test/ddox/.no_build new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/ddox/custom-tool/.gitignore b/test/ddox/custom-tool/.gitignore new file mode 100644 index 0000000000..3dc7018631 --- /dev/null +++ b/test/ddox/custom-tool/.gitignore @@ -0,0 +1,6 @@ +.dub +docs.json +__dummy.html +*.o +*.obj +custom-tool diff --git a/test/ddox/custom-tool/dub.sdl b/test/ddox/custom-tool/dub.sdl new file mode 100644 index 0000000000..558a7eeb4e --- /dev/null +++ b/test/ddox/custom-tool/dub.sdl @@ -0,0 +1,4 @@ +name "custom-tool" +description "A minimal D application." +copyright "Copyright © 2015, dawg" +authors "dawg" diff --git a/test/ddox/custom-tool/public/copied b/test/ddox/custom-tool/public/copied new file mode 100644 index 0000000000..d95f3ad14d --- /dev/null +++ b/test/ddox/custom-tool/public/copied @@ -0,0 +1 @@ +content diff --git a/test/ddox/custom-tool/source/app.d b/test/ddox/custom-tool/source/app.d new file mode 100644 index 0000000000..e3b5f4b7c6 --- /dev/null +++ b/test/ddox/custom-tool/source/app.d @@ -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(" ")); +} diff --git a/test/ddox/custom/.gitignore b/test/ddox/custom/.gitignore new file mode 100644 index 0000000000..7bd19a763a --- /dev/null +++ b/test/ddox/custom/.gitignore @@ -0,0 +1,6 @@ +.dub +docs +docs.json +__dummy.html +*.o +*.obj diff --git a/test/ddox/custom/dub.sdl b/test/ddox/custom/dub.sdl new file mode 100644 index 0000000000..5a17c87112 --- /dev/null +++ b/test/ddox/custom/dub.sdl @@ -0,0 +1,2 @@ +name "ddox-project" +x:ddoxTool "custom-tool" diff --git a/test/ddox/custom/source/ddox_project.d b/test/ddox/custom/source/ddox_project.d new file mode 100644 index 0000000000..dc5478b881 --- /dev/null +++ b/test/ddox/custom/source/ddox_project.d @@ -0,0 +1,5 @@ +/// +module ddox_project; + +/// docstring +int foo; diff --git a/test/ddox/default/.gitignore b/test/ddox/default/.gitignore new file mode 100644 index 0000000000..7bd19a763a --- /dev/null +++ b/test/ddox/default/.gitignore @@ -0,0 +1,6 @@ +.dub +docs +docs.json +__dummy.html +*.o +*.obj diff --git a/test/ddox/default/dub.sdl b/test/ddox/default/dub.sdl new file mode 100644 index 0000000000..6dea9aa1fd --- /dev/null +++ b/test/ddox/default/dub.sdl @@ -0,0 +1 @@ +name "ddox-project" diff --git a/test/ddox/default/source/ddox_project.d b/test/ddox/default/source/ddox_project.d new file mode 100644 index 0000000000..dc5478b881 --- /dev/null +++ b/test/ddox/default/source/ddox_project.d @@ -0,0 +1,5 @@ +/// +module ddox_project; + +/// docstring +int foo; diff --git a/test/run-unittest.sh b/test/run-unittest.sh index ccd0831531..b4a5fcba7e 100755 --- a/test/run-unittest.sh +++ b/test/run-unittest.sh @@ -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