Skip to content

Commit e899d85

Browse files
brandjoncopybara-github
authored andcommitted
Flip package_group incompatible flags
The three flipped flags are: --incompatible_package_group_includes_double_slash, --incompatible_package_group_has_public_syntax, and --incompatible_fix_package_group_reporoot_syntax. The first is a common query flag, and the latter two are stored in starlark semantics. Logically, these are all one flag that migrates package_group to use `public` instead of `//...`, which now means "this repo only". A side-effect of this change is that //src/main/java/net/starlark/java:clients is no longer publicly visible. In order to not break bootstrapping from prior Bazel versions, we will tolerate this regression until after the 6.0 release. The Java Starlark interpreter is not a publicly supported API anyway; its main users are Copybara and Stardoc, both of which can simply avoid vendoring-in the 6.0 version. The //tools source tree is updated to move some allowlist definitions from BUILD files into BUILD.tools files. This works around a bootstrapping issue. The allowlist definitions are not needed at development time for Bazel itself, except for one test that incorrectly referred to a label under the main repo instead of @bazel_tools. Updated a few test setups to use "public" in place of "//...". These flags are not yet flipped in Blaze at Google. Our ordinary mechanism for controlling flags with a bazelrc file does not work in this particular case. Therefore, this CL takes the unusual step of factoring out the default values into string constants in stub files (FlagConstants.java) that differ between the internal and external source trees. This hack will be reverted once the flags are flipped in Blaze. Fixes #16391. Fixes #16355. Fixes #16323. Work toward #11261. RELNOTES[INC]: In package_group's `packages` attribute, the syntax "//..." now refers to all packages in the same repository as the package group, rather than all packages everywhere. The new item "public" can be used instead to obtain the old behavior. In `bazel query --output=proto` (and `--output=xml`), the `packages` attribute now serializes with the leading double slash included (for instance, `//foo/bar/...` instead of `foo/bar/...`). See also #16355, #16323, and #16391. PiperOrigin-RevId: 482023278 Change-Id: If86703d279dd3cd18b6b3948f37720816ada465f
1 parent 63aace2 commit e899d85

File tree

21 files changed

+166
-52
lines changed

21 files changed

+166
-52
lines changed

