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

Mark isolated extension usages as experimental #19021

Closed
Closed
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 @@ -130,8 +130,11 @@ public boolean isDevDependency(TypeCheckedTag tag) {
name = "is_isolated",
doc =
"Whether this particular usage of the extension had <code>isolate = True</code> "
+ "specified and is thus isolated from all other usages.",
structField = true)
+ "specified and is thus isolated from all other usages."
+ "<p>This field is currently experimental and only available with the flag "
+ "<code>--experimental_isolated_extension_usages</code>.",
structField = true,
enableOnlyWithFlag = "-experimental_isolated_extension_usages")
public boolean isIsolated() {
return extensionId.getIsolationKey().isPresent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,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."
+ "<p>This parameter is currently experimental and only available with the "
+ "flag <code>--experimental_isolated_extension_usages</code>.",
named = true,
positional = false,
defaultValue = "False"),
defaultValue = "False",
enableOnlyWithFlag = "-experimental_isolated_extension_usages",
valueWhenDisabled = "False"),
},
useStarlarkThread = true)
public ModuleExtensionProxy useExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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",
Expand Down Expand Up @@ -696,6 +704,7 @@ public StarlarkSemantics toStarlarkSemantics() {
EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS, experimentalEnableAndroidMigrationApis)
.setBool(EXPERIMENTAL_ENABLE_SCL_DIALECT, experimentalEnableSclDialect)
.setBool(ENABLE_BZLMOD, enableBzlmod)
.setBool(EXPERIMENTAL_ISOLATED_EXTENSION_USAGES, experimentalIsolatedExtensionUsages)
.setBool(
EXPERIMENTAL_JAVA_PROTO_LIBRARY_DEFAULT_HAS_SERVICES,
experimentalJavaProtoLibraryDefaultHasServices)
Expand Down Expand Up @@ -791,6 +800,8 @@ public StarlarkSemantics toStarlarkSemantics() {
"-experimental_enable_android_migration_apis";
public static final String EXPERIMENTAL_ENABLE_SCL_DIALECT = "-experimental_enable_scl_dialect";
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand All @@ -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)");
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.INCOMPATIBLE_ALLOW_TAGS_PROPAGATION, rand.nextBoolean())
Expand Down
1 change: 1 addition & 0 deletions src/test/py/bazel/bzlmod/bazel_lockfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def setUp(self):
# In ipv6 only network, this has to be enabled.
# 'startup --host_jvm_args=-Djava.net.preferIPv6Addresses=true',
'build --enable_bzlmod',
'build --experimental_isolated_extension_usages',
'build --registry=' + self.main_registry.getURL(),
# We need to have BCR here to make sure built-in modules like
# bazel_tools can work.
Expand Down
Loading