From fa0b8fb4ad5a549e9d849f754d6ba735d956ba97 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Wed, 25 Mar 2020 20:38:54 -0700 Subject: [PATCH] fix(builtin): windows fix for nodejs_binary entry point logic --- internal/node/launcher.sh | 8 +++++++- internal/node/node.bzl | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/node/launcher.sh b/internal/node/launcher.sh index 2a1992c446..4dfac7ad20 100644 --- a/internal/node/launcher.sh +++ b/internal/node/launcher.sh @@ -191,7 +191,13 @@ for ARG in "${ALL_ARGS[@]:-}"; do case "$ARG" in --bazel_node_modules_manifest=*) MODULES_MANIFEST="${ARG#--bazel_node_modules_manifest=}" ;; --nobazel_patch_module_resolver) - MAIN="TEMPLATED_script_path" + declare MAIN=$(rlocation "TEMPLATED_entry_point_manifest_path") + if [[ ! -f "$MAIN" ]]; then + MAIN="TEMPLATED_entry_point_runfiles_path" + fi + if [[ ! -f "$MAIN" ]]; then + MAIN="TEMPLATED_entry_point_execroot_path" + fi LAUNCHER_NODE_OPTIONS=( "--require" "$node_patches_script" ) # In this case we should always run the linker diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 999db6f872..5329445aec 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -144,6 +144,12 @@ def _to_execroot_path(ctx, file): return "/".join(parts[2:]) return file.path +def _to_runfiles_path(ctx, file): + result = _to_execroot_path(ctx, file) + if result.startswith(ctx.bin_dir.path + "/"): + result = result[len(ctx.bin_dir.path) + 1:] + return result + def _nodejs_binary_impl(ctx): node_modules_manifest = write_node_modules_manifest(ctx) node_modules_depsets = [] @@ -216,6 +222,9 @@ def _nodejs_binary_impl(ctx): expand_location_into_runfiles(ctx, a, ctx.attr.data) for a in ctx.attr.templated_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_entry_point_runfiles_path": _to_runfiles_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), @@ -225,7 +234,6 @@ def _nodejs_binary_impl(ctx): "TEMPLATED_repository_args": _to_manifest_path(ctx, ctx.file._repository_args), "TEMPLATED_require_patch_script": _to_manifest_path(ctx, ctx.outputs.require_patch_script), "TEMPLATED_runfiles_helper_script": _to_manifest_path(ctx, ctx.file._runfiles_helper_script), - "TEMPLATED_script_path": _to_execroot_path(ctx, ctx.file.entry_point), "TEMPLATED_vendored_node": "" if is_builtin else strip_external(ctx.file._node.path), } ctx.actions.expand_template(