forked from aspect-build/rules_js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUILD.bazel
More file actions
72 lines (63 loc) · 1.75 KB
/
BUILD.bazel
File metadata and controls
72 lines (63 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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",
)