aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java
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/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java
parent2415cb4ab69ec05d2e7ba15c75a20e2d2da2fc90 (diff)
Migrate the skylark interfaces of Artifact and ArtifactRoot to skylarkbuildapi
RELNOTES: None. PiperOrigin-RevId: 194960076
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FileApi.java103
1 files changed, 103 insertions, 0 deletions
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();
+}