|
| 1 | +"""Analysis tests for js_run_binary exec cfg handling. |
| 2 | +
|
| 3 | +Reproduces: |
| 4 | + https://github.com/aspect-build/rules_js/issues/2121 |
| 5 | + https://github.com/aspect-build/rules_js/issues/2754 |
| 6 | +""" |
| 7 | + |
| 8 | +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") |
| 9 | +load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 10 | +load("//js:defs.bzl", "js_binary", "js_run_binary") |
| 11 | + |
| 12 | +def _exec_cfg_runfiles_test_impl(ctx): |
| 13 | + env = analysistest.begin(ctx) |
| 14 | + target = analysistest.target_under_test(env) |
| 15 | + |
| 16 | + # Files built for exec cfg have "-exec-" in their output path; target-cfg files don't. |
| 17 | + # Source files (not in bazel-out) are cfg-neutral and are excluded from this check. |
| 18 | + non_exec = [ |
| 19 | + f.short_path |
| 20 | + for f in target[DefaultInfo].files.to_list() |
| 21 | + if not f.is_source and "-exec-" not in f.path |
| 22 | + ] |
| 23 | + asserts.equals( |
| 24 | + env, |
| 25 | + [], |
| 26 | + non_exec, |
| 27 | + "runfiles must use exec cfg, not target cfg (#2121, #2754)", |
| 28 | + ) |
| 29 | + return analysistest.end(env) |
| 30 | + |
| 31 | +_exec_cfg_runfiles_test = analysistest.make(_exec_cfg_runfiles_test_impl) |
| 32 | + |
| 33 | +def js_run_binary_exec_cfg_test_suite(name): |
| 34 | + """Regression test for js_run_binary using exec cfg for tool runfiles (#2121, #2754). |
| 35 | +
|
| 36 | + Args: |
| 37 | + name: Name of the test_suite target. |
| 38 | + """ |
| 39 | + write_file(name = "tool_entry_point", out = "js_run_binary_test_tool.js", content = ["process.exit(0);"], tags = ["manual"]) |
| 40 | + |
| 41 | + js_binary( |
| 42 | + name = "js_run_binary_test_tool", |
| 43 | + entry_point = "js_run_binary_test_tool.js", |
| 44 | + tags = ["manual"], |
| 45 | + ) |
| 46 | + |
| 47 | + js_run_binary( |
| 48 | + name = "js_run_binary_test_subject", |
| 49 | + tool = ":js_run_binary_test_tool", |
| 50 | + outs = ["js_run_binary_test_out.txt"], |
| 51 | + tags = ["manual"], |
| 52 | + ) |
| 53 | + |
| 54 | + _exec_cfg_runfiles_test( |
| 55 | + name = name + "_exec_cfg_test", |
| 56 | + target_under_test = ":js_run_binary_test_subject_exec_runfiles", |
| 57 | + ) |
| 58 | + |
| 59 | + native.test_suite( |
| 60 | + name = name, |
| 61 | + tests = [":" + name + "_exec_cfg_test"], |
| 62 | + ) |
0 commit comments