aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-15 11:22:31 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-15 11:42:19 +0000
commit7751d4376c888f34084a9ebb494fa3bec7b3428d (patch)
treefb5c65453c90050db8de1c1286cb5c856120e08d /src/main/java/com/google
parente7bc9dd46720e2f18aa09b23fad433c78152bdaa (diff)
Add a method for getting the root of a rule workspace to the Label method
This method is exposed to Skylark and will enable correct handling of protobuf skylark files. See #784 -- MOS_MIGRATED_REVID=112235357
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/cmdline/Label.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
index 8fe14e780c..97955dcd84 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
@@ -263,6 +263,20 @@ public final class Label implements Comparable<Label>, Serializable, SkylarkPrin
public String getPackageName() {
return packageIdentifier.getPackageFragment().getPathString();
}
+
+ /**
+ * Returns the execution root for the workspace, relative to the execroot (e.g., for label
+ * {@code @repo//pkg:b}, it will returns {@code external/repo/pkg} and for label {@code //pkg:a},
+ * it will returns an empty string.
+ */
+ @SkylarkCallable(name = "workspace_root", structField = true,
+ doc = "Returns the execution root for the workspace of this label, relative to the execroot. "
+ + "For instance:<br>"
+ + "<pre class=language-python>Label(\"@repo//pkg/foo:abc\").workspace_root =="
+ + " \"external/repo\"</pre>")
+ public String getWorkspaceRoot() {
+ return packageIdentifier.getRepository().getPathFragment().toString();
+ }
/**
* Returns the path fragment of the package in which this rule was declared (e.g. {@code