src/main/java/com/google/devtools/build/lib/packages/semantics/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ filegroup(
1515
# so it may not depend on (say) Label.
1616
java_library(
1717
name = "semantics",
18-
srcs = ["BuildLanguageOptions.java"],
18+
srcs = [
19+
"BuildLanguageOptions.java",
20+
"FlagConstants.java",
21+
],
1922
deps = [
2023
"//src/main/java/com/google/devtools/build/lib/concurrent",
2124
"//src/main/java/com/google/devtools/common/options",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public final class BuildLanguageOptions extends OptionsBase {
452452

453453
@Option(
454454
name = "incompatible_package_group_has_public_syntax",
455-
defaultValue = "false",
455+
defaultValue = FlagConstants.DEFAULT_INCOMPATIBLE_PACKAGE_GROUP_HAS_PUBLIC_SYNTAX,
456456
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
457457
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
458458
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
@@ -463,7 +463,7 @@ public final class BuildLanguageOptions extends OptionsBase {
463463

464464
@Option(
465465
name = "incompatible_fix_package_group_reporoot_syntax",
466-
defaultValue = "false",
466+
defaultValue = FlagConstants.DEFAULT_INCOMPATIBLE_FIX_PACKAGE_GROUP_REPOROOT_SYNTAX,
467467
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
468468
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
469469
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
@@ -803,9 +803,9 @@ public StarlarkSemantics toStarlarkSemantics() {
803803
public static final String INCOMPATIBLE_DISALLOW_STRUCT_PROVIDER_SYNTAX =
804804
"-incompatible_disallow_struct_provider_syntax";
805805
public static final String INCOMPATIBLE_PACKAGE_GROUP_HAS_PUBLIC_SYNTAX =
806-
"-incompatible_package_group_has_public_syntax";
806+
FlagConstants.INCOMPATIBLE_PACKAGE_GROUP_HAS_PUBLIC_SYNTAX;
807807
public static final String INCOMPATIBLE_FIX_PACKAGE_GROUP_REPOROOT_SYNTAX =
808-
"-incompatible_fix_package_group_reporoot_syntax";
808+
FlagConstants.INCOMPATIBLE_FIX_PACKAGE_GROUP_REPOROOT_SYNTAX;
809809
public static final String INCOMPATIBLE_DO_NOT_SPLIT_LINKING_CMDLINE =
810810
"+incompatible_do_not_split_linking_cmdline";
811811
public static final String INCOMPATIBLE_JAVA_COMMON_PARAMETERS =
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.devtools.build.lib.packages.semantics;
16+
17+
/** This file holds hardcoded flag defaults that vary between Bazel and Blaze. */
18+
// TODO(b/254084490): This file is a temporary hack. Eliminate once we've flipped the incompatible
19+
// flag in Blaze.
20+
class FlagConstants {
21+
22+
private FlagConstants() {}
23+
24+
public static final String DEFAULT_INCOMPATIBLE_PACKAGE_GROUP_HAS_PUBLIC_SYNTAX = "true";
25+
public static final String DEFAULT_INCOMPATIBLE_FIX_PACKAGE_GROUP_REPOROOT_SYNTAX = "true";
26+
27+
public static final String INCOMPATIBLE_PACKAGE_GROUP_HAS_PUBLIC_SYNTAX =
28+
"+incompatible_package_group_has_public_syntax";
29+
public static final String INCOMPATIBLE_FIX_PACKAGE_GROUP_REPOROOT_SYNTAX =
30+
"+incompatible_fix_package_group_reporoot_syntax";
31+
}

src/main/java/com/google/devtools/build/lib/query2/common/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ java_library(
3232
name = "options",
3333
srcs = [
3434
"CommonQueryOptions.java",
35+
"FlagConstants.java",
3536
],
3637
deps = [
3738
"//src/main/java/com/google/devtools/build/lib/query2/engine",

src/main/java/com/google/devtools/build/lib/query2/common/CommonQueryOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public String getLineTerminator() {
139139

140140
@Option(
141141
name = "incompatible_package_group_includes_double_slash",
142-
defaultValue = "false",
142+
defaultValue = FlagConstants.DEFAULT_INCOMPATIBLE_PACKAGE_GROUP_INCLUDES_DOUBLE_SLASH,
143143
documentationCategory = OptionDocumentationCategory.QUERY,
144144
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
145145
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2022 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.devtools.build.lib.query2.common;
16+
17+
/** This file holds hardcoded flag defaults that vary between Bazel and Blaze. */
18+
// TODO(b/254084490): This file is a temporary hack. Eliminate once we've flipped the incompatible
19+
// flag in Blaze.
20+
class FlagConstants {
21+
22+
private FlagConstants() {}
23+
24+
static final String DEFAULT_INCOMPATIBLE_PACKAGE_GROUP_INCLUDES_DOUBLE_SLASH = "true";
25+
}

src/main/java/net/starlark/java/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ package_group(
2626
# Approved clients of java.starlark.net.
2727
package_group(
2828
name = "clients",
29+
# TODO(#11261, 16355): The meaning of `//...` changed from "public" to "this
30+
# repo only" in Bazel 6.0. Switch this to `public` in a subsequent release.
31+
# (This must remain `//...` in 6.0 to allow bootstrapping Bazel with 5.x.)
2932
packages = ["//..."], # anyone
3033
)

src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
362362

363363
config.create(
364364
"tools/allowlists/config_feature_flag/BUILD",
365-
"package_group(name='config_feature_flag', packages=['//...'])",
366-
"package_group(name='config_feature_flag_Setter', packages=['//...'])");
365+
"package_group(name='config_feature_flag', packages=['public'])",
366+
"package_group(name='config_feature_flag_Setter', packages=['public'])");
367367

368368
config.create(
369369
"embedded_tools/tools/proto/BUILD",
@@ -541,10 +541,10 @@ private ImmutableList<String> createAndroidBuildContents() {
541541
.add(" generates_api = 1,")
542542
.add(" processor_class = 'android.databinding.annotationprocessor.ProcessDataBinding')")
543543
.add("sh_binary(name = 'instrumentation_test_check', srcs = ['empty.sh'])")
544-
.add("package_group(name = 'android_device_allowlist', packages = ['//...'])")
545-
.add("package_group(name = 'export_deps_allowlist', packages = ['//...'])")
544+
.add("package_group(name = 'android_device_allowlist', packages = ['public'])")
545+
.add("package_group(name = 'export_deps_allowlist', packages = ['public'])")
546546
.add("package_group(name = 'allow_android_library_deps_without_srcs_allowlist',")
547-
.add(" packages=['//...'])")
547+
.add(" packages=['public'])")
548548
.add("android_tools_defaults_jar(name = 'android_jar')")
549549
.add("sh_binary(name = 'dex_list_obfuscator', srcs = ['empty.sh'])");
550550

src/test/java/com/google/devtools/build/lib/packages/PackageGroupTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ public void testNothingSpecificationWorks() throws Exception {
255255

256256
@Test
257257
public void testPublicPrivateAreNotAccessibleWithoutFlag() throws Exception {
258-
setBuildLanguageOptions("--incompatible_package_group_has_public_syntax=false");
258+
setBuildLanguageOptions(
259+
// Flag being tested
260+
"--incompatible_package_group_has_public_syntax=false",
261+
// Must also be disabled in order to disable the above
262+
"--incompatible_fix_package_group_reporoot_syntax=false");
259263

260264
scratch.file(
261265
"foo/BUILD", //

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ public void testPackageWhitelist() throws Exception {
638638
String mockedAndroidToolsContent =
639639
scratch
640640
.readFile(mockedAndroidToolsBuildFileLocation)
641+
.replaceAll(Pattern.quote("packages = ['public']"), "packages = ['//bar/...']")
642+
// TODO(b/254084490): Migrate Google-internal usage of "//..." in test mock to be
643+
// "public" instead.
641644
.replaceAll(Pattern.quote("packages = ['//...']"), "packages = ['//bar/...']");
642645
scratch.overwriteFile(mockedAndroidToolsBuildFileLocation, mockedAndroidToolsContent);
643646
invalidatePackages();

src/test/shell/bazel/local_repository_test.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ EOF
13871387
expect_log "@x_repo//x to @x_repo//a"
13881388
}
13891389

1390-
# This test verifies that the //... pattern includes external dependencies
1390+
# This test verifies that the `public` pattern includes external dependencies.
13911391
#
13921392
# ${WORKSPACE_DIR}/
13931393
# WORKSPACE
@@ -1397,22 +1397,26 @@ EOF
13971397
# blue/
13981398
# BUILD
13991399
#
1400-
# repo2 contains a .sh file whose visibility is set to //...
1401-
# we verify that we can use this file from ${WORKSPACE_DIR} by running it as
1400+
# repo2 contains a .sh file whose visibility is set to public.
1401+
# We verify that we can use this file from ${WORKSPACE_DIR} by running it as
14021402
# part of the "run-the-thing" binary.
1403-
function test_slashslashdotdotdot_includes_external_dependencies() {
1403+
#
1404+
# TODO(brandjon): Can this test be deleted in favor of an analysis-time unit
1405+
# test? Ideally PackageGroupTest should cover it, but that suite can't handle
1406+
# external repos.
1407+
function test_public_includes_external_dependencies() {
14041408
create_new_workspace
14051409
repo2=${new_workspace_dir}
14061410
mkdir -p blue
14071411
cat > blue/BUILD <<EOF
14081412
package_group(
1409-
name = "slash-slash-dot-dot-dot",
1410-
packages = ["//..."],
1413+
name = "everyone",
1414+
packages = ["public"],
14111415
)
14121416
filegroup(
14131417
name = "do-the-thing",
14141418
srcs = ["do-the-thing.sh"],
1415-
visibility = [":slash-slash-dot-dot-dot"]
1419+
visibility = [":everyone"]
14161420
)
14171421
EOF
14181422
cat > blue/do-the-thing.sh <<EOF
@@ -1437,9 +1441,11 @@ EOF
14371441
expect_log "WE DID IT FAM"
14381442
}
14391443

1440-
## Like test above, but testing an external dep can depend on a local target
1441-
## with //... visibility
1442-
function test_slashslashdotdotdot_includes_main_repo_from_external_dep() {
1444+
# Like test above, but testing an external dep can depend on a local target with
1445+
# with `public` visibility.
1446+
#
1447+
# TODO(brandjon): Eliminate this test, as described above?
1448+
function test_public_includes_main_repo_from_external_dep() {
14431449
create_new_workspace
14441450
repo2=${new_workspace_dir}
14451451
mkdir -p blue
@@ -1457,13 +1463,13 @@ local_repository(name = 'blue', path = "${repo2}")
14571463
EOF
14581464
cat > green/BUILD <<EOF
14591465
package_group(
1460-
name = "slash-slash-dot-dot-dot",
1461-
packages = ["//..."],
1466+
name = "everyone",
1467+
packages = ["public"],
14621468
)
14631469
filegroup(
14641470
name = "do-the-thing",
14651471
srcs = ["do-the-thing.sh"],
1466-
visibility = [":slash-slash-dot-dot-dot"]
1472+
visibility = [":everyone"]
14671473
)
14681474
14691475
EOF

src/test/shell/bazel/platform_mapping_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ my_rule = rule(
184184
attrs = {
185185
"deps": attr.label_list(cfg = my_transition),
186186
"_allowlist_function_transition": attr.label(
187-
default = "@//tools/allowlists/function_transition_allowlist"),
187+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
188188
}
189189
)
190190
EOF
@@ -256,7 +256,7 @@ transitioning_rule = rule(
256256
attrs = {
257257
"deps": attr.label_list(cfg = my_transition),
258258
"_allowlist_function_transition": attr.label(
259-
default = "@//tools/allowlists/function_transition_allowlist"),
259+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
260260
}
261261
)
262262

tools/allowlists/config_feature_flag/BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# Package groups for restricting access to config_feature_flag to specific
33
# packages, allowing for careful rollout as it is an experimental feature.
44

5-
package_group(
6-
name = "config_feature_flag",
7-
packages = ["//..."],
8-
)
9-
105
filegroup(
116
name = "srcs",
127
srcs = glob(["**"]),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Description:
2+
# Package groups for restricting access to config_feature_flag to specific
3+
# packages, allowing for careful rollout as it is an experimental feature.
4+
5+
filegroup(
6+
name = "srcs",
7+
srcs = glob(["**"]),
8+
visibility = ["//tools/allowlists:__pkg__"],
9+
)
10+
11+
package_group(
12+
name = "config_feature_flag",
13+
packages = ["public"],
14+
)

tools/allowlists/function_transition_allowlist/BUILD

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Description:
2-
# Package group restricting access to starlark-defined transitions, allowing for careful rollout as it is an experimental feature.
3-
4-
package_group(
5-
name = "function_transition_allowlist",
6-
packages = ["//..."],
7-
)
2+
# Package group restricting access to starlark-defined transitions, allowing
3+
# for careful rollout as it is an experimental feature.
84

95
filegroup(
106
name = "srcs",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Description:
2+
# Package group restricting access to starlark-defined transitions, allowing
3+
# for careful rollout as it is an experimental feature.
4+
5+
filegroup(
6+
name = "srcs",
7+
srcs = glob(["**"]),
8+
visibility = ["//tools/allowlists:__pkg__"],
9+
)
10+
11+
package_group(
12+
name = "function_transition_allowlist",
13+
packages = ["public"],
14+
)

tools/android/BUILD.tools

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,17 @@ config_setting(
523523

524524
package_group(
525525
name = "android_device_allowlist",
526-
packages = ["//..."],
526+
packages = ["public"],
527527
)
528528

529529
package_group(
530530
name = "export_deps_allowlist",
531-
packages = ["//..."],
531+
packages = ["public"],
532532
)
533533

534534
package_group(
535535
name = "allow_android_library_deps_without_srcs_allowlist",
536-
packages = ["//..."],
536+
packages = ["public"],
537537
)
538538

539539
sh_binary(

tools/whitelists/config_feature_flag/BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# Package groups for restricting access to config_feature_flag to specific
33
# packages, allowing for careful rollout as it is an experimental feature.
44

5-
package_group(
6-
name = "config_feature_flag",
7-
includes = ["//tools/allowlists/config_feature_flag"],
8-
)
9-
105
filegroup(
116
name = "srcs",
127
srcs = glob(["**"]),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Description:
2+
# Package groups for restricting access to config_feature_flag to specific
3+
# packages, allowing for careful rollout as it is an experimental feature.
4+
5+
filegroup(
6+
name = "srcs",
7+
srcs = glob(["**"]),
8+
visibility = ["//tools/whitelists:__pkg__"],
9+
)
10+
11+
package_group(
12+
name = "config_feature_flag",
13+
includes = ["//tools/allowlists/config_feature_flag"],
14+
)

tools/whitelists/function_transition_whitelist/BUILD

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Description:
2-
# Package group restricting access to starlark-defined transitions, allowing for careful rollout as it is an experimental feature.
3-
4-
package_group(
5-
name = "function_transition_whitelist",
6-
includes = ["//tools/allowlists/function_transition_allowlist"],
7-
)
2+
# Package group restricting access to starlark-defined transitions, allowing
3+
# for careful rollout as it is an experimental feature.
84

95
filegroup(
106
name = "srcs",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Description:
2+
# Package group restricting access to starlark-defined transitions, allowing
3+
# for careful rollout as it is an experimental feature.
4+
5+
filegroup(
6+
name = "srcs",
7+
srcs = glob(["**"]),
8+
visibility = ["//tools/whitelists:__pkg__"],
9+
)
10+
11+
package_group(
12+
name = "function_transition_whitelist",
13+
includes = ["//tools/allowlists/function_transition_allowlist"],
14+
)

0 commit comments

Comments
 (0)