Skip to content

Fix ModuleThreadContext to only ignore dev dependencies when applicable#28957

Open
namanONcode wants to merge 3 commits intobazelbuild:masterfrom
namanONcode:issue-21596
Open

Fix ModuleThreadContext to only ignore dev dependencies when applicable#28957
namanONcode wants to merge 3 commits intobazelbuild:masterfrom
namanONcode:issue-21596

Conversation

@namanONcode
Copy link

@namanONcode namanONcode commented Mar 11, 2026

Closes #21596

Description

This pull request improves the handling of development-only dependencies (dev_dependency) in Bazel's Bzlmod module system. Specifically, it ensures that any module overrides for dev-only dependencies are ignored when the --ignore_dev_dependency flag is set. The changes introduce a mechanism to track ignored dev dependencies and filter out their overrides.

Key changes:

  • Core logic improvements:

    • Added a Set<String> ignoredDevDeps to ModuleThreadContext to track module names of dev-only dependencies that are ignored when --ignore_dev_dependency is enabled.
    • Modified the buildOverrides method to remove any overrides for modules listed in ignoredDevDeps, ensuring that overrides for ignored dev dependencies do not affect the build.
    • Updated the bazelDep logic to call addIgnoredDevDep when a dev dependency is ignored, ensuring the ignored modules are properly tracked.
  • Testing improvements:

    • Enhanced and added new tests in ModuleFileFunctionTest to verify that overrides for dev-only dependencies are filtered out when --ignore_dev_dependency is set, and that overrides for regular dependencies are preserved.

Motivation

Fixes #21596

Previously, ModuleThreadContext.addOverride() had a blanket if (shouldIgnoreDevDeps()) return; that discarded all overrides when --ignore_dev_dependency was set, regardless of whether the overridden module was actually a dev dependency. This PR fixes this bug so that only the dev dependency overrides are safely ignored.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

Fixes #issue-21596 ModuleThreadContext.addOverride() had a blanket if (shouldIgnoreDevDeps()) return; that discarded all overrides when --ignore_dev_dependency was set, regardless of whether the overridden module was actually a dev dependency.
Copilot AI review requested due to automatic review settings March 11, 2026 18:07
@github-actions github-actions bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Mar 11, 2026
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

This PR refines Bzlmod’s handling of --ignore_dev_dependency by ensuring module overrides are only ignored for dev dependencies that are actually ignored, instead of dropping all overrides when the flag is set.

Changes:

  • Track ignored dev-dependency module names during bazel_dep(..., dev_dependency=True) when --ignore_dev_dependency is enabled.
  • Filter overrides for those ignored dev dependencies when constructing the root module’s override map.
  • Expand ModuleFileFunctionTest coverage to assert dev-only overrides are filtered while non-dev overrides remain.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleThreadContext.java Adds tracking of ignored dev deps and filters override output accordingly.
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java Records ignored dev deps when bazel_dep is skipped due to --ignore_dev_dependency.
src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java Adds/adjusts tests asserting override filtering behavior with --ignore_dev_dependency.
Comments suppressed due to low confidence (1)

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleThreadContext.java:363

  • addOverride() no longer ignores override directives in non-root modules. The Starlark docs for override directives state they only take effect in the root module; with this change, non-root module evaluation can now fail (e.g., duplicate overrides now throw) despite the overrides being semantically ignored. Consider short-circuiting here when the current module key is not ModuleKey.ROOT, and keep the dev-dep filtering logic separate (only applied for the root module when --ignore_dev_dependency is set).
  public void addOverride(String moduleName, ModuleOverride override) throws EvalException {
    ModuleOverride existingOverride = overrides.putIfAbsent(moduleName, override);
    if (existingOverride != null) {
      throw Starlark.errorf("multiple overrides for dep %s found", moduleName);
    }
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@meteorcloudy
Copy link
Member

Can you update the PR description according to our template?

@namanONcode
Copy link
Author

Can you update the PR description according to our template?

I Fixed and implemented all suggestion give a look

@Wyverald
Copy link
Member

I actually think the fix should be much simpler: if --ignore_dev_dependencies is set, all overrides should be ignored. A dev dependency is simply a dependency edge that is ignored if the current module is not the root module. So --ignore_dev_dependencies effectively pretends the current (root) module is non-root. But overrides don't take effective when they're in non-root modules anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--ignore_dev_dependency does not work with local_path_override

4 participants