Create --incompatible_remap_main_repo flag.
This flag fixes a bug in bazel where within a repository called "foo", the labels @foo//some/path:bar.bzl and //some/path:bar.bzl were treated as different labels. It is unlikely that this flag will affect any projects but it is technically a breaking change and so it is guarded behind a flag.
Towards #7130
RELNOTES: None
PiperOrigin-RevId: 229813128
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
index 8e63157..c398b2f 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java
@@ -118,14 +118,6 @@
public List<String> experimentalJavaCommonCreateProviderEnabledPackages;
@Option(
- name = "experimental_remap_main_repo",
- defaultValue = "false",
- documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
- effectTags = OptionEffectTag.LOADING_AND_ANALYSIS,
- help = "If set to true, will treat references to '@<main repo name>' the same as '@'.")
- public boolean experimentalRemapMainRepo;
-
- @Option(
name = "experimental_platforms_api",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
@@ -449,6 +441,19 @@
public boolean incompatibleNoTransitiveLoads;
@Option(
+ name = "incompatible_remap_main_repo",
+ defaultValue = "false",
+ documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
+ effectTags = OptionEffectTag.LOADING_AND_ANALYSIS,
+ metadataTags = {
+ OptionMetadataTag.INCOMPATIBLE_CHANGE,
+ OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
+ },
+ oldName = "experimental_remap_main_repo",
+ help = "If set to true, will treat references to '@<main repo name>' the same as '@'.")
+ public boolean incompatibleRemapMainRepo;
+
+ @Option(
name = "incompatible_remove_native_maven_jar",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
@@ -508,7 +513,6 @@
.experimentalCcSkylarkApiEnabledPackages(experimentalCcSkylarkApiEnabledPackages)
.experimentalEnableAndroidMigrationApis(experimentalEnableAndroidMigrationApis)
.experimentalEnableRepoMapping(experimentalEnableRepoMapping)
- .experimentalRemapMainRepo(experimentalRemapMainRepo)
.experimentalJavaCommonCreateProviderEnabledPackages(
experimentalJavaCommonCreateProviderEnabledPackages)
.experimentalPlatformsApi(experimentalPlatformsApi)
@@ -535,6 +539,7 @@
.incompatibleNoSupportToolsInActionInputs(incompatibleNoSupportToolsInActionInputs)
.incompatibleNoTargetOutputGroup(incompatibleNoTargetOutputGroup)
.incompatibleNoTransitiveLoads(incompatibleNoTransitiveLoads)
+ .incompatibleRemapMainRepo(incompatibleRemapMainRepo)
.incompatibleRemoveNativeMavenJar(incompatibleRemoveNativeMavenJar)
.incompatibleRequireFeatureConfigurationForPic(requireFeatureConfigurationForPic)
.incompatibleStricArgumentOrdering(incompatibleStricArgumentOrdering)
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
index 64cfbd5..8f58636 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
@@ -342,7 +342,7 @@
}
// Add entry in repository map from "@name" --> "@" to avoid issue where bazel
// treats references to @name as a separate external repo
- if (env.getSemantics().experimentalRemapMainRepo()) {
+ if (env.getSemantics().incompatibleRemapMainRepo()) {
builder.addRepositoryMappingEntry(
RepositoryName.MAIN,
RepositoryName.createFromValidStrippedName(name),
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactoryHelper.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactoryHelper.java
index db8dcac..58545db 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactoryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactoryHelper.java
@@ -99,7 +99,7 @@
*/
public static void addMainRepoEntry(
Package.Builder builder, String externalRepoName, SkylarkSemantics semantics) {
- if (semantics.experimentalRemapMainRepo()) {
+ if (semantics.incompatibleRemapMainRepo()) {
if (!Strings.isNullOrEmpty(builder.getPackageWorkspaceName())) {
builder.addRepositoryMappingEntry(
RepositoryName.createFromValidStrippedName(externalRepoName),
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
index 1c4cb65..4cb4ef9 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java
@@ -126,8 +126,6 @@
public abstract ImmutableList<String> experimentalJavaCommonCreateProviderEnabledPackages();
- public abstract boolean experimentalRemapMainRepo();
-
public abstract boolean experimentalPlatformsApi();
public abstract boolean experimentalStarlarkConfigTransitions();
@@ -174,6 +172,8 @@
public abstract boolean incompatibleNoTransitiveLoads();
+ public abstract boolean incompatibleRemapMainRepo();
+
public abstract boolean incompatibleRemoveNativeMavenJar();
public abstract boolean incompatibleRequireFeatureConfigurationForPic();
@@ -204,7 +204,6 @@
.experimentalEnableAndroidMigrationApis(false)
.experimentalEnableRepoMapping(false)
.experimentalJavaCommonCreateProviderEnabledPackages(ImmutableList.of())
- .experimentalRemapMainRepo(false)
.experimentalPlatformsApi(false)
.experimentalStarlarkConfigTransitions(false)
.experimentalTransitionWhitelistLocation("")
@@ -228,6 +227,7 @@
.incompatibleNoSupportToolsInActionInputs(false)
.incompatibleNoTargetOutputGroup(false)
.incompatibleNoTransitiveLoads(false)
+ .incompatibleRemapMainRepo(false)
.incompatibleRemoveNativeMavenJar(false)
.incompatibleRequireFeatureConfigurationForPic(true)
.incompatibleStricArgumentOrdering(false)
@@ -248,8 +248,6 @@
public abstract Builder experimentalEnableRepoMapping(boolean value);
- public abstract Builder experimentalRemapMainRepo(boolean value);
-
public abstract Builder experimentalJavaCommonCreateProviderEnabledPackages(List<String> value);
public abstract Builder experimentalPlatformsApi(boolean value);
@@ -300,6 +298,8 @@
public abstract Builder incompatibleNoTransitiveLoads(boolean value);
+ public abstract Builder incompatibleRemapMainRepo(boolean value);
+
public abstract Builder incompatibleRemoveNativeMavenJar(boolean value);
public abstract Builder incompatibleStricArgumentOrdering(boolean value);
diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
index 0ea7ef7..b31a3d5 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
@@ -130,7 +130,6 @@
+ ","
+ rand.nextDouble(),
"--experimental_platforms_api=" + rand.nextBoolean(),
- "--experimental_remap_main_repo=" + rand.nextBoolean(),
"--experimental_starlark_config_transitions=" + rand.nextBoolean(),
"--experimental_transition_whitelist_location=" + rand.nextDouble(),
"--incompatible_bzl_disallow_load_after_statement=" + rand.nextBoolean(),
@@ -153,6 +152,7 @@
"--incompatible_no_support_tools_in_action_inputs=" + rand.nextBoolean(),
"--incompatible_no_target_output_group=" + rand.nextBoolean(),
"--incompatible_no_transitive_loads=" + rand.nextBoolean(),
+ "--incompatible_remap_main_repo=" + rand.nextBoolean(),
"--incompatible_remove_native_maven_jar=" + rand.nextBoolean(),
"--incompatible_require_feature_configuration_for_pic=" + rand.nextBoolean(),
"--incompatible_strict_argument_ordering=" + rand.nextBoolean(),
@@ -175,7 +175,6 @@
.experimentalJavaCommonCreateProviderEnabledPackages(
ImmutableList.of(String.valueOf(rand.nextDouble()), String.valueOf(rand.nextDouble())))
.experimentalPlatformsApi(rand.nextBoolean())
- .experimentalRemapMainRepo(rand.nextBoolean())
.experimentalStarlarkConfigTransitions(rand.nextBoolean())
.experimentalTransitionWhitelistLocation(String.valueOf(rand.nextDouble()))
.incompatibleBzlDisallowLoadAfterStatement(rand.nextBoolean())
@@ -198,6 +197,7 @@
.incompatibleNoSupportToolsInActionInputs(rand.nextBoolean())
.incompatibleNoTargetOutputGroup(rand.nextBoolean())
.incompatibleNoTransitiveLoads(rand.nextBoolean())
+ .incompatibleRemapMainRepo(rand.nextBoolean())
.incompatibleRemoveNativeMavenJar(rand.nextBoolean())
.incompatibleRequireFeatureConfigurationForPic(rand.nextBoolean())
.incompatibleStricArgumentOrdering(rand.nextBoolean())
diff --git a/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java
index 95fdca0..bcd395f 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java
@@ -204,7 +204,7 @@
@Test
public void testImplicitMainRepoRename() throws Exception {
- helper.setSkylarkSemantics("--experimental_remap_main_repo");
+ helper.setSkylarkSemantics("--incompatible_remap_main_repo");
helper.parse("workspace(name = 'foo')");
assertMapping(helper, "@", "@foo", "@");
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java
index f7d10db..7da92b6 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java
@@ -146,7 +146,7 @@
@Test
public void testDefaultMainRepoNameInMapping() throws Exception {
- setSkylarkSemanticsOptions("--experimental_remap_main_repo");
+ setSkylarkSemanticsOptions("--incompatible_remap_main_repo");
scratch.overwriteFile(
"WORKSPACE",
"local_repository(",
@@ -168,7 +168,7 @@
@Test
public void testExplicitMainRepoNameInMapping() throws Exception {
- setSkylarkSemanticsOptions("--experimental_remap_main_repo");
+ setSkylarkSemanticsOptions("--incompatible_remap_main_repo");
scratch.overwriteFile(
"WORKSPACE",
"workspace(name = 'good')",
diff --git a/src/test/shell/bazel/workspace_test.sh b/src/test/shell/bazel/workspace_test.sh
index 5e0bdb7..1bc7ab9 100755
--- a/src/test/shell/bazel/workspace_test.sh
+++ b/src/test/shell/bazel/workspace_test.sh
@@ -726,7 +726,7 @@
EOF
cd mainrepo
- bazel query --experimental_remap_main_repo //... &>"$TEST_log" \
+ bazel query --incompatible_remap_main_repo //... &>"$TEST_log" \
|| fail "Expected query to succeed"
expect_log "def.bzl loaded"
expect_not_log "external"
@@ -754,7 +754,7 @@
# the bzl file should be loaded from the main workspace and
# not as an external repository
cd mainrepo
- bazel query --experimental_remap_main_repo @a//... &>"$TEST_log" \
+ bazel query --incompatible_remap_main_repo @a//... &>"$TEST_log" \
|| fail "Expected query to succeed"
expect_log "def.bzl loaded"
expect_not_log "external"
@@ -772,7 +772,7 @@
# now that @mainrepo doesn't exist within workspace "a",
# the query should fail
cd mainrepo
- bazel query --experimental_remap_main_repo \
+ bazel query --incompatible_remap_main_repo \
@a//... &>"$TEST_log" \
&& fail "Failure expected" || true
}