Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
67 changes: 67 additions & 0 deletions source/dub/test/others.d
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Comment on lines +155 to +157
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this unittest, GeneratorSettings is only partially initialized (only buildType is set). To avoid the test depending on BuildPlatform.init behavior, consider explicitly setting gsettings.platform (e.g., BuildPlatform.any) so addBuildTypeSettings is exercised with a valid platform value.

Copilot uses AI. Check for mistakes.
// 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");
}
Loading