diff --git a/source/dub/project.d b/source/dub/project.d index cb61a84138..52e38d562e 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -987,6 +987,22 @@ class Project { // unit tests aren't run anyway and the additional code may // cause linking to fail on Windows (issue #640) btsettings.removeOptions(BuildOption.unittests); + + // don't propagate commands from the root package's buildType + // to dependencies - they should only run for the root package + // (issue #2598) + btsettings.preBuildCommands = null; + btsettings.postBuildCommands = null; + btsettings.preGenerateCommands = null; + btsettings.postGenerateCommands = null; + btsettings.preRunCommands = null; + btsettings.postRunCommands = null; + btsettings.preBuildEnvironments = null; + btsettings.postBuildEnvironments = null; + btsettings.preGenerateEnvironments = null; + btsettings.postGenerateEnvironments = null; + btsettings.preRunEnvironments = null; + btsettings.postRunEnvironments = null; } processVars(dst, this, m_rootPackage, btsettings, gsettings); diff --git a/source/dub/test/others.d b/source/dub/test/others.d index be406a2cdd..5aa57c0c5a 100644 --- a/source/dub/test/others.d +++ b/source/dub/test/others.d @@ -120,3 +120,70 @@ unittest dub.loadPackage(); assert(dub.project.hasAllDependencies()); } + +// https://github.com/dlang/dub/issues/2598 +// Verify that preBuildCommands/postBuildCommands from a custom buildType +// in the root package are NOT propagated to dependencies. +unittest +{ + import dub.compilers.buildsettings : BuildSettings; + import dub.generators.generator : GeneratorSettings; + + scope dub = new TestDub((scope Filesystem fs) { + fs.writeFile(TestDub.ProjectPath ~ "dub.json", + `{ + "name": "a", + "dependencies": {"b": "~>1.0"}, + "buildTypes": { + "custom": { + "preBuildCommands": ["echo root-pre"], + "postBuildCommands": ["echo root-post"], + "preGenerateCommands": ["echo root-pregen"], + "postGenerateCommands": ["echo root-postgen"], + "preRunCommands": ["echo root-prerun"], + "postRunCommands": ["echo root-postrun"] + } + } + }`); + fs.writeFile(TestDub.ProjectPath ~ "dub.selections.json", + `{"fileVersion":1,"versions":{"b":"1.0.0"}}`); + fs.writePackageFile("b", "1.0.0", `{"name":"b","version":"1.0.0"}`); + }); + dub.loadPackage(); + assert(dub.project.hasAllDependencies()); + + GeneratorSettings gsettings; + gsettings.buildType = "custom"; + + // For root package: commands should be present + BuildSettings rootSettings; + dub.project.addBuildTypeSettings(rootSettings, gsettings, true); + assert(rootSettings.preBuildCommands.length > 0, + "Root package should have preBuildCommands from custom buildType"); + assert(rootSettings.postBuildCommands.length > 0, + "Root package should have postBuildCommands from custom buildType"); + assert(rootSettings.preGenerateCommands.length > 0, + "Root package should have preGenerateCommands from custom buildType"); + assert(rootSettings.postGenerateCommands.length > 0, + "Root package should have postGenerateCommands from custom buildType"); + assert(rootSettings.preRunCommands.length > 0, + "Root package should have preRunCommands from custom buildType"); + assert(rootSettings.postRunCommands.length > 0, + "Root package should have postRunCommands from custom buildType"); + + // For dependency: commands should NOT be present + BuildSettings depSettings; + dub.project.addBuildTypeSettings(depSettings, gsettings, false); + assert(depSettings.preBuildCommands.length == 0, + "Dependency should NOT have preBuildCommands from root's custom buildType"); + assert(depSettings.postBuildCommands.length == 0, + "Dependency should NOT have postBuildCommands from root's custom buildType"); + assert(depSettings.preGenerateCommands.length == 0, + "Dependency should NOT have preGenerateCommands from root's custom buildType"); + assert(depSettings.postGenerateCommands.length == 0, + "Dependency should NOT have postGenerateCommands from root's custom buildType"); + assert(depSettings.preRunCommands.length == 0, + "Dependency should NOT have preRunCommands from root's custom buildType"); + assert(depSettings.postRunCommands.length == 0, + "Dependency should NOT have postRunCommands from root's custom buildType"); +}