Skip to content

Commit 7de9000

Browse files
committed
Turn on unambiguous label stringification by default
Fixes #15916 Fixes #16196 PiperOrigin-RevId: 470939938 Change-Id: I38caf7879fb82c72e07ef11a96be20ade5ac5401
1 parent 9edede0 commit 7de9000

21 files changed

+302
-299
lines changed

src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class CoreOptions extends FragmentOptions implements Cloneable {
8080

8181
@Option(
8282
name = "incompatible_use_platforms_repo_for_constraints",
83-
defaultValue = "true",
83+
defaultValue = "false",
8484
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
8585
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
8686
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},

src/main/java/com/google/devtools/build/lib/packages/semantics/BuildLanguageOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public final class BuildLanguageOptions extends OptionsBase {
523523

524524
@Option(
525525
name = "incompatible_unambiguous_label_stringification",
526-
defaultValue = "false",
526+
defaultValue = "true",
527527
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
528528
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
529529
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
@@ -759,7 +759,7 @@ public StarlarkSemantics toStarlarkSemantics() {
759759
public static final String INCOMPATIBLE_USE_CC_CONFIGURE_FROM_RULES_CC =
760760
"-incompatible_use_cc_configure_from_rules";
761761
public static final String INCOMPATIBLE_UNAMBIGUOUS_LABEL_STRINGIFICATION =
762-
"-incompatible_unambiguous_label_stringification";
762+
"+incompatible_unambiguous_label_stringification";
763763
public static final String INCOMPATIBLE_VISIBILITY_PRIVATE_ATTRIBUTES_AT_DEFINITION =
764764
"-incompatible_visibility_private_attributes_at_definition";
765765
public static final String INCOMPATIBLE_TOP_LEVEL_ASPECTS_REQUIRE_PROVIDERS =

src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void testGetArtifactOwnerInStarlark() throws Exception {
184184
scratch.file("foo/BUILD", "load(':rule.bzl', 'gen')", "gen(name = 'a')");
185185

186186
update("//foo:a");
187-
assertContainsEvent("DEBUG /workspace/foo/rule.bzl:3:8: f owner is //foo:a");
187+
assertContainsEvent("DEBUG /workspace/foo/rule.bzl:3:8: f owner is @//foo:a");
188188
}
189189

190190
@Test

src/test/java/com/google/devtools/build/lib/analysis/StarlarkAttrTransitionProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ private void writeReadAndPassthroughOptionsTestFiles() throws Exception {
562562
"settings_under_test = {",
563563
" '//command_line_option:cpu': 'armeabi-v7a',",
564564
" '//command_line_option:compilation_mode': 'dbg',",
565-
" '//command_line_option:crosstool_top': '//android/crosstool:everything',",
565+
" '//command_line_option:crosstool_top': '@//android/crosstool:everything',",
566566
" '//command_line_option:platform_suffix': 'my-platform-suffix',",
567567
"}",
568568
"def set_options_transition_func(settings, attr):",

src/test/java/com/google/devtools/build/lib/analysis/test/TestActionBuilderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void testAspectOverNonExpandingTestSuitesVisitsImplicitTests() throws Exc
219219
new StarlarkProvider.Key(Label.parseAbsoluteUnchecked("//:aspect.bzl"), "StructImpl");
220220
StructImpl info = (StructImpl) aspectValue.get(key);
221221
assertThat(((Depset) info.getValue("labels")).getSet(String.class).toList())
222-
.containsExactly("//:suite", "//:test_a", "//:test_b");
222+
.containsExactly("@//:suite", "@//:test_a", "@//:test_b");
223223
}
224224

225225
@Test
@@ -252,7 +252,7 @@ public void testAspectOverNonExpandingTestSuitesVisitsExplicitTests() throws Exc
252252
new StarlarkProvider.Key(Label.parseAbsoluteUnchecked("//:aspect.bzl"), "StructImpl");
253253
StructImpl info = (StructImpl) aspectValue.get(key);
254254
assertThat(((Depset) info.getValue("labels")).getSet(String.class).toList())
255-
.containsExactly("//:suite", "//:test_b");
255+
.containsExactly("@//:suite", "@//:test_b");
256256
}
257257

258258
@Test
@@ -285,7 +285,7 @@ public void testAspectOverExpandingTestSuitesDoesNotVisitSuite() throws Exceptio
285285
StructImpl info = (StructImpl) a.get(key);
286286
labels.addAll(((Depset) info.getValue("labels")).getSet(String.class).toList());
287287
}
288-
assertThat(labels).containsExactly("//:test_a", "//:test_b");
288+
assertThat(labels).containsExactly("@//:test_a", "@//:test_b");
289289
}
290290

291291
private void writeLabelCollectionAspect() throws IOException {

src/test/java/com/google/devtools/build/lib/buildtool/KeepGoingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public void testConfigurationErrorsAreToleratedWithKeepGoing() throws Exception
259259
assertBuildFailedExceptionFromBuilding(
260260
"command succeeded, but not all targets were analyzed", "//a", "//b");
261261
events.assertContainsError(
262-
"in srcs attribute of cc_library rule //a:a: source file '//a:missing.foo' is misplaced"
262+
"in srcs attribute of cc_library rule @//a:a: source file '@//a:missing.foo' is misplaced"
263263
+ " here");
264264
events.assertContainsInfo("Analysis succeeded for only 1 of 2 top-level targets");
265265

src/test/java/com/google/devtools/build/lib/cmdline/LabelTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public void testWorkspaceName() throws Exception {
515515
@Test
516516
public void starlarkStrAndRepr() throws Exception {
517517
Label label = Label.parseCanonical("//x");
518-
assertThat(Starlark.str(label, StarlarkSemantics.DEFAULT)).isEqualTo("//x:x");
518+
assertThat(Starlark.str(label, StarlarkSemantics.DEFAULT)).isEqualTo("@//x:x");
519519
assertThat(Starlark.repr(label)).isEqualTo("Label(\"//x:x\")");
520520

521521
label = Label.parseCanonical("@hello//x");
@@ -524,31 +524,31 @@ public void starlarkStrAndRepr() throws Exception {
524524
}
525525

526526
@Test
527-
public void starlarkStr_unambiguous() throws Exception {
527+
public void starlarkStr_ambiguous() throws Exception {
528528
StarlarkSemantics semantics =
529529
StarlarkSemantics.builder()
530-
.setBool(BuildLanguageOptions.INCOMPATIBLE_UNAMBIGUOUS_LABEL_STRINGIFICATION, true)
530+
.setBool(BuildLanguageOptions.INCOMPATIBLE_UNAMBIGUOUS_LABEL_STRINGIFICATION, false)
531531
.build();
532-
assertThat(Starlark.str(Label.parseCanonical("//x"), semantics)).isEqualTo("@//x:x");
532+
assertThat(Starlark.str(Label.parseCanonical("//x"), semantics)).isEqualTo("//x:x");
533533
assertThat(Starlark.str(Label.parseCanonical("@x//y"), semantics)).isEqualTo("@x//y:y");
534534
}
535535

536536
@Test
537537
public void starlarkStr_canonicalLabelLiteral() throws Exception {
538538
StarlarkSemantics semantics =
539539
StarlarkSemantics.builder().setBool(BuildLanguageOptions.ENABLE_BZLMOD, true).build();
540-
assertThat(Starlark.str(Label.parseCanonical("//x"), semantics)).isEqualTo("//x:x");
540+
assertThat(Starlark.str(Label.parseCanonical("//x"), semantics)).isEqualTo("@@//x:x");
541541
assertThat(Starlark.str(Label.parseCanonical("@x//y"), semantics)).isEqualTo("@@x//y:y");
542542
}
543543

544544
@Test
545-
public void starlarkStr_unambiguousAndCanonicalLabelLiteral() throws Exception {
545+
public void starlarkStr_ambiguousAndCanonicalLabelLiteral() throws Exception {
546546
StarlarkSemantics semantics =
547547
StarlarkSemantics.builder()
548-
.setBool(BuildLanguageOptions.INCOMPATIBLE_UNAMBIGUOUS_LABEL_STRINGIFICATION, true)
548+
.setBool(BuildLanguageOptions.INCOMPATIBLE_UNAMBIGUOUS_LABEL_STRINGIFICATION, false)
549549
.setBool(BuildLanguageOptions.ENABLE_BZLMOD, true)
550550
.build();
551-
assertThat(Starlark.str(Label.parseCanonical("//x"), semantics)).isEqualTo("@@//x:x");
551+
assertThat(Starlark.str(Label.parseCanonical("//x"), semantics)).isEqualTo("//x:x");
552552
assertThat(Starlark.str(Label.parseCanonical("@x//y"), semantics)).isEqualTo("@@x//y:y");
553553
}
554554
}

src/test/java/com/google/devtools/build/lib/rules/android/AbstractAndroidLocalTestTestBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ public void testFeatureFlagsAttributeSetsFeatureFlagProviderValues() throws Exce
318318
"/FooFlags.java");
319319
FileWriteAction action = (FileWriteAction) getGeneratingAction(flagList);
320320
assertThat(action.getFileContents())
321-
.isEqualTo("//java/com/foo:flag1: on\n//java/com/foo:flag2: off");
321+
.isAnyOf(
322+
"//java/com/foo:flag1: on\n//java/com/foo:flag2: off",
323+
"@//java/com/foo:flag1: on\n@//java/com/foo:flag2: off");
322324
}
323325

324326
@Test

src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3777,7 +3777,7 @@ public void testFeatureFlagsAttributeSetsFeatureFlagProviderValues() throws Exce
37773777
"/FooFlags.java");
37783778
FileWriteAction action = (FileWriteAction) getGeneratingAction(flagList);
37793779
assertThat(action.getFileContents())
3780-
.isEqualTo("//java/com/foo:flag1: on\n//java/com/foo:flag2: off");
3780+
.isEqualTo("@//java/com/foo:flag1: on\n@//java/com/foo:flag2: off");
37813781
}
37823782

37833783
@Test

src/test/java/com/google/devtools/build/lib/rules/cpp/CcBadDependenciesTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ private ConfiguredTarget configure(String targetLabel) throws Exception {
3030
@Test
3131
public void testRejectsSingleUnknownSourceFile() throws Exception {
3232
reporter.removeHandler(failFastHandler);
33-
scratch.file("foo/BUILD",
34-
"cc_library(name = 'foo', srcs = ['unknown.oops'])");
33+
scratch.file("foo/BUILD", "cc_library(name = 'foo', srcs = ['unknown.oops'])");
3534
scratch.file("foo/unknown.oops", "foo");
3635
configure("//foo:foo");
37-
assertContainsEvent(getErrorMsgMisplacedFiles(
38-
"srcs", "cc_library", "//foo:foo", "//foo:unknown.oops"));
36+
assertContainsEvent(
37+
getErrorMsgMisplacedFiles("srcs", "cc_library", "@//foo:foo", "@//foo:unknown.oops"));
3938
}
4039

4140
@Test
@@ -65,6 +64,6 @@ public void testRejectsBadGeneratedFile() throws Exception {
6564
assertContainsEvent(
6665
String.format(
6766
"attribute srcs: '%s' does not produce any cc_library srcs files",
68-
"//dependency:generated"));
67+
"@//dependency:generated"));
6968
}
7069
}

