Skip to content

Commit

Permalink
fix(builtin): linker fix for when not running in execroot
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Magolan authored and gregmagolan committed Jul 16, 2020
1 parent 4d2000b commit b187d50
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions internal/linker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ function resolveRoot(root, startCwd, isExecroot, runfiles) {
}
const match = startCwd.match(/(\/bazel-out\/|\/bazel-~1\/x64_wi~1\/)/);
if (!match) {
panic(`No 'bazel-out' folder found in path '${startCwd}'!`);
return '';
if (!root) {
return `${startCwd}/node_modules`;
}
return path.resolve(`${startCwd}/../${root}`);
}
const symlinkRoot = startCwd.slice(0, match.index);
process.chdir(symlinkRoot);
Expand Down
16 changes: 14 additions & 2 deletions internal/linker/link_node_modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,21 @@ async function resolveRoot(
// c:/b/ojvxx6nx/execroot/build_~1/bazel-~1/x64_wi~1/bin/internal/npm_in~1/test
const match = startCwd.match(/(\/bazel-out\/|\/bazel-~1\/x64_wi~1\/)/);
if (!match) {
panic(`No 'bazel-out' folder found in path '${startCwd}'!`);
return '';
// No execroot found. This can happen if we are inside a nodejs_image or a nodejs_binary is
// run manually.

if (!root) {
// If there is no root, which will be the case if there are no third-party modules
// dependencies for this target, simply link to node_modules at the cwd.
return `${startCwd}/node_modules`;
}

// If there is a root then attempt to symlink as if we are in runfiles in a sandbox. This will
// be the case for nodejs_image.
return path.resolve(`${startCwd}/../${root}`)
}

// We've found the execroot
const symlinkRoot = startCwd.slice(0, match.index);
process.chdir(symlinkRoot);

Expand Down
6 changes: 4 additions & 2 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ if [[ "$PWD" == *"/bazel-out/"* ]]; then
readonly execroot=${PWD:0:${index}}
export BAZEL_PATCH_GUARDS="${execroot}/node_modules"
else
# We are in execroot, linker node_modules is in the PWD
# We are in execroot or in some other context all together such as a nodejs_image or a manually
# run nodejs_binary. If this is execroot then linker node_modules is in the PWD. If this another
# context then it is safe to assume the node_modules are there and guard that directory if it exists.
export BAZEL_PATCH_GUARDS="${PWD}/node_modules"
fi
fi
if [[ -n "${BAZEL_NODE_MODULES_ROOT:-}" ]]; then
if [[ "${BAZEL_NODE_MODULES_ROOT}" != "${BAZEL_WORKSPACE}/node_modules" ]]; then
# If BAZEL_NODE_MODULES_ROOT is set and it is not , add it to the list of bazel patch guards
Expand Down

0 comments on commit b187d50

Please sign in to comment.