* Resolve a path that came from a Bazel $(location …) expansion. * * When a js_binary runs inside a js_run_binary action Bazel sets BAZEL_BINDIR * and the js_binary wrapper calls process.chdir(BAZEL_BINDIR) before handing * control to the script. $(location) values are relative to the *execroot*
(p)
| 91 | * Outside Bazel (BAZEL_BINDIR unset) paths are resolved normally. |
| 92 | */ |
| 93 | function resolveInputPath(p) { |
| 94 | if (!p) return null |
| 95 | if (!process.env.BAZEL_BINDIR) return resolve(p) |
| 96 | // Normalize both strings to forward slashes before prefix-stripping so that |
| 97 | // mixed separators on Windows (BAZEL_BINDIR uses '\', $(location) uses '/') |
| 98 | // do not cause the startsWith check to silently fail. |
| 99 | const normalizedP = p.replaceAll('\\', '/') |
| 100 | const normalizedBindir = process.env.BAZEL_BINDIR.replaceAll('\\', '/') |
| 101 | const prefix = normalizedBindir + '/' |
| 102 | return resolve(normalizedP.startsWith(prefix) ? normalizedP.slice(prefix.length) : normalizedP) |
| 103 | } |
| 104 | |
| 105 | // ============================================================ |
| 106 | // Main |