From 23798dec0f139bdcc095b0cf5bbbf2842858e1b0 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 4 Sep 2019 10:05:32 -0700 Subject: [PATCH] fix(builtin): fix localWorkspacePath logic If the manifest has an entry in the output_base but not in the binDir or genDir, we get a wrong path for later resolutions Fixes #1087 --- internal/node/node_loader.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/internal/node/node_loader.js b/internal/node/node_loader.js index 7a02c7cdd3..da3e91e9e7 100644 --- a/internal/node/node_loader.js +++ b/internal/node/node_loader.js @@ -108,6 +108,17 @@ function loadRunfilesManifest(manifestPath) { const reverseRunfilesManifest = Object.create(null); const input = fs.readFileSync(manifestPath, {encoding: 'utf-8'}); + // Determine bin and gen root to convert absolute paths into runfile paths. + const binRootIdx = manifestPath.indexOf(BIN_DIR); + if (binRootIdx < 0) { + throw new Error(`internal error, please file a bug: runfiles manifest is not under ${BIN_DIR}`); + } + const execRoot = manifestPath.slice(0, binRootIdx - 1); + const outputBase = + manifestPath.slice(0, binRootIdx - USER_WORKSPACE_NAME.length - '/execroot/'.length); + const binRoot = `${execRoot}/${BIN_DIR}/`; + const genRoot = `${execRoot}/${GEN_DIR}/`; + // Absolute path that refers to the local workspace path. We need to determine the absolute // path to the local workspace because it allows us to support absolute path resolving // for runfiles. @@ -122,9 +133,9 @@ function loadRunfilesManifest(manifestPath) { // We don't need to try determining the local workspace path for the current runfile // mapping in case we already determined the local workspace path, the current // runfile refers to a different workspace, or the current runfile resolves to a file - // in the bazel-out directory (bin/genfiles directory). + // in the output_base directory. if (localWorkspacePath || !runfilesPath.startsWith(USER_WORKSPACE_NAME) || - realPath.includes(BIN_DIR) || realPath.includes(GEN_DIR)) { + realPath.startsWith(outputBase)) { continue; } @@ -140,15 +151,7 @@ function loadRunfilesManifest(manifestPath) { localWorkspacePath = realPath.slice(0, -relativeWorkspacePath.length); } - // Determine bin and gen root to convert absolute paths into runfile paths. - const binRootIdx = manifestPath.indexOf(BIN_DIR); - let binRoot, genRoot; - if (binRootIdx !== -1) { - const execRoot = manifestPath.slice(0, binRootIdx); - binRoot = `${execRoot}${BIN_DIR}/`; - genRoot = `${execRoot}${GEN_DIR}/`; - } - + log_verbose(`using outputBase ${outputBase}`); log_verbose(`using binRoot ${binRoot}`); log_verbose(`using genRoot ${genRoot}`); log_verbose(`using localWorkspacePath ${localWorkspacePath}`);