forked from bazelruby/rules_ruby
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathruntime_alias.bzl
98 lines (86 loc) · 2.58 KB
/
runtime_alias.bzl
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_java//java:defs.bzl", "java_binary")
load(":constants.bzl", "TOOLCHAIN_TYPE_NAME")
load(":providers.bzl", "RubyRuntimeToolchainInfo")
# These rules expose the runtime targets of whichever toolchain has been resolved.
def _ruby_runtime_alias_impl(ctx):
ruby = ctx.toolchains[TOOLCHAIN_TYPE_NAME].ruby_runtime
return [
DefaultInfo(
runfiles = ctx.runfiles(transitive_files = depset(ruby.runtime)),
files = depset(ruby.runtime),
),
ruby,
]
ruby_runtime_alias = rule(
implementation = _ruby_runtime_alias_impl,
toolchains = [TOOLCHAIN_TYPE_NAME],
)
def _ruby_jars_alias_impl(ctx):
runtime = ctx.attr.runtime[RubyRuntimeToolchainInfo]
target = runtime.jars
infos = [
DefaultInfo(
files = target.files,
runfiles = ctx.runfiles(transitive_files = target.files),
),
]
for jar in infos[0].files.to_list():
infos.append(JavaInfo(jar, jar))
return infos
ruby_jars_alias = rule(
implementation = _ruby_jars_alias_impl,
attrs = {
"runtime": attr.label(
doc = "The runtime alias to use.",
mandatory = True,
),
},
)
def _ruby_headers_alias_impl(ctx):
runtime = ctx.attr.runtime[RubyRuntimeToolchainInfo]
target = runtime.headers
return [
ctx.attr.runtime[DefaultInfo],
target[CcInfo],
target[InstrumentedFilesInfo],
target[OutputGroupInfo],
]
ruby_headers_alias = rule(
implementation = _ruby_headers_alias_impl,
attrs = {
"runtime": attr.label(
doc = "The runtime alias to use.",
mandatory = True,
),
},
)
def _ruby_interpreter_alias_impl(ctx):
runtime = ctx.attr.runtime[RubyRuntimeToolchainInfo]
target = runtime.interpreter
output = ctx.actions.declare_file("ruby_interpreter")
ctx.actions.symlink(
output = output,
target_file = target[DefaultInfo].files_to_run.executable,
is_executable = True,
)
runfiles = ctx.attr.runtime[DefaultInfo].default_runfiles.merge(
ctx.attr.runtime[DefaultInfo].data_runfiles,
)
return [
DefaultInfo(
files = target.files,
runfiles = runfiles,
executable = output,
),
]
ruby_interpreter_alias = rule(
implementation = _ruby_interpreter_alias_impl,
executable = True,
attrs = {
"runtime": attr.label(
doc = "The runtime alias to use.",
mandatory = True,
),
},
)