Skip to content

Commit b8ef3f3

Browse files
fmeumcopybara-github
authored andcommitted
Don't crash Bazel when a source directory crosses package boundaries
Also add the target for the test that was missed in the merge of ad381cb. Work towards #25834 Closes #25863. PiperOrigin-RevId: 758308509 Change-Id: Iafb5854c8986eb3f3b34d96e4f94990f6914f47a
1 parent 9c8141a commit b8ef3f3

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,12 @@ private SkyValue createSourceValue(Artifact artifact, Environment env)
334334
case FILE_OPERATION_FAILURE:
335335
case SYMLINK_CYCLE_OR_INFINITE_EXPANSION:
336336
case CANNOT_TRAVERSE_SOURCE_DIRECTORY:
337+
case CANNOT_CROSS_PACKAGE_BOUNDARY:
337338
throw new ArtifactFunctionException(
338339
SourceArtifactException.create(artifact, e), Transience.PERSISTENT);
339340
case INCONSISTENT_FILESYSTEM:
340341
throw new ArtifactFunctionException(
341342
SourceArtifactException.create(artifact, e), Transience.TRANSIENT);
342-
case CANNOT_CROSS_PACKAGE_BOUNDARY:
343-
throw new IllegalStateException(
344-
String.format(
345-
"Cannot cross package boundary: %s %s %s", artifact, fileValue, request),
346-
e);
347343
case GENERATED_PATH_CONFLICT:
348344
throw new IllegalStateException(
349345
String.format(

src/test/java/com/google/devtools/build/lib/skyframe/BUILD

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,24 @@ java_test(
19041904
],
19051905
)
19061906

1907+
java_test(
1908+
name = "SourceDirectoryIntegrationTest",
1909+
timeout = "short",
1910+
srcs = ["SourceDirectoryIntegrationTest.java"],
1911+
jvm_flags = [
1912+
"-DBAZEL_TRACK_SOURCE_DIRECTORIES=1",
1913+
],
1914+
deps = [
1915+
"//src/main/java/com/google/devtools/build/lib/actions",
1916+
"//src/main/java/com/google/devtools/build/lib/events",
1917+
"//src/main/java/com/google/devtools/build/lib/vfs",
1918+
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
1919+
"//src/test/java/com/google/devtools/build/lib/buildtool/util",
1920+
"//third_party:guava",
1921+
"//third_party:junit4",
1922+
],
1923+
)
1924+
19071925
java_test(
19081926
name = "FileArtifactValueTest",
19091927
timeout = "short",

src/test/java/com/google/devtools/build/lib/skyframe/SourceDirectoryIntegrationTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.google.common.collect.ImmutableSet;
2323
import com.google.devtools.build.lib.actions.BuildFailedException;
24-
import com.google.devtools.build.lib.bugreport.BugReport;
2524
import com.google.devtools.build.lib.buildtool.util.BuildIntegrationTestCase;
2625
import com.google.devtools.build.lib.events.EventKind;
2726
import com.google.devtools.build.lib.vfs.Path;
@@ -228,9 +227,7 @@ public void danglingSymlinkModified_invalidatesAction() throws Exception {
228227
@Test
229228
public void crossingPackageBoundary_fails() throws Exception {
230229
createEmptyFile(sourceDir.getRelative("subdir/BUILD"));
231-
// TODO(#25834): This should not crash Bazel.
232-
assertThrows(IllegalStateException.class, () -> buildTarget("//foo"));
233-
BugReport.getAndResetLastCrashingThrowableIfInTest();
230+
assertThrows(BuildFailedException.class, () -> buildTarget("//foo"));
234231
assertContainsEvent(
235232
"Directory artifact foo/dir crosses package boundary into package rooted at"
236233
+ " foo/dir/subdir");

0 commit comments

Comments
 (0)