Fix #2598: don't propagate build commands from root buildType to deps#3107
Fix #2598: don't propagate build commands from root buildType to deps#3107queelius wants to merge 1 commit intodlang:masterfrom
Conversation
… dependencies When a root package defines preBuildCommands/postBuildCommands (or other command hooks) inside a custom buildType, those commands were incorrectly executed for every dependency during the build. This happened because addBuildTypeSettings applied the root package's buildType settings to all targets without filtering out commands for non-root packages. The fix clears all command-related fields (pre/post build, generate, and run commands plus their associated environments) from the buildType settings before they are applied to dependency build settings, matching the existing pattern that already strips unittest options for deps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
✅ PR OK, no changes in deprecations or warnings Total deprecations: 0 Total warnings: 0 Build statistics: statistics (-before, +after)
executable size=5710288 bin/dub
-rough build time=66s
+rough build time=68sFull build output |
There was a problem hiding this comment.
Pull request overview
Fixes a long-standing issue where command hooks defined in the root package’s custom buildType were being applied to dependency targets, causing dependency builds to execute the root project’s commands.
Changes:
- Strip all command-hook fields (and their corresponding environment maps) from root
buildTypesettings when applying build-type settings to non-root packages. - Add a regression unittest ensuring command hooks from a root custom build type appear only for the root package and not dependencies.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| source/dub/project.d | Clears command hooks/envs from root buildType settings when propagating to dependencies. |
| source/dub/test/others.d | Adds unittest coverage for issue #2598 to prevent command-hook propagation to dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| GeneratorSettings gsettings; | ||
| gsettings.buildType = "custom"; | ||
|
|
There was a problem hiding this comment.
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.
Summary
preBuildCommands/postBuildCommands(and all other command hooks) defined in a custombuildTypein the root package were incorrectly executed for every dependency during the build.addBuildTypeSettingsis called for a non-root package, command fields and their associated environments are now cleared from the buildType settings before propagation, matching the existing pattern that already strips unittest options for dependencies.Root cause
In
Project.addBuildTypeSettings()(source/dub/project.d), the root package's buildType settings (including all command hooks) were applied to every target viaprocessVars(). Thefor_root_packageflag was only used to strip unittest options, but commands were never filtered.Test plan
source/dub/test/others.dthat creates a project with a custom buildType containing all 6 command types, a dependency, and verifies commands appear only for the root package🤖 Generated with Claude Code