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

[6.3.1] Mark isolated extension usages as experimental #19050

Merged
merged 1 commit into from
Jul 25, 2023
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 @@ -128,8 +128,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 @@ -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."
+ "<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 @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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.EXPERIMENTAL_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',
'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.
Expand Down