src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoCommonTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,11 @@ public void shouldGenerateCode_mixed() throws Exception {
580580
getConfiguredTarget("//bar:simple");
581581

582582
assertContainsEvent(
583-
"The 'srcs' attribute of '//third_party/x:mixed' contains protos for which 'MyRule'"
583+
"The 'srcs' attribute of '@//third_party/x:mixed' contains protos for which 'MyRule'"
584584
+ " shouldn't generate code (third_party/x/metadata.proto,"
585585
+ " third_party/x/descriptor.proto), in addition to protos for which it should"
586586
+ " (third_party/x/something.proto).\n"
587-
+ "Separate '//third_party/x:mixed' into 2 proto_library rules.");
587+
+ "Separate '@//third_party/x:mixed' into 2 proto_library rules.");
588588
}
589589

590590
/** Verifies <code>proto_common.declare_generated_files</code> call. */

src/test/java/com/google/devtools/build/lib/rules/python/PythonSrcsVersionAspectTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public void simpleCase() throws Exception {
7878
"<None>",
7979
"",
8080
"Python 3-only deps:",
81-
"//pkg:lib",
81+
"@//pkg:lib",
8282
"",
8383
"Paths to these deps:",
84-
"//pkg:bin -> //pkg:lib",
84+
"@//pkg:bin -> @//pkg:lib",
8585
"");
8686
assertThat(result).isEqualTo(golden);
8787
}
@@ -138,14 +138,14 @@ public void twoContradictoryRequirements() throws Exception {
138138
String golden =
139139
join(
140140
"Python 2-only deps:",
141-
"//pkg:lib2",
141+
"@//pkg:lib2",
142142
"",
143143
"Python 3-only deps:",
144-
"//pkg:lib3",
144+
"@//pkg:lib3",
145145
"",
146146
"Paths to these deps:",
147-
"//pkg:bin -> //pkg:lib2",
148-
"//pkg:bin -> //pkg:lib3",
147+
"@//pkg:bin -> @//pkg:lib2",
148+
"@//pkg:bin -> @//pkg:lib3",
149149
"");
150150
assertThat(result).isEqualTo(golden);
151151
}
@@ -168,10 +168,10 @@ public void toplevelSelfContradictory() throws Exception {
168168
"<None>",
169169
"",
170170
"Python 3-only deps:",
171-
"//pkg:bin",
171+
"@//pkg:bin",
172172
"",
173173
"Paths to these deps:",
174-
"//pkg:bin",
174+
"@//pkg:bin",
175175
"");
176176
assertThat(result).isEqualTo(golden);
177177
}
@@ -209,10 +209,10 @@ public void indirectDependencies() throws Exception {
209209
"<None>",
210210
"",
211211
"Python 3-only deps:",
212-
"//pkg:libB",
212+
"@//pkg:libB",
213213
"",
214214
"Paths to these deps:",
215-
"//pkg:bin -> //pkg:libC -> //pkg:libB",
215+
"@//pkg:bin -> @//pkg:libC -> @//pkg:libB",
216216
"");
217217
assertThat(result).isEqualTo(golden);
218218
}
@@ -251,10 +251,10 @@ public void onlyReportTopmost() throws Exception {
251251
"<None>",
252252
"",
253253
"Python 3-only deps:",
254-
"//pkg:libC",
254+
"@//pkg:libC",
255255
"",
256256
"Paths to these deps:",
257-
"//pkg:bin -> //pkg:libC",
257+
"@//pkg:bin -> @//pkg:libC",
258258
"");
259259
assertThat(result).isEqualTo(golden);
260260
}
@@ -294,12 +294,12 @@ public void oneTopmostReachesAnother() throws Exception {
294294
"<None>",
295295
"",
296296
"Python 3-only deps:",
297-
"//pkg:libA",
298-
"//pkg:libC",
297+
"@//pkg:libA",
298+
"@//pkg:libC",
299299
"",
300300
"Paths to these deps:",
301-
"//pkg:bin -> //pkg:libA",
302-
"//pkg:bin -> //pkg:libC",
301+
"@//pkg:bin -> @//pkg:libA",
302+
"@//pkg:bin -> @//pkg:libC",
303303
"");
304304
assertThat(result).isEqualTo(golden);
305305
}
@@ -338,10 +338,10 @@ public void multiplePathsToRequirement() throws Exception {
338338
"<None>",
339339
"",
340340
"Python 3-only deps:",
341-
"//pkg:libA",
341+
"@//pkg:libA",
342342
"",
343343
"Paths to these deps:",
344-
"//pkg:bin -> //pkg:libB -> //pkg:libA",
344+
"@//pkg:bin -> @//pkg:libB -> @//pkg:libA",
345345
"");
346346
assertThat(result).isEqualTo(golden);
347347
}
@@ -391,10 +391,10 @@ public void noSrcsVersionButIntroducesRequirement() throws Exception {
391391
"<None>",
392392
"",
393393
"Python 3-only deps:",
394-
"//pkg:libB",
394+
"@//pkg:libB",
395395
"",
396396
"Paths to these deps:",
397-
"//pkg:bin -> //pkg:libC -> //pkg:libB",
397+
"@//pkg:bin -> @//pkg:libC -> @//pkg:libB",
398398
"");
399399
assertThat(result).isEqualTo(golden);
400400
}

0 commit comments

Comments
 (0)