Skip to content

Commit

Permalink
Support multiple source roots.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 494993697
Change-Id: If42ff630db9e64dd3052d15d66deecb921396201
  • Loading branch information
coeuvre authored and copybara-github committed Dec 13, 2022
1 parent dfdbf5d commit de4746d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static FileArtifactValue createFromStat(
stat.isFile(),
stat.getSize(),
FileContentsProxy.create(stat),
/*digest=*/ null,
/* digest= */ null,
xattrProvider);
}

Expand All @@ -272,7 +272,7 @@ private static FileArtifactValue create(
}

public static FileArtifactValue createForVirtualActionInput(byte[] digest, long size) {
return new RegularFileArtifactValue(digest, /*proxy=*/ null, size);
return new RegularFileArtifactValue(digest, /* proxy= */ null, size);
}

public static FileArtifactValue createForUnresolvedSymlink(Path symlink) throws IOException {
Expand Down Expand Up @@ -305,7 +305,8 @@ public static FileArtifactValue createForNormalFile(
*/
public static FileArtifactValue createForNormalFileUsingPath(
Path path, long size, XattrProvider xattrProvider) throws IOException {
return create(path, /*isFile=*/ true, size, /*proxy=*/ null, /*digest=*/ null, xattrProvider);
return create(
path, /* isFile= */ true, size, /* proxy= */ null, /* digest= */ null, xattrProvider);
}

public static FileArtifactValue createForDirectoryWithHash(byte[] digest) {
Expand All @@ -322,7 +323,7 @@ public static FileArtifactValue createForDirectoryWithMtime(long mtime) {
*/
public static FileArtifactValue createProxy(byte[] digest) {
Preconditions.checkNotNull(digest);
return createForNormalFile(digest, /*proxy=*/ null, /*size=*/ 0);
return createForNormalFile(digest, /* proxy= */ null, /* size= */ 0);
}

private static String bytesToString(byte[] bytes) {
Expand Down Expand Up @@ -830,11 +831,17 @@ public boolean wasModifiedSinceDigest(Path path) {
* required to resolve the content.
*/
public static final class SourceFileArtifactValue extends FileArtifactValue {
private final PathFragment path;
private final PathFragment execPath;
private final byte[] digest;
private final long size;

public SourceFileArtifactValue(PathFragment execPath, byte[] digest, long size) {
public SourceFileArtifactValue(
PathFragment path, PathFragment execPath, byte[] digest, long size) {
Preconditions.checkArgument(path.isAbsolute(), "path %s isn't absolute", path);
Preconditions.checkArgument(
path.endsWith(execPath), "path %s doesn't end with execPath %s", path, execPath);
this.path = path;
this.execPath = Preconditions.checkNotNull(execPath);
this.digest = Preconditions.checkNotNull(digest);
this.size = size;
Expand All @@ -847,14 +854,19 @@ public boolean equals(Object o) {
}

SourceFileArtifactValue that = (SourceFileArtifactValue) o;
return Objects.equals(execPath, that.execPath)
return Objects.equals(path, that.path)
&& Objects.equals(execPath, that.execPath)
&& Arrays.equals(digest, that.digest)
&& size == that.size;
}

@Override
public int hashCode() {
return Objects.hash(execPath, Arrays.hashCode(digest), size);
return Objects.hash(path, execPath, Arrays.hashCode(digest), size);
}

public PathFragment getPath() {
return path;
}

public PathFragment getExecPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,33 @@ public void treeOutputsFromLocalFileSystem_works() throws Exception {
assertValidOutputFile("out/foobar.txt", "file-1\nbar\n");
}

@Test
public void multiplePackagePaths_buildsSuccessfully() throws Exception {
write(
"../a/src/BUILD",
"genrule(",
" name = 'foo',",
" srcs = [],",
" outs = ['out/foo.txt'],",
" cmd = 'echo foo > $@',",
")");
write(
"BUILD",
"genrule(",
" name = 'foobar',",
" srcs = ['//src:foo'],",
" outs = ['out/foobar.txt'],",
" cmd = 'cat $(location //src:foo) > $@ && echo bar >> $@',",
")");
addOptions("--package_path=%workspace%:%workspace%/../a");
setDownloadToplevel();

buildTarget("//:foobar");
waitDownloads();

assertValidOutputFile("out/foobar.txt", "foo\nbar\n");
}

@Test
public void incrementalBuild_deleteOutputsInUnwritableParentDirectory() throws Exception {
write(
Expand Down

0 comments on commit de4746d

Please sign in to comment.