Skip to content

Commit 78cb7d5

Browse files
Wyveraldcopybara-github
authored andcommitted
Allow overrides in non-root modules
They're simply ignored. RELNOTES: Overrides specified by non-root modules no longer cause an error, and are silently ignored instead. They were originally treated as an error to allow for the future possibility of overrides in the transitive dependency graph working together; but we've deemed that infeasible (and even if it was, it'd be so complicated and confusing to users that it would not be a good addition). PiperOrigin-RevId: 529095596 Change-Id: I8b9b7b570b405ee757554accf791d8e4c1ff6528
1 parent 38e08c2 commit 78cb7d5

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

site/en/external/module.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ exist in the resolved dependency graph.
108108
## Overrides
109109

110110
Specify overrides in the `MODULE.bazel` file to alter the behavior of Bazel
111-
module resolution. Only the root module can specify overridesBazel throws an
112-
error for dependency modules with overrides.
111+
module resolution. Only the root module's overrides take effectif a module is
112+
used as a dependency, its overrides are ignored.
113113

114114
Each override is specified for a certain module name, affecting all of its
115-
versions in the dependency graph. Although only the root module can specify
116-
overrides, they can be for transitive dependencies that the root module does not
115+
versions in the dependency graph. Although only the root module's overrides take
116+
effect, they can be for transitive dependencies that the root module does not
117117
directly depend on.
118118

119119
### Single-version override

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunction.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
138138
moduleKey,
139139
module.getVersion());
140140
}
141-
if (!moduleFileGlobals.buildOverrides().isEmpty()) {
142-
throw errorf(Code.BAD_MODULE, "The MODULE.bazel file of %s declares overrides", moduleKey);
143-
}
144141

145142
return NonRootModuleFileValue.create(module, moduleFileHash);
146143
}

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ private void addOverride(String moduleName, ModuleOverride override) throws Eval
626626
doc =
627627
"Specifies that a dependency should still come from a registry, but its version should"
628628
+ " be pinned, or its registry overridden, or a list of patches applied. This"
629-
+ " directive can only be used by the root module; in other words, if a module"
630-
+ " specifies any overrides, it cannot be used as a dependency by others.",
629+
+ " directive only takes effect in the root module; in other words, if a module"
630+
+ " is used as a dependency by others, its own overrides are ignored.",
631631
parameters = {
632632
@Param(
633633
name = "module_name",
@@ -708,9 +708,9 @@ public void singleVersionOverride(
708708
"Specifies that a dependency should still come from a registry, but multiple versions of"
709709
+ " it should be allowed to coexist. See <a"
710710
+ " href=\"/external/module#multiple-version_override\">the documentation</a> for"
711-
+ " more details. This directive can only be used by the root module; in other words,"
712-
+ " if a module specifies any overrides, it cannot be used as a dependency by"
713-
+ " others.",
711+
+ " more details. This"
712+
+ " directive only takes effect in the root module; in other words, if a module"
713+
+ " is used as a dependency by others, its own overrides are ignored.",
714714
parameters = {
715715
@Param(
716716
name = "module_name",
@@ -760,9 +760,9 @@ public void multipleVersionOverride(String moduleName, Iterable<?> versions, Str
760760
name = "archive_override",
761761
doc =
762762
"Specifies that this dependency should come from an archive file (zip, gzip, etc) at a"
763-
+ " certain location, instead of from a registry. This directive can only be used by"
764-
+ " the root module; in other words, if a module specifies any overrides, it cannot"
765-
+ " be used as a dependency by others.",
763+
+ " certain location, instead of from a registry. This"
764+
+ " directive only takes effect in the root module; in other words, if a module"
765+
+ " is used as a dependency by others, its own overrides are ignored.",
766766
parameters = {
767767
@Param(
768768
name = "module_name",
@@ -844,8 +844,8 @@ public void archiveOverride(
844844
name = "git_override",
845845
doc =
846846
"Specifies that a dependency should come from a certain commit of a Git repository. This"
847-
+ " directive can only be used by the root module; in other words, if a module"
848-
+ " specifies any overrides, it cannot be used as a dependency by others.",
847+
+ " directive only takes effect in the root module; in other words, if a module"
848+
+ " is used as a dependency by others, its own overrides are ignored.",
849849
parameters = {
850850
@Param(
851851
name = "module_name",
@@ -911,8 +911,8 @@ public void gitOverride(
911911
name = "local_path_override",
912912
doc =
913913
"Specifies that a dependency should come from a certain directory on local disk. This"
914-
+ " directive can only be used by the root module; in other words, if a module"
915-
+ " specifies any overrides, it cannot be used as a dependency by others.",
914+
+ " directive only takes effect in the root module; in other words, if a module"
915+
+ " is used as a dependency by others, its own overrides are ignored.",
916916
parameters = {
917917
@Param(
918918
name = "module_name",

src/test/java/com/google/devtools/build/lib/bazel/bzlmod/DiscoveryTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ public void testSimpleDiamond() throws Exception {
215215
.addModule(
216216
createModuleKey("ccc", "2.0"),
217217
"module(name='ccc', version='2.0');bazel_dep(name='ddd',version='3.0')")
218-
.addModule(createModuleKey("ddd", "3.0"), "module(name='ddd', version='3.0')");
218+
.addModule(
219+
createModuleKey("ddd", "3.0"),
220+
// Add a random override here; it should be ignored
221+
"module(name='ddd', version='3.0');local_path_override(module_name='ff',path='f')");
219222
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl()));
220223

221224
EvaluationResult<DiscoveryValue> result =

0 commit comments

Comments
 (0)