diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionContext.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionContext.java
index b7a392673c2db9..456148a1f4db63 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionContext.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionContext.java
@@ -128,8 +128,11 @@ public boolean isDevDependency(TypeCheckedTag tag) {
name = "is_isolated",
doc =
"Whether this particular usage of the extension had isolate = True
"
- + "specified and is thus isolated from all other usages.",
- structField = true)
+ + "specified and is thus isolated from all other usages."
+ + "
This field is currently experimental and only available with the flag "
+ + "--experimental_isolated_extension_usages
.",
+ structField = true,
+ enableOnlyWithFlag = "-experimental_isolated_extension_usages")
public boolean isIsolated() {
return extensionId.getIsolationKey().isPresent();
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java
index 3c45f89a4f17db..e44a3b6e70d450 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileGlobals.java
@@ -435,10 +435,14 @@ public void registerToolchains(boolean devDependency, Sequence> toolchainLabel
+ "usages, both in this and other modules. Tags created for this usage do not "
+ "affect other usages and the repositories generated by the extension for "
+ "this usage will be distinct from all other repositories generated by the "
- + "extension.",
+ + "extension."
+ + "
This parameter is currently experimental and only available with the "
+ + "flag --experimental_isolated_extension_usages
.",
named = true,
positional = false,
- defaultValue = "False"),
+ defaultValue = "False",
+ enableOnlyWithFlag = "-experimental_isolated_extension_usages",
+ valueWhenDisabled = "False"),
},
useStarlarkThread = true)
public ModuleExtensionProxy useExtension(
diff --git a/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java b/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java
index 054166f0687d15..6d2b22fac63480 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java
@@ -199,6 +199,14 @@ public final class BuildLanguageOptions extends OptionsBase {
+ " WORKSPACE. See https://bazel.build/docs/bzlmod for more information.")
public boolean enableBzlmod;
+ @Option(
+ name = "experimental_isolated_extension_usages",
+ defaultValue = "false",
+ documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
+ effectTags = OptionEffectTag.LOADING_AND_ANALYSIS,
+ help = "foo")
+ public boolean experimentalIsolatedExtensionUsages;
+
@Option(
name = "experimental_java_proto_library_default_has_services",
defaultValue = "true",
@@ -669,6 +677,7 @@ public StarlarkSemantics toStarlarkSemantics() {
.setBool(
EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS, experimentalEnableAndroidMigrationApis)
.setBool(ENABLE_BZLMOD, enableBzlmod)
+ .setBool(EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, experimentalIsolatedExtensionUsages)
.setBool(
EXPERIMENTAL_JAVA_PROTO_LIBRARY_DEFAULT_HAS_SERVICES,
experimentalJavaProtoLibraryDefaultHasServices)
@@ -761,6 +770,8 @@ public StarlarkSemantics toStarlarkSemantics() {
public static final String EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS =
"-experimental_enable_android_migration_apis";
public static final String ENABLE_BZLMOD = "-enable_bzlmod";
+ public static final String EXPERIMENTAL_ISOLATED_EXTENSION_USAGES =
+ "-experimental_isolated_extension_usages";
public static final String EXPERIMENTAL_JAVA_PROTO_LIBRARY_DEFAULT_HAS_SERVICES =
"+experimental_java_proto_library_default_has_services";
public static final String INCOMPATIBLE_EXISTING_RULES_IMMUTABLE_VIEW =
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
index 3e8bb0920f5b2a..675a9ce4f7816c 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionResolutionTest.java
@@ -263,7 +263,10 @@ public void setup() throws Exception {
PrecomputedValue.STARLARK_SEMANTICS.set(
differencer,
- StarlarkSemantics.builder().setBool(BuildLanguageOptions.ENABLE_BZLMOD, true).build());
+ StarlarkSemantics.builder()
+ .setBool(BuildLanguageOptions.ENABLE_BZLMOD, true)
+ .setBool(BuildLanguageOptions.EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, true)
+ .build());
RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(differencer, ImmutableMap.of());
RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
index 3ee5f0d59ff4be..35b09dcdf214fd 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleFileFunctionTest.java
@@ -1049,6 +1049,13 @@ public void module_calledLate() throws Exception {
@Test
public void isolatedUsageWithoutImports() throws Exception {
+ PrecomputedValue.STARLARK_SEMANTICS.set(
+ differencer,
+ StarlarkSemantics.builder()
+ .setBool(BuildLanguageOptions.ENABLE_BZLMOD, true)
+ .setBool(BuildLanguageOptions.EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, true)
+ .build());
+
scratch.file(
rootDirectory.getRelative("MODULE.bazel").getPathString(),
"isolated_ext = use_extension('//:extensions.bzl', 'my_ext', isolate = True)");
@@ -1069,6 +1076,13 @@ public void isolatedUsageWithoutImports() throws Exception {
@Test
public void isolatedUsageNotExported() throws Exception {
+ PrecomputedValue.STARLARK_SEMANTICS.set(
+ differencer,
+ StarlarkSemantics.builder()
+ .setBool(BuildLanguageOptions.ENABLE_BZLMOD, true)
+ .setBool(BuildLanguageOptions.EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, true)
+ .build());
+
scratch.file(
rootDirectory.getRelative("MODULE.bazel").getPathString(),
"use_extension('//:extensions.bzl', 'my_ext', isolate = True)");
@@ -1081,4 +1095,20 @@ public void isolatedUsageNotExported() throws Exception {
"Isolated extension usage at /workspace/MODULE.bazel:1:14 must be assigned to a "
+ "top-level variable");
}
+
+ @Test
+ public void isolatedUsage_notEnabled() throws Exception {
+ scratch.file(
+ rootDirectory.getRelative("MODULE.bazel").getPathString(),
+ "use_extension('//:extensions.bzl', 'my_ext', isolate = True)");
+ FakeRegistry registry = registryFactory.newFakeRegistry("/foo");
+ ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl()));
+
+ reporter.removeHandler(failFastHandler); // expect failures
+ evaluator.evaluate(ImmutableList.of(ModuleFileValue.KEY_FOR_ROOT_MODULE), evaluationContext);
+ assertContainsEvent(
+ "Error in use_extension: in call to use_extension(), parameter 'isolate' is experimental "
+ + "and thus unavailable with the current flags. It may be enabled by setting "
+ + "--experimental_isolated_extension_usages");
+ }
}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/semantics/ConsistencyTest.java b/src/test/java/com/google/devtools/build/lib/packages/semantics/ConsistencyTest.java
index 4cf733d5057d12..246bbe7e4b67ee 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/semantics/ConsistencyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/semantics/ConsistencyTest.java
@@ -128,6 +128,7 @@ private static BuildLanguageOptions buildRandomOptions(Random rand) throws Excep
"--experimental_bzl_visibility=" + rand.nextBoolean(),
"--experimental_enable_android_migration_apis=" + rand.nextBoolean(),
"--enable_bzlmod=" + rand.nextBoolean(),
+ "--experimental_isolated_extension_usages=" + rand.nextBoolean(),
"--experimental_google_legacy_api=" + rand.nextBoolean(),
"--experimental_platforms_api=" + rand.nextBoolean(),
"--incompatible_allow_tags_propagation=" + rand.nextBoolean(), // flag, Java names differ
@@ -170,6 +171,7 @@ private static StarlarkSemantics buildRandomSemantics(Random rand) {
.setBool(
BuildLanguageOptions.EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS, rand.nextBoolean())
.setBool(BuildLanguageOptions.ENABLE_BZLMOD, rand.nextBoolean())
+ .setBool(BuildLanguageOptions.EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, rand.nextBoolean())
.setBool(BuildLanguageOptions.EXPERIMENTAL_GOOGLE_LEGACY_API, rand.nextBoolean())
.setBool(BuildLanguageOptions.EXPERIMENTAL_PLATFORMS_API, rand.nextBoolean())
.setBool(BuildLanguageOptions.EXPERIMENTAL_ALLOW_TAGS_PROPAGATION, rand.nextBoolean())
diff --git a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py
index 76f603b48e9c4c..f145c633d301b5 100644
--- a/src/test/py/bazel/bzlmod/bazel_lockfile_test.py
+++ b/src/test/py/bazel/bzlmod/bazel_lockfile_test.py
@@ -45,6 +45,7 @@ def setUp(self):
# In ipv6 only network, this has to be enabled.
# 'startup --host_jvm_args=-Djava.net.preferIPv6Addresses=true',
'common --enable_bzlmod',
+ 'common --experimental_isolated_extension_usages',
'common --registry=' + self.main_registry.getURL(),
# We need to have BCR here to make sure built-in modules like
# bazel_tools can work.