Skip to content

Commit

Permalink
skyfocus: when using PROJECT.scl file, don't attempt to infer using t…
Browse files Browse the repository at this point in the history
…he top level packages.

This makes the working set derivation less confusing by not keeping files that
aren't specified in the PROJECT.scl file.

PiperOrigin-RevId: 655974491
Change-Id: I89c73e77bdc8e07be77570cfb8c18d5aed8ad9f4
  • Loading branch information
jin authored and copybara-github committed Jul 25, 2024
1 parent adb1b1e commit d915b98
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,24 @@ public static Optional<SkyfocusState> prepareWorkingSet(
return;
}

// Check if the file belongs to a project directory (defined in PROJECT.scl)
//
// If this end up being costly, we could represent projectDirectories as a trie
// and iterate with PathFragment#segments.
for (PathFragment projectDirectory : projectDirectories) {
if (fileStateKey
.argument()
.getRootRelativePath()
.startsWith(projectDirectory)) {
if (!projectDirectories.isEmpty()) {
// Check if the file belongs to a project directory (defined in PROJECT.scl)
//
// If this ends up being costly, we could represent projectDirectories as a
// trie and iterate with PathFragment#segments.
for (PathFragment projectDirectory : projectDirectories) {
PathFragment pathFragment = fileStateKey.argument().getRootRelativePath();
if (!pathFragment.startsWith(projectDirectory)) {
continue;
}
newWorkingSet.add(fileStateKey.argument());
return;
}
return;
}

// Check if the file belongs to the package of a top level target being built.
// If project directories are not defined, check if the file belongs to the
// package of a top level target being built.
PathFragment currPath = fileStateKey.argument().getRootRelativePath();
while (currPath != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,42 @@ public void workingSet_canBeAutomaticallyDerivedUsingProjectFile() throws Except
"somewhere/else/file.txt");
}

@Test
public void workingSet_ignoresTopLevelPackageDirectoriesWhenUsingProjectFile() throws Exception {
addOptions("--experimental_enable_scl_dialect");

write("hello/x.txt", "x");
write(
"hello/BUILD",
"""
genrule(
name = "target",
srcs = ["x.txt", "//somewhere/else:files"],
outs = ["out"],
cmd = "cat $(SRCS) > $@",
)
""");

// Files under //somewhere/else will be included because of this PROJECT.scl file.
write(
"hello/PROJECT.scl",
"""
owned_code_paths = ["somewhere/else"]
""");

write("somewhere/else/file.txt", "some content");
write(
"somewhere/else/BUILD",
"""
filegroup(name = "files", srcs = ["file.txt"])
""");

buildTarget("//hello:target");
assertContainsEvent("automatically deriving working set");
assertThat(getSkyframeExecutor().getSkyfocusState().workingSetStrings())
.containsExactly("somewhere/else", "somewhere/else/BUILD", "somewhere/else/file.txt");
}

@Test
public void workingSet_skyfocusDoesNotRunIfDerivedWorkingSetIsUnchanged() throws Exception {
write("hello/x.txt", "x");
Expand Down

0 comments on commit d915b98

Please sign in to comment.