Skip to content

Commit de4746d

Browse files
coeuvrecopybara-github
authored andcommitted
Support multiple source roots.
PiperOrigin-RevId: 494993697 Change-Id: If42ff630db9e64dd3052d15d66deecb921396201
1 parent dfdbf5d commit de4746d

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static FileArtifactValue createFromStat(
246246
stat.isFile(),
247247
stat.getSize(),
248248
FileContentsProxy.create(stat),
249-
/*digest=*/ null,
249+
/* digest= */ null,
250250
xattrProvider);
251251
}
252252

@@ -272,7 +272,7 @@ private static FileArtifactValue create(
272272
}
273273

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

278278
public static FileArtifactValue createForUnresolvedSymlink(Path symlink) throws IOException {
@@ -305,7 +305,8 @@ public static FileArtifactValue createForNormalFile(
305305
*/
306306
public static FileArtifactValue createForNormalFileUsingPath(
307307
Path path, long size, XattrProvider xattrProvider) throws IOException {
308-
return create(path, /*isFile=*/ true, size, /*proxy=*/ null, /*digest=*/ null, xattrProvider);
308+
return create(
309+
path, /* isFile= */ true, size, /* proxy= */ null, /* digest= */ null, xattrProvider);
309310
}
310311

311312
public static FileArtifactValue createForDirectoryWithHash(byte[] digest) {
@@ -322,7 +323,7 @@ public static FileArtifactValue createForDirectoryWithMtime(long mtime) {
322323
*/
323324
public static FileArtifactValue createProxy(byte[] digest) {
324325
Preconditions.checkNotNull(digest);
325-
return createForNormalFile(digest, /*proxy=*/ null, /*size=*/ 0);
326+
return createForNormalFile(digest, /* proxy= */ null, /* size= */ 0);
326327
}
327328

328329
private static String bytesToString(byte[] bytes) {
@@ -830,11 +831,17 @@ public boolean wasModifiedSinceDigest(Path path) {
830831
* required to resolve the content.
831832
*/
832833
public static final class SourceFileArtifactValue extends FileArtifactValue {
834+
private final PathFragment path;
833835
private final PathFragment execPath;
834836
private final byte[] digest;
835837
private final long size;
836838

837-
public SourceFileArtifactValue(PathFragment execPath, byte[] digest, long size) {
839+
public SourceFileArtifactValue(
840+
PathFragment path, PathFragment execPath, byte[] digest, long size) {
841+
Preconditions.checkArgument(path.isAbsolute(), "path %s isn't absolute", path);
842+
Preconditions.checkArgument(
843+
path.endsWith(execPath), "path %s doesn't end with execPath %s", path, execPath);
844+
this.path = path;
838845
this.execPath = Preconditions.checkNotNull(execPath);
839846
this.digest = Preconditions.checkNotNull(digest);
840847
this.size = size;
@@ -847,14 +854,19 @@ public boolean equals(Object o) {
847854
}
848855

849856
SourceFileArtifactValue that = (SourceFileArtifactValue) o;
850-
return Objects.equals(execPath, that.execPath)
857+
return Objects.equals(path, that.path)
858+
&& Objects.equals(execPath, that.execPath)
851859
&& Arrays.equals(digest, that.digest)
852860
&& size == that.size;
853861
}
854862

855863
@Override
856864
public int hashCode() {
857-
return Objects.hash(execPath, Arrays.hashCode(digest), size);
865+
return Objects.hash(path, execPath, Arrays.hashCode(digest), size);
866+
}
867+
868+
public PathFragment getPath() {
869+
return path;
858870
}
859871

860872
public PathFragment getExecPath() {

src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTestBase.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,33 @@ public void treeOutputsFromLocalFileSystem_works() throws Exception {
579579
assertValidOutputFile("out/foobar.txt", "file-1\nbar\n");
580580
}
581581

582+
@Test
583+
public void multiplePackagePaths_buildsSuccessfully() throws Exception {
584+
write(
585+
"../a/src/BUILD",
586+
"genrule(",
587+
" name = 'foo',",
588+
" srcs = [],",
589+
" outs = ['out/foo.txt'],",
590+
" cmd = 'echo foo > $@',",
591+
")");
592+
write(
593+
"BUILD",
594+
"genrule(",
595+
" name = 'foobar',",
596+
" srcs = ['//src:foo'],",
597+
" outs = ['out/foobar.txt'],",
598+
" cmd = 'cat $(location //src:foo) > $@ && echo bar >> $@',",
599+
")");
600+
addOptions("--package_path=%workspace%:%workspace%/../a");
601+
setDownloadToplevel();
602+
603+
buildTarget("//:foobar");
604+
waitDownloads();
605+
606+
assertValidOutputFile("out/foobar.txt", "foo\nbar\n");
607+
}
608+
582609
@Test
583610
public void incrementalBuild_deleteOutputsInUnwritableParentDirectory() throws Exception {
584611
write(

0 commit comments

Comments
 (0)