From 8091b2b42bfd9113513aa68294ddc6160cb6500f Mon Sep 17 00:00:00 2001 From: Dmitry Lomov Date: Wed, 2 Mar 2016 01:24:56 +0000 Subject: Expose artifact owner label to Skylark. -- MOS_MIGRATED_REVID=116076100 --- src/main/java/com/google/devtools/build/lib/actions/Artifact.java | 7 +++++++ .../java/com/google/devtools/build/lib/actions/ArtifactTest.java | 6 ++++++ 2 files changed, 13 insertions(+) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java index 5c69ce5cfd..4e8989f9ba 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java @@ -295,6 +295,13 @@ public class Artifact return owner; } + @SkylarkCallable(name = "owner", structField = true, allowReturnNones = true, + doc = "A label of a target that produces this File. Can be None." + ) + public Label getOwnerLabel() { + return owner.getLabel(); + } + /** * Returns the root beneath which this Artifact resides, if any. This may be one of the * package-path entries (for source Artifacts), or one of the bin, genfiles or includes dirs diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java index c0c992f2b5..37f57c87df 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java @@ -78,6 +78,12 @@ public class ArtifactTest { new Artifact(bPath, rootDir))); } + @Test + public void testEmptyLabelIsNone() throws Exception { + Artifact artifact = new Artifact(new PathFragment("src/a"), rootDir); + assertThat(artifact.getOwnerLabel()).isNull(); + } + @Test public void testComparison() throws Exception { PathFragment aPath = new PathFragment("src/a"); -- cgit v1.2.3