1 package bazel 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/bazelbuild/rules_go/go/runfiles" 8 ) 9 10 // Rlocation simplifies the process for retrieving runfiles at runtime via 11 // `bazel run` or in a container runtime. 12 func Rlocation(path string) (string, error) { 13 if ws := os.Getenv(BuildWorkspaceDir); ws != "" { 14 return runfiles.Rlocation(filepath.Join(ws, path)) 15 } 16 17 if ws := os.Getenv(TestWorkspace); ws != "" { 18 return runfiles.Rlocation(filepath.Join(ws, path)) 19 } 20 21 return runfiles.Rlocation(filepath.Join(RootRepoName, path)) 22 } 23