Skip to content

Commit

Permalink
Add named-workspace-relative runfiles lookup to node_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetten committed Nov 1, 2017
1 parent 9dcf8ba commit f011f3c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions node/internal/node_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_launcher(ctx, output_dir, node, manifest):
# The package path is the path
package_path = []
if ctx.label.workspace_root:
package_path.append(ctx.label.workspace_root)
package_path.append(ctx.label.workspace_root.replace("external/", "", 1))
if ctx.label.package:
package_path.append(ctx.label.package)

Expand All @@ -52,25 +52,31 @@ def create_launcher(ctx, output_dir, node, manifest):
# Namespace where node and node_modules assets have been
# built.
'TARGET_NAME="%s"' % ctx.attr.target,
# Workspace name where this rule is defined
'WORKSPACE_NAME="%s"' % ctx.workspace_name,
# Based on the way the script has been invoked, $PACKAGE_PATH
# can exist in various locations. We need to discover this
# and assign the value to $TARGET_PATH.
'TARGET_PATH=""' ,

'ENTRYPOINT="%s"' % entrypoint,

'if [[ -e "${0}_files/${NODE_EXE}" ]]; then',
' TARGET_PATH="${0}_files/"',
#' echo "Matched [standalone script] or [bazel test] context [${TARGET_PATH}]"',
'',
'elif [[ -e "${0}_files/${NODE_EXE}" ]]; then',
' TARGET_PATH="${0}_files/"',
#' echo "Matched [standalone script] or [bazel test] context [${TARGET_PATH}]"',
'',
'elif [[ -e "${0}.runfiles/__main__/${PACKAGE_PATH}/${TARGET_NAME}/${NODE_EXE}" ]]; then',
' TARGET_PATH="${0}.runfiles/__main__/${PACKAGE_PATH}/${TARGET_NAME}/"',
' TARGET_PATH="${0}.runfiles/__main__/${PACKAGE_PATH}/${TARGET_NAME}/"',
#' echo "Matched [bazel run] context [${TARGET_PATH}]"',
'',
'elif [[ -e "${0}.runfiles/${WORKSPACE_NAME}/${PACKAGE_PATH}/${TARGET_NAME}/${NODE_EXE}" ]]; then',
' TARGET_PATH="${0}.runfiles/${WORKSPACE_NAME}/${PACKAGE_PATH}/${TARGET_NAME}/"',
#' echo "Matched [bazel build] or [bazel run] context in a named workspace [${TARGET_PATH}]"',
'',
'elif [[ -e "${0}.runfiles/${PACKAGE_PATH}/${TARGET_NAME}/${NODE_EXE}" ]]; then',
' TARGET_PATH="${0}.runfiles/${PACKAGE_PATH}/${TARGET_NAME}/"',
#' echo "Matched [bazel build] context [${TARGET_PATH}]"',
'',
'elif [[ -e "${PACKAGE_PATH}/${TARGET_NAME}/${NODE_EXE}" ]]; then',
' TARGET_PATH="${PACKAGE_PATH}/${TARGET_NAME}/"',
#' echo "Matched [bazel test TESTRULE] context [${TARGET_PATH}]"',
Expand Down

0 comments on commit f011f3c

Please sign in to comment.