forked from rabbitmq/rabbitmq-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrabbitmq_run.bzl
75 lines (63 loc) · 2.19 KB
/
rabbitmq_run.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
load("@bazel-erlang//:erlang_home.bzl", "ErlangHomeProvider", "ErlangVersionProvider")
load("@bazel-erlang//:bazel_erlang_lib.bzl", "path_join")
load("@bazel-erlang//:ct.bzl", "sanitize_sname")
load(":rabbitmq_home.bzl", "RabbitmqHomeInfo")
def _dirname(p):
return p.rpartition("/")[0]
def _rabbitmq_home_info_root_short_path(rabbitmq_home):
return _dirname(_dirname(rabbitmq_home.sbin[0].short_path))
def _impl(ctx):
rabbitmq_home = ctx.attr.home[RabbitmqHomeInfo]
root = _rabbitmq_home_info_root_short_path(rabbitmq_home)
erl_libs = [path_join(root, "plugins")]
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.executable,
substitutions = {
"{RABBITMQ_HOME}": root,
"{ERL_LIBS}": ":".join(erl_libs),
"{ERLANG_HOME}": ctx.attr._erlang_home[ErlangHomeProvider].path,
"{SNAME}": sanitize_sname("sbb-" + ctx.attr.name),
},
is_executable = True,
)
runfiles = ctx.runfiles(ctx.attr.home[DefaultInfo].files.to_list())
return [DefaultInfo(runfiles = runfiles)]
rabbitmq_run = rule(
implementation = _impl,
attrs = {
"_template": attr.label(
default = Label("//:scripts/bazel/rabbitmq-run.sh"),
allow_single_file = True,
),
"_erlang_home": attr.label(default = "@bazel-erlang//:erlang_home"),
"home": attr.label(providers = [RabbitmqHomeInfo]),
},
executable = True,
)
def _run_command_impl(ctx):
ctx.actions.write(
output = ctx.outputs.executable,
content = "exec ./{} {} $@".format(
ctx.attr.rabbitmq_run[DefaultInfo].files_to_run.executable.short_path,
ctx.attr.subcommand,
),
)
return [DefaultInfo(
runfiles = ctx.attr.rabbitmq_run[DefaultInfo].default_runfiles,
)]
rabbitmq_run_command = rule(
implementation = _run_command_impl,
attrs = {
"rabbitmq_run": attr.label(
executable = True,
cfg = "target",
),
"subcommand": attr.string(values = [
"run-broker",
"start-background-broker",
"stop-node",
]),
},
executable = True,
)