FileThis 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 Rules page for more information.
File is passed to an
Args object without using a
map_each function, it is converted to a string by taking the value of its
string File.basenameThe base name of this file. This is the name of the file inside the directory.
string File.dirnameThe name of the directory containing this file. It's taken from path and is always relative to the execution directory.
string File.extensionThe file extension of this file.
bool File.is_sourceReturns true if this is a source file, i.e. it is not generated.
Label File.ownerA label of a target that produces this File. May return
string File.pathThe execution path of this file, relative to the workspace's execution directory. It consists of two parts, an optional first part called the root (see also the root module), and the second part which is the
short_path. 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
short_pathfor the path under which the file is mapped if it's in the runfiles of a binary.
root File.rootThe root beneath which this file resides.
string File.short_pathThe path of this file relative to its root. This excludes the aforementioned root, 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.