Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore overrides with --ignore_dev_dependency #23520

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion site/en/external/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,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 @@ -51,7 +51,7 @@ public class ModuleThreadContext extends StarlarkThreadContext {
@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 @@ -269,12 +269,16 @@ public InterimModule buildModule(@Nullable Registry registry) throws EvalExcepti
}

public ImmutableMap<String, ModuleOverride> buildOverrides() {
LinkedHashMap<String, ModuleOverride> effectiveOverrides = new LinkedHashMap<>();
if (!shouldIgnoreDevDeps()) {
effectiveOverrides.putAll(overrides);
}
// Add overrides for builtin modules if there is no existing override for them.
if (ModuleKey.ROOT.equals(module.getKey())) {
for (String moduleName : builtinModules.keySet()) {
overrides.putIfAbsent(moduleName, builtinModules.get(moduleName));
effectiveOverrides.putIfAbsent(moduleName, builtinModules.get(moduleName));
}
}
return ImmutableMap.copyOf(overrides);
return ImmutableMap.copyOf(effectiveOverrides);
}
}
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