Skip to content

Commit

Permalink
fix(builtin): fix localWorkspacePath logic
Browse files Browse the repository at this point in the history
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 bazel-contrib#1087
  • Loading branch information
alexeagle committed Sep 4, 2019
1 parent df37fca commit 23798de
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions internal/node/node_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand All @@ -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}`);
Expand Down

0 comments on commit 23798de

Please sign in to comment.