Skip to content

Commit

Permalink
fix(builtin): look in the execroot for nodejs_binary source entry_points
Browse files Browse the repository at this point in the history
In a6e29c2 we added support for generated entry_point by adding a secondary lookup.
In 863c7de we reversed the order of the lookups to make rollup work in a certain use case.
Neither of these was principled, because we know ahead of time whether the entry_point is generated. We can use a single lookup.

This also makes sure that programs run in the location where the linker will put them (note that the logic in question runs before the linker has created the node_modules directory in the execroot.)
This is why bazel-contrib#1787 observes that some node programs were broken - we were running the entry point as
bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh.runfiles/npm/node_modules/@graphql-codegen/cli/bin.js
when it should have been
node_modules/@graphql-codegen/cli/bin.js

Fixes bazel-contrib#1787
  • Loading branch information
alexeagle committed Apr 10, 2020
1 parent 7e3f9b1 commit 244eb24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ for ARG in "${ALL_ARGS[@]:-}"; do
case "$ARG" in
--bazel_node_modules_manifest=*) MODULES_MANIFEST="${ARG#--bazel_node_modules_manifest=}" ;;
--nobazel_patch_module_resolver)
declare MAIN="TEMPLATED_entry_point_execroot_path"
if [[ ! -f "$MAIN" ]]; then
MAIN=$(rlocation "TEMPLATED_entry_point_manifest_path")
fi
MAIN=TEMPLATED_script_path
LAUNCHER_NODE_OPTIONS=( "--require" "$node_patches_script" )

# In this case we should always run the linker
Expand Down
8 changes: 6 additions & 2 deletions internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ fi
# Need a smarter split operation than `expanded_arg.split(" ")` as it will split
# up args with intentional spaces and it will fail for expanded files with spaces.
"TEMPLATED_args": " ".join(expanded_args),
"TEMPLATED_entry_point_execroot_path": _to_execroot_path(ctx, ctx.file.entry_point),
"TEMPLATED_entry_point_manifest_path": _to_manifest_path(ctx, ctx.file.entry_point),
"TEMPLATED_env_vars": env_vars,
"TEMPLATED_expected_exit_code": str(expected_exit_code),
"TEMPLATED_link_modules_script": _to_manifest_path(ctx, ctx.file._link_modules_script),
Expand All @@ -259,6 +257,12 @@ fi
"TEMPLATED_runfiles_helper_script": _to_manifest_path(ctx, ctx.file._runfiles_helper_script),
"TEMPLATED_vendored_node": "" if is_builtin else strip_external(ctx.file._node.path),
}

if ctx.file.entry_point.is_source:
substitutions["TEMPLATED_script_path"] = "\"%s\"" % _to_execroot_path(ctx, ctx.file.entry_point)
else:
substitutions["TEMPLATED_script_path"] = "$(rlocation \"%s\")" % _to_manifest_path(ctx, ctx.file.entry_point)

ctx.actions.expand_template(
template = ctx.file._launcher_template,
output = ctx.outputs.launcher_sh,
Expand Down

0 comments on commit 244eb24

Please sign in to comment.