diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index f72acec..6ae5182 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -156,6 +156,7 @@ TargetType targetType; string targetPath; string targetName; + string workingDirectory; string[] dflags; string[] lflags; string[] libs; diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index 41623ec..9ba8276 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -174,6 +174,11 @@ // copy files and run the executable if (generate_binary && settings.run) { if (buildsettings.targetType == TargetType.executable) { + if (buildsettings.workingDirectory.length) { + logDiagnostic("Switching to %s", (cwd ~ buildsettings.workingDirectory).toNativeString()); + chdir((cwd ~ buildsettings.workingDirectory).toNativeString()); + } + scope(exit) chdir(cwd.toNativeString()); logInfo("Running %s...", exe_file_path.toNativeString()); auto prg_pid = spawnProcess(exe_file_path.toNativeString() ~ settings.runArgs); auto result = prg_pid.wait(); diff --git a/source/dub/generators/rdmd.d b/source/dub/generators/rdmd.d index be29713..f928578 100644 --- a/source/dub/generators/rdmd.d +++ b/source/dub/generators/rdmd.d @@ -112,6 +112,12 @@ if (generate_binary && settings.run) { if (buildsettings.targetType == TargetType.executable) { + auto cwd = Path(getcwd()); + if (buildsettings.workingDirectory.length) { + logDiagnostic("Switching to %s", (cwd ~ buildsettings.workingDirectory).toNativeString()); + chdir((cwd ~ buildsettings.workingDirectory).toNativeString()); + } + scope(exit) chdir(cwd.toNativeString()); logInfo("Running %s...", run_exe_file.toNativeString()); auto prg_pid = spawnProcess(run_exe_file.toNativeString() ~ settings.runArgs); result = prg_pid.wait(); diff --git a/source/dub/package_.d b/source/dub/package_.d index 8a50dc0..3100102 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -424,6 +424,7 @@ TargetType targetType = TargetType.autodetect; string targetPath; string targetName; + string workingDirectory; string[string] subConfigurations; string[][string] dflags; string[][string] lflags; @@ -484,11 +485,16 @@ case "targetPath": enforce(suffix.empty, "targetPath does not support platform customization."); this.targetPath = value.get!string; + if (this.workingDirectory is null) this.workingDirectory = this.targetPath; break; case "targetName": enforce(suffix.empty, "targetName does not support platform customization."); this.targetName = value.get!string; break; + case "workingDirectory": + enforce(suffix.empty, "workingDirectory does not support platform customization."); + this.workingDirectory = value.get!string; + break; case "subConfigurations": enforce(suffix.empty, "subConfigurations does not support platform customization."); this.subConfigurations = deserializeJson!(string[string])(value); @@ -539,7 +545,8 @@ } if (targetType != TargetType.autodetect) ret["targetType"] = targetType.to!string(); if (!targetPath.empty) ret["targetPath"] = targetPath; - if (!targetName.empty) ret["targetName"] = targetPath; + if (!targetName.empty) ret["targetName"] = targetName; + if (!workingDirectory.empty) ret["workingDirectory"] = workingDirectory; foreach (suffix, arr; dflags) ret["dflags"~suffix] = serializeToJson(arr); foreach (suffix, arr; lflags) ret["lflags"~suffix] = serializeToJson(arr); foreach (suffix, arr; libs) ret["libs"~suffix] = serializeToJson(arr); @@ -569,6 +576,7 @@ dst.targetType = this.targetType; if (!this.targetPath.empty) dst.targetPath = this.targetPath; if (!this.targetName.empty) dst.targetName = this.targetName; + if (!this.workingDirectory.empty) dst.workingDirectory = this.workingDirectory; // collect source files from all source folders foreach(suffix, paths; sourcePaths){ diff --git a/source/dub/project.d b/source/dub/project.d index 39ac734..76abe55 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -260,6 +260,7 @@ dst.targetType = psettings.targetType; dst.targetPath = psettings.targetPath; dst.targetName = psettings.targetName; + dst.workingDirectory = psettings.workingDirectory; } }