|
| 1 | +load("@bazel_lib//lib:testing.bzl", "assert_contains") |
| 2 | +load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") |
| 3 | +load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 4 | +load("//js:defs.bzl", "js_binary", "js_run_binary") |
| 5 | + |
| 6 | +config_setting( |
| 7 | + name = "linux_arm64_target", |
| 8 | + constraint_values = [ |
| 9 | + "@platforms//os:linux", |
| 10 | + "@platforms//cpu:arm64", |
| 11 | + ], |
| 12 | +) |
| 13 | + |
| 14 | +platform( |
| 15 | + name = "linux_arm64", |
| 16 | + constraint_values = [ |
| 17 | + "@platforms//os:linux", |
| 18 | + "@platforms//cpu:arm64", |
| 19 | + ], |
| 20 | +) |
| 21 | + |
| 22 | +write_file( |
| 23 | + name = "write_tool", |
| 24 | + out = "tool.mjs", |
| 25 | + content = [ |
| 26 | + """import { readFileSync } from "node:fs";""", |
| 27 | + """import { dirname, join } from "node:path";""", |
| 28 | + """import { fileURLToPath } from "node:url";""", |
| 29 | + """const here = dirname(fileURLToPath(import.meta.url));""", |
| 30 | + """console.log(readFileSync(join(here, "exec_config_marker.txt"), "utf8").trim());""", |
| 31 | + ], |
| 32 | +) |
| 33 | + |
| 34 | +write_file( |
| 35 | + name = "write_exec_marker", |
| 36 | + out = "exec_config_marker.txt", |
| 37 | + content = ["exec-config-data"], |
| 38 | +) |
| 39 | + |
| 40 | +write_file( |
| 41 | + name = "write_target_marker", |
| 42 | + out = "target_config_marker.txt", |
| 43 | + content = ["target-config-data"], |
| 44 | +) |
| 45 | + |
| 46 | +js_binary( |
| 47 | + name = "tool", |
| 48 | + data = select({ |
| 49 | + ":linux_arm64_target": [":target_config_marker.txt"], |
| 50 | + "//conditions:default": [":exec_config_marker.txt"], |
| 51 | + }), |
| 52 | + entry_point = "tool.mjs", |
| 53 | +) |
| 54 | + |
| 55 | +js_run_binary( |
| 56 | + name = "run_tool", |
| 57 | + stdout = "run_tool.out", |
| 58 | + tool = ":tool", |
| 59 | +) |
| 60 | + |
| 61 | +platform_transition_filegroup( |
| 62 | + name = "run_tool_linux_arm64", |
| 63 | + testonly = True, |
| 64 | + srcs = [":run_tool"], |
| 65 | + target_platform = ":linux_arm64", |
| 66 | +) |
| 67 | + |
| 68 | +assert_contains( |
| 69 | + name = "run_tool_uses_exec_config_runfiles", |
| 70 | + actual = ":run_tool_linux_arm64", |
| 71 | + expected = "exec-config-data", |
| 72 | +) |
0 commit comments