Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions js/private/js_binary.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,36 @@ function logf_debug {
fi
}

function _normalize_cpu {
case "$1" in
*aarch64* | *arm64*) echo "arm64" ;;
*amd64* | *k8* | *x86_64*) echo "x64" ;;
*) echo "$1" ;;
esac
}

function _use_exec_config_entry_point {
if [ "$(_normalize_cpu "${BAZEL_TARGET_CPU:-}")" != "$(_normalize_cpu "${JS_BINARY__TARGET_CPU:-}")" ]; then
return 0
fi
case "${BAZEL_BINDIR:-}" in
bazel-out/*-ST-* | bazel-out/platform-*) return 0 ;;
*) return 1 ;;
esac
}

function resolve_execroot_bin_path {
local short_path="$1"
local bindir="${BAZEL_BINDIR:-$JS_BINARY__BINDIR}"
if [ "${JS_BINARY__USE_EXECROOT_ENTRY_POINT:-}" ]; then
if _use_exec_config_entry_point; then
bindir="$JS_BINARY__BINDIR"
fi
fi
if [[ "$short_path" == ../* ]]; then
echo "$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/external/${short_path:3}"
echo "$JS_BINARY__EXECROOT/$bindir/external/${short_path:3}"
else
echo "$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/$short_path"
echo "$JS_BINARY__EXECROOT/$bindir/$short_path"
fi
}

Expand Down
31 changes: 31 additions & 0 deletions js/private/js_run_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ See https://github.com/aspect-build/rules_js/tree/main/docs#using-binaries-publi
testonly = kwargs.get("testonly", False),
)
extra_srcs.append(":{}".format(js_runfiles_name))
js_exec_runfiles_name = "{}_exec_runfiles".format(name)
_js_binary_exec_runfiles(
name = js_exec_runfiles_name,
tool = tool,
# Always tag the target manual since we should only build it when the final target is built.
tags = kwargs.get("tags", []) + ["manual"],
# Always propagate the testonly attribute
testonly = kwargs.get("testonly", False),
)
extra_srcs.append(":{}".format(js_exec_runfiles_name))

if allow_execroot_entry_point_with_no_copy_data_to_bin:
fixed_env["JS_BINARY__ALLOW_EXECROOT_ENTRY_POINT_WITH_NO_COPY_DATA_TO_BIN"] = "1"
Expand All @@ -400,3 +410,24 @@ See https://github.com/aspect-build/rules_js/tree/main/docs#using-binaries-publi
use_default_shell_env = use_default_shell_env,
**kwargs
)

def _js_binary_exec_runfiles_impl(ctx):
return DefaultInfo(
files = ctx.attr.tool[DefaultInfo].default_runfiles.files,
)

_js_binary_exec_runfiles = rule(
implementation = _js_binary_exec_runfiles_impl,
attrs = {
"tool": attr.label(
doc = """The js_binary tool whose execution-configuration runfiles should be available as action inputs.

js_run_binary executes its tool in the execution configuration. When use_execroot_entry_point is enabled,
the tool's runfiles must come from the same configuration so native optional npm packages are filtered for
the platform that runs the action, not for the target platform being built.
""",
mandatory = True,
cfg = "exec",
),
},
)
4 changes: 2 additions & 2 deletions js/private/test/image/custom_owner_test_app.listing
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/
-r-xr-xr-x 0 100 0 xxxxx Jan 1 1970 ./js/private/test/image/bin
-r-xr-xr-x 0 100 0 25394 Jan 1 1970 ./js/private/test/image/bin
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/
Expand All @@ -14,7 +14,7 @@ drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runf
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image-fixture-d/
-r-xr-xr-x 0 100 0 128 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image-fixture-d/package.json
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/
-r-xr-xr-x 0 100 0 xxxxx Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/bin
-r-xr-xr-x 0 100 0 25394 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/bin
drwxr-xr-x 0 100 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_node_bin/
-r-xr-xr-x 0 100 0 133 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_node_bin/node
-r-xr-xr-x 0 100 0 20 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/main.js
4 changes: 2 additions & 2 deletions js/private/test/image/default_test_app.listing
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./js/private/test/image/bin
-r-xr-xr-x 0 0 0 25394 Jan 1 1970 ./js/private/test/image/bin
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/
Expand All @@ -14,7 +14,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runf
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image-fixture-d/
-r-xr-xr-x 0 0 0 128 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image-fixture-d/package.json
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/bin
-r-xr-xr-x 0 0 0 25394 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/bin
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_node_bin/
-r-xr-xr-x 0 0 0 133 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_node_bin/node
-r-xr-xr-x 0 0 0 20 Jan 1 1970 ./js/private/test/image/bin.runfiles/_main/js/private/test/image/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2
-r-xr-xr-x 0 0 0 25489 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/
Expand All @@ -14,7 +14,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/
-r-xr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/ㅑㅕㅣㅇ.ㄴㅅ
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_/
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_/bin2
-r-xr-xr-x 0 0 0 25489 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_/bin2
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_node_bin/
-r-xr-xr-x 0 0 0 133 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/bin2_node_bin/node
-r-xr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/non_ascii/bin2.runfiles/_main/js/private/test/image/non_ascii/empty empty.ㄴㅅ
Expand Down
4 changes: 2 additions & 2 deletions js/private/test/image/regex_edge_cases_test_app.listing
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./app/js/private/test/image/bin
-r-xr-xr-x 0 0 0 25394 Jan 1 1970 ./app/js/private/test/image/bin
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/
Expand All @@ -15,7 +15,7 @@ drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image-fixture-d/
-r-xr-xr-x 0 0 0 128 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image-fixture-d/package.json
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/
-r-xr-xr-x 0 0 0 xxxxx Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/bin
-r-xr-xr-x 0 0 0 25394 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_/bin
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_node_bin/
-r-xr-xr-x 0 0 0 133 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/bin_node_bin/node
-r-xr-xr-x 0 0 0 20 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/main.js
72 changes: 72 additions & 0 deletions js/private/test/js_run_binary_exec_config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
load("@bazel_lib//lib:testing.bzl", "assert_contains")
load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//js:defs.bzl", "js_binary", "js_run_binary")

config_setting(
name = "linux_arm64_target",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
)

platform(
name = "linux_arm64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
)

write_file(
name = "write_tool",
out = "tool.mjs",
content = [
"""import { readFileSync } from "node:fs";""",
"""import { dirname, join } from "node:path";""",
"""import { fileURLToPath } from "node:url";""",
"""const here = dirname(fileURLToPath(import.meta.url));""",
"""console.log(readFileSync(join(here, "exec_config_marker.txt"), "utf8").trim());""",
],
)

write_file(
name = "write_exec_marker",
out = "exec_config_marker.txt",
content = ["exec-config-data"],
)

write_file(
name = "write_target_marker",
out = "target_config_marker.txt",
content = ["target-config-data"],
)

js_binary(
name = "tool",
data = select({
":linux_arm64_target": [":target_config_marker.txt"],
"//conditions:default": [":exec_config_marker.txt"],
}),
entry_point = "tool.mjs",
)

js_run_binary(
name = "run_tool",
stdout = "run_tool.out",
tool = ":tool",
)

platform_transition_filegroup(
name = "run_tool_linux_arm64",
testonly = True,
srcs = [":run_tool"],
target_platform = ":linux_arm64",
)

assert_contains(
name = "run_tool_uses_exec_config_runfiles",
actual = ":run_tool_linux_arm64",
expected = "exec-config-data",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make exec-config test independent of host CPU architecture

This assertion assumes the execution platform is never linux_arm64, but on ARM64 Linux runners the tool’s exec configuration will also match :linux_arm64_target, so target_config_marker.txt is selected and the expected exec-config-data string is wrong. That makes the new test fail on valid environments even when js_run_binary is behaving correctly; the check needs to force a distinct exec platform (or make the marker selection architecture-agnostic) to avoid host-dependent failures.

Useful? React with 👍 / 👎.

)
28 changes: 26 additions & 2 deletions js/private/test/snapshots/launcher.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.