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.2.1] Allow discard previous overrides for --override_repository and --override_module #22784

Merged
merged 1 commit into from
Jun 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
// We use a LinkedHashMap to preserve the iteration order.
Map<RepositoryName, PathFragment> overrideMap = new LinkedHashMap<>();
for (RepositoryOverride override : repoOptions.repositoryOverrides) {
if (override.path().isEmpty()) {
overrideMap.remove(override.repositoryName());
continue;
}
String repoPath = getAbsolutePath(override.path(), env);
overrideMap.put(override.repositoryName(), PathFragment.create(repoPath));
}
Expand All @@ -474,6 +478,10 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
if (repoOptions.moduleOverrides != null) {
Map<String, ModuleOverride> moduleOverrideMap = new LinkedHashMap<>();
for (RepositoryOptions.ModuleOverride override : repoOptions.moduleOverrides) {
if (override.path().isEmpty()) {
moduleOverrideMap.remove(override.moduleName());
continue;
}
String modulePath = getAbsolutePath(override.path(), env);
moduleOverrideMap.put(override.moduleName(), LocalPathOverride.create(modulePath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public class RepositoryOptions extends OptionsBase {
+ " given path is an absolute path, it will be used as it is. If the given path is a"
+ " relative path, it is relative to the current working directory. If the given path"
+ " starts with '%workspace%, it is relative to the workspace root, which is the"
+ " output of `bazel info workspace`")
+ " output of `bazel info workspace`. If the given path is empty, then remove any"
+ " previous overrides.")
public List<RepositoryOverride> repositoryOverrides;

@Option(
Expand All @@ -186,7 +187,8 @@ public class RepositoryOptions extends OptionsBase {
+ " path is an absolute path, it will be used as it is. If the given path is a"
+ " relative path, it is relative to the current working directory. If the given path"
+ " starts with '%workspace%, it is relative to the workspace root, which is the"
+ " output of `bazel info workspace`")
+ " output of `bazel info workspace`. If the given path is empty, then remove any"
+ " previous overrides.")
public List<ModuleOverride> moduleOverrides;

@Option(
Expand Down
21 changes: 21 additions & 0 deletions src/test/py/bazel/bzlmod/bazel_overrides_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,27 @@ def testCmdRelativeModuleOverride(self):
'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr
)

# Test delete previous overrides
_, _, stderr = self.RunBazel(
[
'build',
'--announce_rc',
'@ss//:all',
'--override_module',
'ss=../../bb',
'--override_module',
'ss=',
'--enable_bzlmod',
],
cwd=self.Path('aa/cc'),
allow_failure=True,
)
self.assertIn(
'ERROR: Error computing the main repository mapping: module not found'
' in registries: ss@1.0',
stderr,
)

def testCmdWorkspaceRelativeModuleOverride(self):
self.ScratchFile(
'MODULE.bazel',
Expand Down
Loading