diff --git a/changelog/cwd-fix.dd b/changelog/cwd-fix.dd new file mode 100644 index 0000000..16d1ca5 --- /dev/null +++ b/changelog/cwd-fix.dd @@ -0,0 +1,12 @@ +Reverted v1.31.0 working directory change when using `dub run --root=` + +DUB < v1.31.0 would run applications in the working directory it was invoked in, +ignoring the `--root` argument. + +In v1.31.0, `dub` started to respect the `--root` argument and run programs in +the requested directory. + +While sometimes desirable, this change was not intended, and has now been +reverted. To restore the 1.31.0 behaivor, set `"workingDirectory"` to `"."` in +the dub.json/dub.sdl file. This works both with older DUB versions and with +future DUB versions. diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 7d34440..bb85690 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1211,6 +1211,8 @@ if (!gensettings.config.length) gensettings.config = m_defaultConfig; gensettings.runArgs = app_args; + // legacy compatibility, default working directory is always CWD + gensettings.overrideToolWorkingDirectory = getWorkingDirectory(); logDiagnostic("Generating using %s", m_generator); dub.generateProject(m_generator, gensettings); diff --git a/test/dub-as-a-library-cwd/dub.json b/test/dub-as-a-library-cwd/dub.json index 15adddf..958f419 100644 --- a/test/dub-as-a-library-cwd/dub.json +++ b/test/dub-as-a-library-cwd/dub.json @@ -1,5 +1,6 @@ { "name": "dub-as-a-library-cwd", + "workingDirectory": ".", "dependencies": { "dub": { "path": "../.." diff --git a/test/dub-custom-root-2/.gitignore b/test/dub-custom-root-2/.gitignore new file mode 100644 index 0000000..2278645 --- /dev/null +++ b/test/dub-custom-root-2/.gitignore @@ -0,0 +1,6 @@ +.dub +docs.json +__dummy.html +*.o +*.obj +/target-exe diff --git a/test/dub-custom-root-2/.no_run b/test/dub-custom-root-2/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/dub-custom-root-2/.no_run diff --git a/test/dub-custom-root-2/.no_test b/test/dub-custom-root-2/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/dub-custom-root-2/.no_test diff --git a/test/dub-custom-root-2/dub.json b/test/dub-custom-root-2/dub.json new file mode 100644 index 0000000..e0d7508 --- /dev/null +++ b/test/dub-custom-root-2/dub.json @@ -0,0 +1,4 @@ +{ + "name": "target-exe", + "workingDirectory": "source" +} diff --git a/test/dub-custom-root-2/source/app.d b/test/dub-custom-root-2/source/app.d new file mode 100644 index 0000000..5d07423 --- /dev/null +++ b/test/dub-custom-root-2/source/app.d @@ -0,0 +1,12 @@ +import std.file; +import std.path; +import std.stdio; +import std.string; + +void main() +{ + // run me from test/ with dub --root=dub-custom-root + string cwd = getcwd.chomp("/"); + assert(cwd.endsWith("test/dub-custom-root-2/source"), cwd); + writeln("ok"); +} diff --git a/test/dub-custom-root.sh b/test/dub-custom-root.sh new file mode 100755 index 0000000..f7e52ca --- /dev/null +++ b/test/dub-custom-root.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh + +pushd "$CURR_DIR" + +$DUB --root=dub-custom-root + +$DUB --root=dub-custom-root-2 + +popd diff --git a/test/dub-custom-root/.gitignore b/test/dub-custom-root/.gitignore new file mode 100644 index 0000000..2278645 --- /dev/null +++ b/test/dub-custom-root/.gitignore @@ -0,0 +1,6 @@ +.dub +docs.json +__dummy.html +*.o +*.obj +/target-exe diff --git a/test/dub-custom-root/.no_run b/test/dub-custom-root/.no_run new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/dub-custom-root/.no_run diff --git a/test/dub-custom-root/.no_test b/test/dub-custom-root/.no_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/dub-custom-root/.no_test diff --git a/test/dub-custom-root/dub.json b/test/dub-custom-root/dub.json new file mode 100644 index 0000000..172c135 --- /dev/null +++ b/test/dub-custom-root/dub.json @@ -0,0 +1,3 @@ +{ + "name": "target-exe" +} diff --git a/test/dub-custom-root/source/app.d b/test/dub-custom-root/source/app.d new file mode 100644 index 0000000..612dfe0 --- /dev/null +++ b/test/dub-custom-root/source/app.d @@ -0,0 +1,10 @@ +import std.file; +import std.path; +import std.stdio; + +void main() +{ + // run me from test/ with dub --root=test/dub-custom-root + assert(getcwd.baseName == "test", getcwd); + writeln("ok"); +}