Documentation

File

This type represents a file used by the build system. It can be either a source file or a derived file produced by a rule.

The File constructor is private, so you cannot call it directly to create new Files. If you have a Skylark rule that needs to create a new File, you might need to add the label to the attrs (if it's an input) or the outputs (if it's an output). Then you can access the File through the rule's context. You can also use ctx.new_file to create a new file in the rule implementation.

basename

string File.basename

The base file name of this file.

dirname

string File.dirname

The name of the directory containing this file.

extension

string File.extension

The file extension of this file.

is_source

bool File.is_source

Returns true if this is a source file, i.e. it is not generated.

owner

Label File.owner

A label of a target that produces this File. May return None.

path

string File.path

The 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_path for the path under which the file is mapped if it's in the runfiles of a binary.

root

root File.root

The root beneath which this file resides.

short_path

string File.short_path

The 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.