aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar cparsons <cparsons@google.com>2018-05-01 10:50:26 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-01 10:52:13 -0700
commit6363ee06f0d1b44c50928ca65f22a6d67f456abd (patch)
tree7fdcc0240c92e32b4a09a874d97020dacb49bca1 /src
parent2415cb4ab69ec05d2e7ba15c75a20e2d2da2fc90 (diff)
Migrate the skylark interfaces of Artifact and ArtifactRoot to skylarkbuildapi
RELNOTES: None. PiperOrigin-RevId: 194960076
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/Artifact.java72
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java17
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD2
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java103
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileRootApi.java37
6 files changed, 155 insertions, 77 deletions
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 84110fe84f..95714cdc8a 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
@@ -37,11 +37,8 @@ import com.google.devtools.build.lib.skyframe.serialization.SerializationContext
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.EvalUtils.ComparisonException;
import com.google.devtools.build.lib.util.FileType;
@@ -104,26 +101,11 @@ import javax.annotation.Nullable;
* </ul>
*/
@Immutable
-@SkylarkModule(
- name = "File",
- category = SkylarkModuleCategory.BUILTIN,
- doc =
- "This object is created during the analysis phase to represent a file or directory that "
- + "will be read or written during the execution phase. It is not an open file handle, "
- + "and cannot be used to directly read or write file contents. Rather, you use it to "
- + "construct the action graph in a rule implementation function by passing it to "
- + "action-creating functions. See the "
- + "<a href='../rules.$DOC_EXT#files'>Rules page</a> for more information."
- + ""
- + "<p>When a <code>File</code> is passed to an <a href='Args.html'><code>Args</code></a> "
- + "object without using a <code>map_each</code> function, it is converted to a string by "
- + "taking the value of its <code>path</code> field."
-)
@AutoCodec
public class Artifact
implements FileType.HasFileType,
ActionInput,
- SkylarkValue,
+ FileApi,
Comparable<Object>,
CommandLineItem {
@@ -316,9 +298,7 @@ public class Artifact
*
* <p> The directory name is always a relative path to the execution directory.
*/
- @SkylarkCallable(name = "dirname", structField = true,
- doc = "The name of the directory containing this file. It's taken from "
- + "<a href=\"#path\">path</a> and is always relative to the execution directory.")
+ @Override
public final String getDirname() {
PathFragment parent = getExecPath().getParentDirectory();
return (parent == null) ? "/" : parent.getSafePathString();
@@ -327,13 +307,12 @@ public class Artifact
/**
* Returns the base file name of this artifact, similar to basename(1).
*/
- @SkylarkCallable(name = "basename", structField = true,
- doc = "The base name of this file. This is the name of the file inside the directory.")
+ @Override
public final String getFilename() {
return getExecPath().getBaseName();
}
- @SkylarkCallable(name = "extension", structField = true, doc = "The file extension of this file.")
+ @Override
public final String getExtension() {
return getExecPath().getFileExtension();
}
@@ -383,9 +362,7 @@ public class Artifact
return owner;
}
- @SkylarkCallable(name = "owner", structField = true, allowReturnNones = true,
- doc = "A label of a target that produces this File."
- )
+ @Override
public Label getOwnerLabel() {
return owner.getLabel();
}
@@ -395,11 +372,7 @@ public class Artifact
* package-path entries (for source Artifacts), or one of the bin, genfiles or includes dirs (for
* derived Artifacts). It will always be an ancestor of getPath().
*/
- @SkylarkCallable(
- name = "root",
- structField = true,
- doc = "The root beneath which this file resides."
- )
+ @Override
public final ArtifactRoot getRoot() {
return root;
}
@@ -424,11 +397,7 @@ public class Artifact
* Note that this will report all Artifacts in the output tree, including in the include symlink
* tree, as non-source.
*/
- @SkylarkCallable(
- name = "is_source",
- structField = true,
- doc = "Returns true if this is a source file, i.e. it is not generated."
- )
+ @Override
public final boolean isSourceArtifact() {
return root.isSourceRoot();
}
@@ -444,7 +413,7 @@ public class Artifact
* Returns true iff this is a TreeArtifact representing a directory tree containing Artifacts.
*/
// TODO(rduan): Document this Skylark method once TreeArtifact is no longer experimental.
- @SkylarkCallable(name = "is_directory", structField = true, documented = false)
+ @Override
public boolean isTreeArtifact() {
return false;
}
@@ -637,14 +606,7 @@ public class Artifact
return relativePath;
}
- @SkylarkCallable(
- name = "short_path",
- structField = true,
- doc =
- "The path of this file relative to its root. This excludes the aforementioned "
- + "<i>root</i>, i.e. configuration-specific fragments of the path. This is also the "
- + "path under which the file is mapped if it's in the runfiles of a binary."
- )
+ @Override
public final String getRunfilesPathString() {
return getRunfilesPath().getPathString();
}
@@ -653,20 +615,6 @@ public class Artifact
* Returns this.getExecPath().getPathString().
*/
@Override
- @SkylarkCallable(
- name = "path",
- structField = true,
- doc =
- "The execution path of this file, relative to the workspace's execution directory. It "
- + "consists of two parts, an optional first part called the <i>root</i> (see also the "
- + "<a href=\"root.html\">root</a> module), and the second part which is the "
- + "<code>short_path</code>. The root may be empty, which it usually is for "
- + "non-generated files. For generated files it usually contains a "
- + "configuration-specific path fragment that encodes things like the target CPU "
- + "architecture that was used while building said file. Use the "
- + "<code>short_path</code> for the path under which the file is mapped if it's in the "
- + "runfiles of a binary."
- )
public final String getExecPathString() {
return getExecPath().getPathString();
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java
index a98876bfc9..cdcea4d47f 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java
@@ -20,11 +20,8 @@ import com.google.devtools.build.lib.skyframe.serialization.DeserializationConte
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.SerializationContext;
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.FileRootApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
@@ -50,15 +47,8 @@ import java.util.Objects;
* <p>The derived roots must have paths that point inside the exec root, i.e. below the directory
* that is the root of the merged directory tree.
*/
-@SkylarkModule(
- name = "root",
- category = SkylarkModuleCategory.BUILTIN,
- doc =
- "A root for files. The roots are the directories containing files, and they are mapped "
- + "together into a single directory tree to form the execution environment."
-)
@Immutable
-public final class ArtifactRoot implements Comparable<ArtifactRoot>, Serializable, SkylarkValue {
+public final class ArtifactRoot implements Comparable<ArtifactRoot>, Serializable, FileRootApi {
/**
* Do not use except in tests and in {@link
* com.google.devtools.build.lib.skyframe.SkyframeExecutor}.
@@ -119,8 +109,7 @@ public final class ArtifactRoot implements Comparable<ArtifactRoot>, Serializabl
return execPath;
}
- @SkylarkCallable(name = "path", structField = true,
- doc = "Returns the relative path from the exec root to the actual root.")
+ @Override
public String getExecPathString() {
return getExecPath().getPathString();
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/BUILD b/src/main/java/com/google/devtools/build/lib/actions/BUILD
index 71a951558f..a65817caf8 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/actions/BUILD
@@ -38,6 +38,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/profiler",
"//src/main/java/com/google/devtools/build/lib/shell",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
+ "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD
index b441d201b3..4e0da37087 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/BUILD
@@ -6,7 +6,7 @@
# those which contain pure-Skylark concepts, such as the interpretter or
# annotation interfaces).
-package(default_visibility = ["//src/main/java/com/google/devtools/build/lib:__pkg__"])
+package(default_visibility = ["//src:__subpackages__"])
licenses(["notice"]) # Apache 2.0
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java
new file mode 100644
index 0000000000..1c6979267f
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java
@@ -0,0 +1,103 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi;
+
+import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
+
+/**
+ * The interface for files in Skylark.
+ */
+@SkylarkModule(
+ name = "File",
+ category = SkylarkModuleCategory.BUILTIN,
+ doc =
+ "This object is created during the analysis phase to represent a file or directory that "
+ + "will be read or written during the execution phase. It is not an open file handle, "
+ + "and cannot be used to directly read or write file contents. Rather, you use it to "
+ + "construct the action graph in a rule implementation function by passing it to "
+ + "action-creating functions. See the "
+ + "<a href='../rules.$DOC_EXT#files'>Rules page</a> for more information."
+ + ""
+ + "<p>When a <code>File</code> is passed to an <a href='Args.html'><code>Args</code></a> "
+ + "object without using a <code>map_each</code> function, it is converted to a string by "
+ + "taking the value of its <code>path</code> field."
+)
+public interface FileApi extends SkylarkValue {
+
+ @SkylarkCallable(name = "dirname", structField = true,
+ doc = "The name of the directory containing this file. It's taken from "
+ + "<a href=\"#path\">path</a> and is always relative to the execution directory.")
+ public String getDirname();
+
+ @SkylarkCallable(name = "basename", structField = true,
+ doc = "The base name of this file. This is the name of the file inside the directory.")
+ public String getFilename();
+
+ @SkylarkCallable(name = "extension", structField = true, doc = "The file extension of this file.")
+ public String getExtension();
+
+ @SkylarkCallable(name = "owner", structField = true, allowReturnNones = true,
+ doc = "A label of a target that produces this File."
+ )
+ public Label getOwnerLabel();
+
+ @SkylarkCallable(
+ name = "root",
+ structField = true,
+ doc = "The root beneath which this file resides."
+ )
+ public FileRootApi getRoot();
+
+ @SkylarkCallable(
+ name = "is_source",
+ structField = true,
+ doc = "Returns true if this is a source file, i.e. it is not generated."
+ )
+ public boolean isSourceArtifact();
+
+ // TODO(rduan): Document this Skylark method once TreeArtifact is no longer experimental.
+ @SkylarkCallable(name = "is_directory", structField = true, documented = false)
+ public boolean isTreeArtifact();
+
+ @SkylarkCallable(
+ name = "short_path",
+ structField = true,
+ doc =
+ "The path of this file relative to its root. This excludes the aforementioned "
+ + "<i>root</i>, i.e. configuration-specific fragments of the path. This is also the "
+ + "path under which the file is mapped if it's in the runfiles of a binary."
+ )
+ public String getRunfilesPathString();
+
+ @SkylarkCallable(
+ name = "path",
+ structField = true,
+ doc =
+ "The execution path of this file, relative to the workspace's execution directory. It "
+ + "consists of two parts, an optional first part called the <i>root</i> (see also the "
+ + "<a href=\"root.html\">root</a> module), and the second part which is the "
+ + "<code>short_path</code>. The root may be empty, which it usually is for "
+ + "non-generated files. For generated files it usually contains a "
+ + "configuration-specific path fragment that encodes things like the target CPU "
+ + "architecture that was used while building said file. Use the "
+ + "<code>short_path</code> for the path under which the file is mapped if it's in the "
+ + "runfiles of a binary."
+ )
+ public String getExecPathString();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileRootApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileRootApi.java
new file mode 100644
index 0000000000..ee8a15843f
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileRootApi.java
@@ -0,0 +1,37 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi;
+
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
+
+/**
+ * A root for a file. The roots are the directories containing files, and they are mapped
+ * together into a single directory tree to form the execution environment.
+ */
+@SkylarkModule(
+ name = "root",
+ category = SkylarkModuleCategory.BUILTIN,
+ doc =
+ "A root for files. The roots are the directories containing files, and they are mapped "
+ + "together into a single directory tree to form the execution environment."
+)
+public interface FileRootApi extends SkylarkValue {
+ @SkylarkCallable(name = "path", structField = true,
+ doc = "Returns the relative path from the exec root to the actual root.")
+ public String getExecPathString();
+}