This repository was archived by the owner on Dec 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjava_runtime_toolchain.bzl
More file actions
80 lines (71 loc) · 2.59 KB
/
Copy pathjava_runtime_toolchain.bzl
File metadata and controls
80 lines (71 loc) · 2.59 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
73
74
75
76
77
78
79
80
'''Implements the `java_runtime_toolchain` rule.
Java runtime toolchain instances are created with `java_runtime_toolchain`
rule instances. A separate `toolchain` rule instance is used to declare a
`java_runtime_toolchain` instance has the type
`@dwtj_rules_java//java/toolchains/java_runtime_toolchain:toolchain_type`.
See [the Bazel Toolchain documentation][1] for more information.
An example might look something like this:
```build
java_runtime_toolchain(
name = "my_java",
java_executable = ":my_java_executable",
)
toolchain(
name = "my_java_toolchain",
exec_compatible_with = [
...
],
target_compatible_with = [
...
],
toolchain = ":my_java",
toolchain_type = "@dwtj_rules_java//java/toolchains/java_runtime_toolchain:toolchain_type",
)
```
---
[1]: https://docs.bazel.build/versions/3.4.0/toolchains.html
'''
JavaRuntimeToolchainInfo = provider(
fields = {
"java_executable": "A `java` executable file (in the host configuration).",
"java_run_script_template": "A template from which Java run scripts are instantiated.",
"class_path_separator": "The class path separator to use when invoking this `java` executable."
},
)
def _java_compiler_toolchain_impl(ctx):
java_runtime_toolchain_info = JavaRuntimeToolchainInfo(
java_executable = ctx.file.java_executable,
java_run_script_template = ctx.file._java_run_script_template,
class_path_separator = ctx.attr.class_path_separator,
)
toolchain_info = platform_common.ToolchainInfo(
java_runtime_toolchain_info = java_runtime_toolchain_info,
)
return [
toolchain_info,
java_runtime_toolchain_info,
]
java_runtime_toolchain = rule(
implementation = _java_compiler_toolchain_impl,
attrs = {
"java_executable": attr.label(
allow_single_file = True,
mandatory = True,
executable = True,
cfg = "host",
),
# NOTE(dwtj): This seems like a somewhat roundabout way to make this
# template available for instantiation in the `write_java_run_script`
# helper function, but I haven't yet figured out another way to do it
# which resolves the label to a file.
# TODO(dwtj): Try the `Label()` constructor.
"_java_run_script_template": attr.label(
default = "@dwtj_rules_java//java:common/actions/TEMPLATE.java_run_script.sh",
allow_single_file = True,
),
"class_path_separator": attr.string(
default = ":",
)
},
provides = [JavaRuntimeToolchainInfo],
)