-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrule.bzl
66 lines (58 loc) · 1.76 KB
/
rule.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
PatchelfInfo = provider(
doc = "Patchelf",
fields = ["patchelf_binary"],
)
def _patchelf_toolchain_impl(ctx):
toolchain_info = platform_common.ToolchainInfo(
patchelf = PatchelfInfo(
patchelf_binary = ctx.attr.patchelf_binary,
),
)
return [toolchain_info]
patchelf_toolchain = rule(
implementation = _patchelf_toolchain_impl,
attrs = {
"patchelf_binary": attr.label(
mandatory = True,
allow_single_file = True,
executable = True,
cfg = "exec",
),
},
)
def _patchelf_impl(ctx):
patchelf = ctx.toolchains["@com_github_rules_patchelf//:toolchain_type"].patchelf.patchelf_binary
file = ctx.file.obj
cmd = ctx.attr.command
arguments = (cmd + " " + file.path).split(" ")
out = None
if ctx.attr.output:
out = ctx.actions.declare_file(ctx.attr.output)
arguments.append("--output")
arguments.append(out.path)
else:
out = ctx.actions.declare_file(ctx.attr.name + "_null")
ctx.actions.run(
outputs = [out],
inputs = [ctx.file.obj, patchelf.files_to_run.executable],
executable = str(patchelf.files_to_run.executable.path),
arguments = arguments,
)
return [
DefaultInfo(
files = depset([out]),
),
]
# TODO: perhaps rename this to patchelf_shared_library
# since it's not creating executable outputs
patchelf = rule(
implementation = _patchelf_impl,
attrs = {
"obj": attr.label(
allow_single_file = True,
),
"command": attr.string(),
"output": attr.string(), # TODO: should this be mandatory since otherwise it's in-place?
},
toolchains = ["@com_github_rules_patchelf//:toolchain_type"],
)