ErrEmpty indicates that a runfile isn’t present in the filesystem, but should be created as an empty file if necessary.
var ErrEmpty = errors.New("empty runfile")
func CallerRepository() string
CallerRepository returns the canonical name of the Bazel repository that contains the source file of the caller of the function that itself calls CallerRepository.
func CurrentRepository() string
CurrentRepository returns the canonical name of the Bazel repository that contains the source file of the caller of CurrentRepository.
func Env() ([]string, error)
Env returns additional environmental variables to pass to subprocesses. Each element is of the form “key=value”. Pass these variables to Bazel-built binaries so they can find their runfiles as well. See the Runfiles example for an illustration of this.
The return value is a newly-allocated slice; you can modify it at will.
func Rlocation(path string) (string, error)
Rlocation returns the absolute path name of a runfile. The runfile name must be a relative path, using the slash (not backslash) as directory separator. If the runfiles manifest maps s to an empty name (indicating an empty runfile not present in the filesystem), Rlocation returns an error that wraps ErrEmpty.
func RlocationFrom(path string, sourceRepo string) (string, error)
Directory specifies the location of the runfiles directory. You can pass this as an option to New. If unset or empty, use the value of the environmental variable RUNFILES_DIR.
type Directory string
Error represents a failure to look up a runfile.
type Error struct { // Runfile name that caused the failure. Name string // Underlying error. Err error }
func (e Error) Error() string
Error implements error.Error.
func (e Error) Unwrap() error
Unwrap returns the underlying error, for errors.Unwrap.
ManifestFile specifies the location of the runfile manifest file. You can pass this as an option to New. If unset or empty, use the value of the environmental variable RUNFILES_MANIFEST_FILE.
type ManifestFile string
Option is an option for the New function to override runfiles discovery.
type Option interface {
// contains filtered or unexported methods
}
ProgramName is an Option that sets the program name. If not set, New uses os.Args[0].
type ProgramName string
Runfiles allows access to Bazel runfiles. Use New to create Runfiles objects; the zero Runfiles object always returns errors. See https://docs.bazel.build/skylark/rules.html#runfiles for some information on Bazel runfiles.
type Runfiles struct {
// contains filtered or unexported fields
}
func New(opts ...Option) (*Runfiles, error)
New creates a given Runfiles object. By default, it uses os.Args and the RUNFILES_MANIFEST_FILE and RUNFILES_DIR environmental variables to find the runfiles location. This can be overwritten by passing some options.
See section “Runfiles discovery” in https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub.
func (r *Runfiles) Env() []string
Env returns additional environmental variables to pass to subprocesses. Each element is of the form “key=value”. Pass these variables to Bazel-built binaries so they can find their runfiles as well. See the Runfiles example for an illustration of this.
The return value is a newly-allocated slice; you can modify it at will. If r is the zero Runfiles object, the return value is nil.
func (r *Runfiles) Open(name string) (fs.File, error)
Open implements fs.FS.Open.
func (r *Runfiles) ReadFile(name string) ([]byte, error)
ReadFile implements fs.ReadFileFS.ReadFile.
func (r *Runfiles) Rlocation(path string) (string, error)
Rlocation returns the (relative or absolute) path name of a runfile. The runfile name must be a runfile-root relative path, using the slash (not backslash) as directory separator. It is typically of the form "repo/path/to/pkg/file".
If r is the zero Runfiles object, Rlocation always returns an error. If the runfiles manifest maps s to an empty name (indicating an empty runfile not present in the filesystem), Rlocation returns an error that wraps ErrEmpty.
See section “Library interface” in https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub.
func (r *Runfiles) Stat(name string) (fs.FileInfo, error)
Stat implements fs.StatFS.Stat.
func (r *Runfiles) WithSourceRepo(sourceRepo string) *Runfiles
WithSourceRepo returns a Runfiles instance identical to the current one, except that it uses the given repository's repository mapping when resolving runfiles paths.
SourceRepo is an Option that sets the canonical name of the repository whose repository mapping should be used to resolve runfiles paths. If not set, New uses the repository containing the source file from which New is called. Use CurrentRepository to get the name of the current repository.
type SourceRepo string