aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jon Brandvein <brandjon@google.com>2016-12-28 17:04:37 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-12-28 18:35:13 +0000
commit8d10034638509ae9915a652a02c1051f4f2aedae (patch)
tree74f1913f0718fd88f65c45d7032956066a817ecd /src
parent969d1071441979d980f2995bef1287b58cf57945 (diff)
Expose to Skylark a merge() method for runfiles objects
This is a quick way to make it possible for Skylark rules to aggregate and pass on symlinks from their dependencies. -- PiperOrigin-RevId: 143111353 MOS_MIGRATED_REVID=143111353
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java28
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java19
2 files changed, 46 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index 80d67573b2..25fc4ca865 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -784,7 +784,18 @@ public final class Runfiles {
* created.
*/
public Builder(String workspace, boolean legacyExternalRunfiles) {
- this.suffix = new PathFragment(workspace);
+ this(new PathFragment(workspace), legacyExternalRunfiles);
+ }
+
+ /**
+ * Creates a builder with the given suffix.
+ * @param suffix is the PathFragment wrapping the string specified in workspace() in the
+ * WORKSPACE file.
+ * @param legacyExternalRunfiles if the wsname/external/repo symlinks should also be
+ * created.
+ */
+ private Builder(PathFragment suffix, boolean legacyExternalRunfiles) {
+ this.suffix = suffix;
this.legacyExternalRunfiles = legacyExternalRunfiles;
}
@@ -1106,4 +1117,19 @@ public final class Runfiles {
}
}
}
+
+ /**
+ * Provides a Skylark-visible way to merge two Runfiles objects.
+ */
+ @SkylarkCallable(
+ name = "merge",
+ doc = "Returns a new runfiles object that includes all the contents of this one and the "
+ + "argument."
+ )
+ public Runfiles merge(Runfiles other) {
+ Runfiles.Builder builder = new Runfiles.Builder(suffix, false);
+ builder.merge(this);
+ builder.merge(other);
+ return builder.build();
+ }
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java
index f8bacacf9a..f6d1509bb1 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java
@@ -386,4 +386,23 @@ public class RunfilesTest extends FoundationTestCase {
Maps.immutableEntry(new PathFragment("repo/b"), artifactExternalB));
checkConflictWarning();
}
+
+ @Test
+ public void testMergeWithSymlinks() {
+ Root root = Root.asSourceRoot(scratch.resolve("/workspace"));
+ Artifact artifactA = new Artifact(new PathFragment("a/target"), root);
+ Artifact artifactB = new Artifact(new PathFragment("b/target"), root);
+ PathFragment sympathA = new PathFragment("a/symlink");
+ PathFragment sympathB = new PathFragment("b/symlink");
+ Runfiles runfilesA = new Runfiles.Builder("TESTING")
+ .addSymlink(sympathA, artifactA)
+ .build();
+ Runfiles runfilesB = new Runfiles.Builder("TESTING")
+ .addSymlink(sympathB, artifactB)
+ .build();
+
+ Runfiles runfilesC = runfilesA.merge(runfilesB);
+ assertThat(runfilesC.getSymlinksAsMap(null).get(sympathA)).isEqualTo(artifactA);
+ assertThat(runfilesC.getSymlinksAsMap(null).get(sympathB)).isEqualTo(artifactB);
+ }
}