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

[7.4.0] Ignore overrides with --ignore_dev_dependency #23550

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading