Skip to content

Commit

Permalink
[7.4.0] Ignore overrides with --ignore_dev_dependency (#23550)
Browse files Browse the repository at this point in the history
This makes it easier to realistically test how the root module would
behave as a non-root module.

RELNOTES: Overrides in the root MODULE.bazel file are now ignored with
`--ignore_dev_dependency`. (Overrides in non-root modules are already
ignored.)

Closes #23520.

PiperOrigin-RevId: 672480499
Change-Id: Ifd3a99f4ed462061101fecf918d61989c9f60401

Commit
bb7a54c

Co-authored-by: Fabian Meumertzheim <[email protected]>
  • Loading branch information
bazel-io and fmeum authored Sep 10, 2024
1 parent 846802a commit fb1a95e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion site/en/external/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ You can set the `dev_dependency` attribute to true for
[`use_extension`](/rules/lib/globals/module#use_extension) directives so that
they don't propagate to dependent projects. As the root module, you can use the
[`--ignore_dev_dependency`][ignore_dev_dep_flag] flag to verify if your targets
still build without dev dependencies.
still build without dev dependencies and overrides.
[ignore_dev_dep_flag]: /reference/command-line-reference#flag--ignore_dev_dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ModuleThreadContext {
@Nullable private final ImmutableMap<String, CompiledModuleFile> includeLabelToCompiledModuleFile;
private final Map<String, DepSpec> deps = new LinkedHashMap<>();
private final List<ModuleExtensionUsageBuilder> extensionUsageBuilders = new ArrayList<>();
private final Map<String, ModuleOverride> overrides = new HashMap<>();
private final Map<String, ModuleOverride> overrides = new LinkedHashMap<>();
private final Map<String, RepoNameUsage> repoNameUsages = new HashMap<>();

public static ModuleThreadContext fromOrFail(StarlarkThread thread, String what)
Expand Down Expand Up @@ -231,6 +231,9 @@ public PathFragment getCurrentModuleFilePath() {
}

public void addOverride(String moduleName, ModuleOverride override) throws EvalException {
if (shouldIgnoreDevDeps()) {
return;
}
ModuleOverride existingOverride = overrides.putIfAbsent(moduleName, override);
if (existingOverride != null) {
throw Starlark.errorf("multiple overrides for dep %s found", moduleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,25 @@ public void testRootModule_overrideBuiltinModule() throws Exception {
assertThat(bazelToolsOverride).isEqualTo(LocalPathOverride.create("./bazel_tools_new"));
}

@Test
public void testRootModule_overridesIgnoredWithIgnoreDevDependency() throws Exception {
scratch.overwriteFile(
rootDirectory.getRelative("MODULE.bazel").getPathString(),
"bazel_dep(name='aaa')",
"single_version_override(module_name='ddd',version='18')",
"local_path_override(module_name='eee',path='somewhere/else')",
"multiple_version_override(module_name='fff',versions=['1.0','2.0'])",
"archive_override(module_name='ggg',urls=['https://hello.com/world.zip'])");
FakeRegistry registry = registryFactory.newFakeRegistry("/foo");
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableSet.of(registry.getUrl()));
ModuleFileFunction.IGNORE_DEV_DEPS.set(differencer, true);

EvaluationResult<RootModuleFileValue> result =
evaluator.evaluate(
ImmutableList.of(ModuleFileValue.KEY_FOR_ROOT_MODULE), evaluationContext);
assertThat(result.get(ModuleFileValue.KEY_FOR_ROOT_MODULE).getOverrides()).isEmpty();
}

@Test
public void testRootModule_include_good() throws Exception {
scratch.overwriteFile(
Expand Down

0 comments on commit fb1a95e

Please sign in to comment.