-
-
Notifications
You must be signed in to change notification settings - Fork 167
fix: allow js_run_binary to hoist runfiles in the exec configuration #2809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bb975a4
34f9e68
3873c45
adac4ad
4d6f900
2e0deee
49a6e78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,20 @@ | ||
| "Public API" | ||
|
|
||
| load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
| load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") | ||
|
|
||
| # This flag controls the default value of the use_execroot_exec_cfg flag on | ||
| # js_run_binary. | ||
| bool_flag( | ||
| name = "use_execroot_exec_cfg", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about prefixing this with |
||
| build_setting_default = False, | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| config_setting( | ||
| name = "_use_execroot_exec_cfg_true", | ||
| flag_values = {"use_execroot_exec_cfg": "True"}, | ||
| ) | ||
|
|
||
| bzl_library( | ||
| name = "defs", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,10 +97,18 @@ function logf_debug { | |
|
|
||
| function resolve_execroot_bin_path { | ||
| local short_path="$1" | ||
| local suffix | ||
| if [[ "$short_path" == ../* ]]; then | ||
| echo "$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/external/${short_path:3}" | ||
| suffix="external/${short_path:3}" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just modify |
||
| else | ||
| echo "$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/$short_path" | ||
| suffix="$short_path" | ||
| fi | ||
| local exec_path="$JS_BINARY__EXECROOT/$JS_BINARY__BINDIR/$suffix" | ||
| local target_path="$JS_BINARY__EXECROOT/${BAZEL_BINDIR:-$JS_BINARY__BINDIR}/$suffix" | ||
| if [ -e "$exec_path" ]; then | ||
| echo "$exec_path" | ||
| else | ||
| echo "$target_path" | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,7 @@ js_test( | |
| # TEST: js_test(data = js_run_binary(srcs)) --------------- | ||
| js_run_binary( | ||
| name = "run-write-srcs", | ||
| srcs = ["data.json"], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was essentially an undeclared input before, but magically worked because the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right. With the new option enabled and without this line adding the dep via
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds correct to me 👍 |
||
| outs = ["rb0.json"], | ||
| args = [ | ||
| "rb0.json", | ||
|
|
@@ -142,6 +143,7 @@ js_test( | |
| # TEST: js_test(data = js_run_binary(srcs = js_library(srcs))) ---------------- | ||
| js_run_binary( | ||
| name = "run-write-js_library-srcs", | ||
| srcs = ["data.json"], | ||
| outs = ["rb1.json"], | ||
| args = [ | ||
| "rb1.json", | ||
|
|
@@ -174,6 +176,7 @@ js_binary( | |
|
|
||
| js_run_binary( | ||
| name = "run-write-js_library-data", | ||
| srcs = ["data.json"], | ||
| outs = ["rb2.json"], | ||
| args = [ | ||
| "rb2.json", | ||
|
|
@@ -199,6 +202,7 @@ js_test( | |
| # TEST: js_test(data = js_run_binary(srcs = genrule())) ----------------------- | ||
| js_run_binary( | ||
| name = "run-write-generated", | ||
| srcs = ["data-generated.json"], | ||
| outs = ["rb3.json"], | ||
| args = [ | ||
| "rb3.json", | ||
|
|
@@ -224,6 +228,7 @@ js_test( | |
| # TEST: js_test(data = js_run_binary(srcs = genrule(srcs = filegroup))) ------- | ||
| js_run_binary( | ||
| name = "run-write-generated-copied", | ||
| srcs = ["data-copied.json"], | ||
| outs = ["rb4.json"], | ||
| args = [ | ||
| "rb4.json", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| load("@bazel_lib//lib:diff_test.bzl", "diff_test") | ||
| 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") | ||
|
|
||
| # Verify that the js_binary tool's data dependencies are built in the exec configuration | ||
| # when use_execroot_exec_cfg is True. | ||
| # To do this we check that js_run_binary agrees with genrule on the location of a | ||
| # tool dependency. | ||
| write_file( | ||
| name = "gen_cfg_probe", | ||
| out = "cfg_probe.txt", | ||
| content = ["probe"], | ||
| ) | ||
|
|
||
| js_binary( | ||
| name = "find_cfg_probe", | ||
| data = [":cfg_probe.txt"], | ||
| entry_point = "find_cfg_probe.mjs", | ||
| ) | ||
|
|
||
| js_run_binary( | ||
| name = "tools_cfg_location", | ||
| stdout = "tools_cfg_location.txt", | ||
| tool = ":find_cfg_probe", | ||
| use_execroot_exec_cfg = True, | ||
| ) | ||
|
|
||
| genrule( | ||
| name = "expected_tools_cfg_location", | ||
| outs = ["expected_tools_cfg_location.txt"], | ||
| cmd = "echo $(execpath :cfg_probe.txt) > $@", | ||
| tools = [":cfg_probe.txt"], | ||
| ) | ||
|
|
||
| diff_test( | ||
| name = "tools_exec_cfg_test", | ||
| file1 = ":tools_cfg_location.txt", | ||
| file2 = ":expected_tools_cfg_location.txt", | ||
| ) | ||
|
|
||
| # Verify the opposite: with use_execroot_exec_cfg = False, the tool's data | ||
| # dependencies are built in the target configuration, matching a genrule srcs path. | ||
| js_run_binary( | ||
| name = "target_cfg_location", | ||
| stdout = "target_cfg_location.txt", | ||
| tool = ":find_cfg_probe", | ||
| use_execroot_exec_cfg = False, | ||
| ) | ||
|
|
||
| genrule( | ||
| name = "expected_target_cfg_location", | ||
| srcs = [":cfg_probe.txt"], | ||
| outs = ["expected_target_cfg_location.txt"], | ||
| cmd = "echo $(execpath :cfg_probe.txt) > $@", | ||
| ) | ||
|
|
||
| diff_test( | ||
| name = "target_cfg_test", | ||
| file1 = ":target_cfg_location.txt", | ||
| file2 = ":expected_target_cfg_location.txt", | ||
| ) | ||
|
|
||
| # Verify that dependencies passed via the srcs parameter are always built for | ||
| # the target platform, unlike the tool parameter and its dependencies. | ||
| # We use a select() on the OS to produce a platform-specific file, then | ||
| # transition to three different target platforms and assert the contents match. | ||
| write_file( | ||
| name = "gen_os_name", | ||
| out = "os_name.txt", | ||
| content = select({ | ||
| "@platforms//os:linux": ["linux"], | ||
| "@platforms//os:macos": ["macos"], | ||
| "@platforms//os:windows": ["windows"], | ||
| "//conditions:default": ["other"], | ||
| }), | ||
| tags = ["manual"], | ||
| ) | ||
|
|
||
| platform( | ||
| name = "linux", | ||
| constraint_values = ["@platforms//os:linux"], | ||
| ) | ||
|
|
||
| platform( | ||
| name = "macos", | ||
| constraint_values = ["@platforms//os:macos"], | ||
| ) | ||
|
|
||
| platform( | ||
| name = "windows", | ||
| constraint_values = ["@platforms//os:windows"], | ||
| ) | ||
|
|
||
| js_binary( | ||
| name = "read_file", | ||
| entry_point = "read_file.mjs", | ||
| ) | ||
|
|
||
| js_run_binary( | ||
| name = "gen_target_os", | ||
| srcs = [":os_name.txt"], | ||
| args = ["$(rootpath :os_name.txt)"], | ||
| stdout = "target_os.txt", | ||
| tags = ["manual"], | ||
| tool = ":read_file", | ||
| use_execroot_exec_cfg = True, | ||
| ) | ||
|
|
||
| platform_transition_filegroup( | ||
| name = "target_os_linux", | ||
| srcs = [":gen_target_os"], | ||
| target_platform = ":linux", | ||
| ) | ||
|
|
||
| platform_transition_filegroup( | ||
| name = "target_os_macos", | ||
| srcs = [":gen_target_os"], | ||
| target_platform = ":macos", | ||
| ) | ||
|
|
||
| platform_transition_filegroup( | ||
| name = "target_os_windows", | ||
| srcs = [":gen_target_os"], | ||
| target_platform = ":windows", | ||
| ) | ||
|
|
||
| assert_contains( | ||
| name = "linux_target_platform_test", | ||
| actual = ":target_os_linux", | ||
| expected = "linux", | ||
| ) | ||
|
|
||
| assert_contains( | ||
| name = "macos_target_platform_test", | ||
| actual = ":target_os_macos", | ||
| expected = "macos", | ||
| ) | ||
|
|
||
| assert_contains( | ||
| name = "windows_target_platform_test", | ||
| actual = ":target_os_windows", | ||
| expected = "windows", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment just like this for the reason we need 3.3.0?