From 6e42edff04abc6e4e9494f891b58d38a3a820069 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Mon, 9 Jan 2023 02:06:36 +0100 Subject: [PATCH] future-proofed cwd dub fix --- workspace-d/source/workspaced/com/dub.d | 9 +++++---- .../source/workspaced/dub/lintgenerator.d | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/workspace-d/source/workspaced/com/dub.d b/workspace-d/source/workspaced/com/dub.d index ea80f224..bef28a2c 100644 --- a/workspace-d/source/workspaced/com/dub.d +++ b/workspace-d/source/workspaced/com/dub.d @@ -585,14 +585,15 @@ class DubComponent : ComponentWrapper auto compiler = _compiler; auto buildPlatform = _platform; + string cwd = instance.cwd; + GeneratorSettings settings; settings.platform = buildPlatform; settings.config = _configuration; settings.buildType = _buildType; settings.compiler = compiler; - settings.buildSettings = _dub.project.rootPackage.getBuildSettings(buildPlatform, _configuration); - - string cwd = instance.cwd; + static if (is(typeof(settings.overrideToolWorkingDirectory))) + settings.overrideToolWorkingDirectory = NativePath(cwd); auto ret = new typeof(return); new Thread({ @@ -638,7 +639,7 @@ class DubComponent : ComponentWrapper import workspaced.dub.lintgenerator : DubLintGenerator; import std.file : chdir; - new DubLintGenerator(_dub.project).generate(settings); + new DubLintGenerator(_dub.project, NativePath(cwd)).generate(settings); } catch (CompilerInvocationException e) { diff --git a/workspace-d/source/workspaced/dub/lintgenerator.d b/workspace-d/source/workspaced/dub/lintgenerator.d index 295c086c..2f3b0b7e 100644 --- a/workspace-d/source/workspaced/dub/lintgenerator.d +++ b/workspace-d/source/workspaced/dub/lintgenerator.d @@ -29,9 +29,15 @@ import std.string; class DubLintGenerator : ProjectGenerator { - this(Project project) + private + { + NativePath m_cwd; + } + + this(Project project, NativePath cwd) { super(project); + m_cwd = cwd; } override void generateTargets(GeneratorSettings settings, in TargetInfo[string] targets) @@ -48,14 +54,12 @@ class DubLintGenerator : ProjectGenerator private void performDirectBuild(GeneratorSettings settings, ref BuildSettings buildsettings, in Package pack, string config) { - auto cwd = NativePath(getcwd()); - tracef("%s %s: building configuration %s", pack.name, pack.version_, config); // make all target/import paths relative string makeRelative(string path) { - return shrinkPath(NativePath(path), cwd); + return shrinkPath(NativePath(path), m_cwd); } buildsettings.targetPath = makeRelative(buildsettings.targetPath); @@ -81,11 +85,13 @@ class DubLintGenerator : ProjectGenerator buildsettings.lflags = null; buildsettings.addOptions(BuildOption.syntaxOnly); buildsettings.sourceFiles = buildsettings.sourceFiles.filter!(f => !isLinkerFile(settings.platform, f)).array; - trace("Build settings: ", buildsettings); settings.compiler.prepareBuildSettings(buildsettings, settings.platform, BuildSetting.commandLine); - settings.compiler.invoke(buildsettings, settings.platform, settings.compileCallback); + static if (is(typeof(settings.toolWorkingDirectory))) + settings.compiler.invoke(buildsettings, settings.platform, settings.compileCallback, settings.toolWorkingDirectory); + else + settings.compiler.invoke(buildsettings, settings.platform, settings.compileCallback); } }