Skip to content

Commit

Permalink
Let runfiles env vars take priority
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Dec 30, 2021
1 parent 32dd168 commit 5e4298e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions runfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ func New(opts ...Option) (*Runfiles, error) {
}
// See section “Runfiles discovery” in
// https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub.
// We deviate from the doc (as of 2021-12-30) in one point to work around
// https://github.com/bazelbuild/bazel/issues/14500:
// If runfiles environment variables are set, they take priority over the
// runfiles dirs and manifests that potentially exist next to the binary.
// This is necessary since the Bazel cache can contain outdated runfiles
// trees next to non-top-level binaries.
if o.manifest != "" {
return o.manifest.new()
}
if o.directory != "" {
return o.directory.new(), nil
}
manifest := ManifestFile(o.program + ".runfiles_manifest")
if stat, err := os.Stat(string(manifest)); err == nil && stat.Mode().IsRegular() {
return manifest.new()
Expand All @@ -97,12 +109,6 @@ func New(opts ...Option) (*Runfiles, error) {
if stat, err := os.Stat(string(dir)); err == nil && stat.IsDir() {
return dir.new(), nil
}
if o.manifest != "" {
return o.manifest.new()
}
if o.directory != "" {
return o.directory.new(), nil
}
return nil, errors.New("runfiles: no runfiles found")
}

Expand Down

0 comments on commit 5e4298e

Please sign in to comment.