Skip to content

Fix #2598: don't propagate build commands from root buildType to deps#3107

Open
queelius wants to merge 1 commit intodlang:masterfrom
queelius:fix/2598-build-commands-scope
Open

Fix #2598: don't propagate build commands from root buildType to deps#3107
queelius wants to merge 1 commit intodlang:masterfrom
queelius:fix/2598-build-commands-scope

Conversation

@queelius
Copy link

Summary

  • Fixes preBuildCommands/postBuildCommands tainting _all_ dependencies from root package #2598: preBuildCommands/postBuildCommands (and all other command hooks) defined in a custom buildType in the root package were incorrectly executed for every dependency during the build.
  • When addBuildTypeSettings is 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.
  • Added a unit test that verifies commands from a custom buildType are present for the root package but absent 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 via processVars(). The for_root_package flag was only used to strip unittest options, but commands were never filtered.

Test plan

  • New unit test in source/dub/test/others.d that creates a project with a custom buildType containing all 6 command types, a dependency, and verifies commands appear only for the root package
  • Confirmed the test fails without the fix (1/56 modules FAILED) and passes with it (56 modules passed)
  • All existing tests continue to pass

🤖 Generated with Claude Code

… 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>
Copilot AI review requested due to automatic review settings March 25, 2026 10:39
@github-actions
Copy link

github-actions bot commented Mar 25, 2026

✅ 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=68s
Full build output
DUB version 1.41.0, built on Mar  1 2026
LDC - the LLVM D compiler (1.42.0):
  based on DMD v2.112.1 and LLVM 21.1.8
  built with LDC - the LLVM D compiler (1.42.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver3
  https://dlang.org - https://wiki.dlang.org/LDC


  Registered Targets:
    aarch64     - AArch64 (little endian)
    aarch64_32  - AArch64 (little endian ILP32)
    aarch64_be  - AArch64 (big endian)
    amdgcn      - AMD GCN GPUs
    arm         - ARM
    arm64       - ARM64 (little endian)
    arm64_32    - ARM64 (little endian ILP32)
    armeb       - ARM (big endian)
    avr         - Atmel AVR Microcontroller
    bpf         - BPF (host endian)
    bpfeb       - BPF (big endian)
    bpfel       - BPF (little endian)
    hexagon     - Hexagon
    lanai       - Lanai
    loongarch32 - 32-bit LoongArch
    loongarch64 - 64-bit LoongArch
    mips        - MIPS (32-bit big endian)
    mips64      - MIPS (64-bit big endian)
    mips64el    - MIPS (64-bit little endian)
    mipsel      - MIPS (32-bit little endian)
    msp430      - MSP430 [experimental]
    nvptx       - NVIDIA PTX 32-bit
    nvptx64     - NVIDIA PTX 64-bit
    ppc32       - PowerPC 32
    ppc32le     - PowerPC 32 LE
    ppc64       - PowerPC 64
    ppc64le     - PowerPC 64 LE
    r600        - AMD GPUs HD2XXX-HD6XXX
    riscv32     - 32-bit RISC-V
    riscv64     - 64-bit RISC-V
    sparc       - Sparc
    sparcel     - Sparc LE
    sparcv9     - Sparc V9
    spirv       - SPIR-V Logical
    spirv32     - SPIR-V 32-bit
    spirv64     - SPIR-V 64-bit
    systemz     - SystemZ
    thumb       - Thumb
    thumbeb     - Thumb (big endian)
    ve          - VE
    wasm32      - WebAssembly 32-bit
    wasm64      - WebAssembly 64-bit
    x86         - 32-bit X86: Pentium-Pro and above
    x86-64      - 64-bit X86: EM64T and AMD64
    xcore       - XCore
    xtensa      - Xtensa 32
   Upgrading project in /home/runner/work/dub/dub/
    Starting Performing "release" build using /opt/hostedtoolcache/dc/ldc2-1.42.0/x64/ldc2-1.42.0-linux-x86_64/bin/ldc2 for x86_64.
    Building dub 1.42.0-beta.1+commit.4.ge6de8b76: building configuration [application]
     Linking dub
STAT:statistics (-before, +after)
STAT:executable size=5710288 bin/dub
STAT:rough build time=68s

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 buildType settings 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.

Comment on lines +155 to +157
GeneratorSettings gsettings;
gsettings.buildType = "custom";

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preBuildCommands/postBuildCommands tainting _all_ dependencies from root package

2 participants