Skip to content

Commit

Permalink
Enable incompatible_disallow_load_labels_to_cross_package_boundaries …
Browse files Browse the repository at this point in the history
…by default

Fixes #6408

Tested: https://buildkite.com/bazel/bazelisk-plus-incompatible-flags/builds/52

RELNOTES: `--incompatible_disallow_load_labels_to_cross_package_boundaries` is enabled by default
PiperOrigin-RevId: 240347889
  • Loading branch information
laurentlb authored and copybara-github committed Mar 26, 2019
1 parent f7e60d2 commit 3f791e7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl

@Option(
name = "incompatible_disallow_load_labels_to_cross_package_boundaries",
defaultValue = "false",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ public String apply(SkyKey input) {
+ "' was defined too late in your WORKSPACE file."));
return true;
} else if (Iterables.any(cycle, IS_PACKAGE_LOOKUP)) {
eventHandler.handle(
Event.error(null, "cycle detected loading "
+ String.join(
" ", lastPathElement.functionName().toString().toLowerCase().split("_"))
+ " '" + lastPathElement.argument().toString() + "'"));
PackageIdentifier pkg =
(PackageIdentifier)
Iterables.getLast(Iterables.filter(cycle, IS_PACKAGE_LOOKUP)).argument();
eventHandler.handle(Event.error(null, "cannot load package '" + pkg + "'"));
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static Builder builderWithDefaults() {
.incompatibleDisallowFileType(true)
.incompatibleDisallowLegacyJavaProvider(false)
.incompatibleDisallowLegacyJavaInfo(false)
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(false)
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(true)
.incompatibleDisallowNativeInBuildFile(false)
.incompatibleDisallowOldStyleArgsAdd(true)
.incompatibleDisallowStructProviderSyntax(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public void testSkylarkImportLookupNoBuildFile() throws Exception {
ErrorInfo errorInfo = result.getError(skylarkImportLookupKey);
String errorMessage = errorInfo.getException().getMessage();
assertThat(errorMessage)
.isEqualTo(
"Unable to load package for '//pkg:ext.bzl': BUILD file not found on package path");
.contains(
"Every .bzl file must have a corresponding package, but '//pkg:ext.bzl' does not");
}

@Test
Expand All @@ -211,9 +211,7 @@ public void testSkylarkImportLookupNoBuildFileForLoad() throws Exception {
assertThat(result.hasError()).isTrue();
ErrorInfo errorInfo = result.getError(skylarkImportLookupKey);
String errorMessage = errorInfo.getException().getMessage();
assertThat(errorMessage)
.isEqualTo(
"Unable to load package for '//pkg:ext.bzl': BUILD file not found on package path");
assertThat(errorMessage).contains("Every .bzl file must have a corresponding package");
}

@Test
Expand Down Expand Up @@ -276,6 +274,8 @@ public void testLoadUsingLabelThatDoesntCrossBoundaryOfPackage() throws Exceptio

@Test
public void testLoadUsingLabelThatCrossesBoundaryOfPackage_Allow_OfSamePkg() throws Exception {
setSkylarkSemanticsOptions("--noincompatible_disallow_load_labels_to_cross_package_boundaries");

scratch.file("a/BUILD");
scratch.file("a/a.bzl", "load('//a:b/b.bzl', 'b')");
scratch.file("a/b/BUILD", "");
Expand Down Expand Up @@ -314,6 +314,7 @@ public void testLoadUsingLabelThatCrossesBoundaryOfPackage_Disallow_OfSamePkg()
@Test
public void testLoadUsingLabelThatCrossesBoundaryOfPackage_Allow_OfDifferentPkgUnder()
throws Exception {
setSkylarkSemanticsOptions("--noincompatible_disallow_load_labels_to_cross_package_boundaries");
scratch.file("a/BUILD");
scratch.file("a/a.bzl", "load('//a/b:c/c.bzl', 'c')");
scratch.file("a/b/BUILD", "");
Expand Down Expand Up @@ -355,6 +356,7 @@ public void testLoadUsingLabelThatCrossesBoundaryOfPackage_Disallow_OfDifferentP
@Test
public void testLoadUsingLabelThatCrossesBoundaryOfPackage_Allow_OfDifferentPkgAbove()
throws Exception {
setSkylarkSemanticsOptions("--noincompatible_disallow_load_labels_to_cross_package_boundaries");
scratch.file("a/b/BUILD");
scratch.file("a/b/b.bzl", "load('//a/c:c/c.bzl', 'c')");
scratch.file("a/BUILD");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ public void topLevelAspectDoesNotExistNoBuildFile() throws Exception {
} catch (ViewCreationFailedException e) {
// expect to fail.
}
assertContainsEvent("Unable to load package for '//foo:aspect.bzl'");
assertContainsEvent("Every .bzl file must have a corresponding package");
}

@Test
Expand Down
9 changes: 3 additions & 6 deletions src/test/shell/bazel/skylark_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ EOF
[ $exitCode != 0 ] || fail "building @foo//:data.txt succeed while expected failure"

expect_not_log "PACKAGE"
expect_log "Failed to load Starlark extension '@foo//:ext.bzl'"
expect_log "repository 'foo' was defined too late in your WORKSPACE file"
expect_log "cannot load package '@foo//'"
}

function test_load_nonexistent_with_subworkspace() {
Expand All @@ -312,17 +311,15 @@ EOF
[ $exitCode != 0 ] || fail "building //... succeed while expected failure"

expect_not_log "PACKAGE"
expect_log "Failed to load Starlark extension '@does_not_exist//:random.bzl'"
expect_log "repository 'does_not_exist' was defined too late in your WORKSPACE file"
expect_log "cannot load package '@does_not_exist//'"

# Retest with query //...
bazel clean --expunge
bazel query //... >& $TEST_log || exitCode=$?
[ $exitCode != 0 ] || fail "querying //... succeed while expected failure"

expect_not_log "PACKAGE"
expect_log "Failed to load Starlark extension '@does_not_exist//:random.bzl'"
expect_log "repository 'does_not_exist' was defined too late in your WORKSPACE file"
expect_log "cannot load package '@does_not_exist//'"
}

function test_skylark_local_repository() {
Expand Down
8 changes: 6 additions & 2 deletions src/test/shell/integration/loading_phase_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,19 @@ function test_incompatible_disallow_load_labels_to_cross_package_boundaries() {
touch "$pkg"/foo/a/b/BUILD
echo "b = 42" > "$pkg"/foo/a/b/b.bzl

bazel query "$pkg/foo:BUILD" >& "$TEST_log" || fail "Expected success"
bazel query \
--incompatible_disallow_load_labels_to_cross_package_boundaries=false \
"$pkg/foo:BUILD" >& "$TEST_log" || fail "Expected success"
expect_log "//$pkg/foo:BUILD"

bazel query \
--incompatible_disallow_load_labels_to_cross_package_boundaries=true \
"$pkg/foo:BUILD" >& "$TEST_log" && fail "Expected failure"
expect_log "Label '//$pkg/foo/a:b/b.bzl' crosses boundary of subpackage '$pkg/foo/a/b'"

bazel query "$pkg/foo:BUILD" >& "$TEST_log" || fail "Expected success"
bazel query \
--incompatible_disallow_load_labels_to_cross_package_boundaries=false \
"$pkg/foo:BUILD" >& "$TEST_log" || fail "Expected success"
expect_log "//$pkg/foo:BUILD"
}

Expand Down

0 comments on commit 3f791e7

Please sign in to comment.