Skip to content

Commit

Permalink
Allow overrides in non-root modules
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Wyverald authored and copybara-github committed May 3, 2023
1 parent 38e08c2 commit 78cb7d5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions site/en/external/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ exist in the resolved dependency graph.
## Overrides

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

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

### Single-version override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
moduleKey,
module.getVersion());
}
if (!moduleFileGlobals.buildOverrides().isEmpty()) {
throw errorf(Code.BAD_MODULE, "The MODULE.bazel file of %s declares overrides", moduleKey);
}

return NonRootModuleFileValue.create(module, moduleFileHash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ private void addOverride(String moduleName, ModuleOverride override) throws Eval
doc =
"Specifies that a dependency should still come from a registry, but its version should"
+ " be pinned, or its registry overridden, or a list of patches applied. This"
+ " directive can only be used by the root module; in other words, if a module"
+ " specifies any overrides, it cannot be used as a dependency by others.",
+ " directive only takes effect in the root module; in other words, if a module"
+ " is used as a dependency by others, its own overrides are ignored.",
parameters = {
@Param(
name = "module_name",
Expand Down Expand Up @@ -708,9 +708,9 @@ public void singleVersionOverride(
"Specifies that a dependency should still come from a registry, but multiple versions of"
+ " it should be allowed to coexist. See <a"
+ " href=\"/external/module#multiple-version_override\">the documentation</a> for"
+ " more details. This directive can only be used by the root module; in other words,"
+ " if a module specifies any overrides, it cannot be used as a dependency by"
+ " others.",
+ " more details. This"
+ " directive only takes effect in the root module; in other words, if a module"
+ " is used as a dependency by others, its own overrides are ignored.",
parameters = {
@Param(
name = "module_name",
Expand Down Expand Up @@ -760,9 +760,9 @@ public void multipleVersionOverride(String moduleName, Iterable<?> versions, Str
name = "archive_override",
doc =
"Specifies that this dependency should come from an archive file (zip, gzip, etc) at a"
+ " certain location, instead of from a registry. This directive can only be used by"
+ " the root module; in other words, if a module specifies any overrides, it cannot"
+ " be used as a dependency by others.",
+ " certain location, instead of from a registry. This"
+ " directive only takes effect in the root module; in other words, if a module"
+ " is used as a dependency by others, its own overrides are ignored.",
parameters = {
@Param(
name = "module_name",
Expand Down Expand Up @@ -844,8 +844,8 @@ public void archiveOverride(
name = "git_override",
doc =
"Specifies that a dependency should come from a certain commit of a Git repository. This"
+ " directive can only be used by the root module; in other words, if a module"
+ " specifies any overrides, it cannot be used as a dependency by others.",
+ " directive only takes effect in the root module; in other words, if a module"
+ " is used as a dependency by others, its own overrides are ignored.",
parameters = {
@Param(
name = "module_name",
Expand Down Expand Up @@ -911,8 +911,8 @@ public void gitOverride(
name = "local_path_override",
doc =
"Specifies that a dependency should come from a certain directory on local disk. This"
+ " directive can only be used by the root module; in other words, if a module"
+ " specifies any overrides, it cannot be used as a dependency by others.",
+ " directive only takes effect in the root module; in other words, if a module"
+ " is used as a dependency by others, its own overrides are ignored.",
parameters = {
@Param(
name = "module_name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ public void testSimpleDiamond() throws Exception {
.addModule(
createModuleKey("ccc", "2.0"),
"module(name='ccc', version='2.0');bazel_dep(name='ddd',version='3.0')")
.addModule(createModuleKey("ddd", "3.0"), "module(name='ddd', version='3.0')");
.addModule(
createModuleKey("ddd", "3.0"),
// Add a random override here; it should be ignored
"module(name='ddd', version='3.0');local_path_override(module_name='ff',path='f')");
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl()));

EvaluationResult<DiscoveryValue> result =
Expand Down

0 comments on commit 78cb7d5

Please sign in to comment.