forked from rabbitmq/rabbitmq-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbitmq_run.bzl
80 lines (70 loc) · 2.62 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
76
77
78
79
80
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")
# Note: Theses rules take advantage of the fact that when the files from
# the rabbitmq_home rule are used as runfiles, they are linked in
# at their declared relative paths. In other words, since
# rabbitmq_home declares "sbin/rabbitmq-server", is still at
# "sbin/rabbitmq-server" when our script runs.
def _impl(ctx):
erlang_version = ctx.attr._erlang_version[ErlangVersionProvider].version
rabbitmq_home = ctx.attr.home[RabbitmqHomeInfo]
if rabbitmq_home.erlang_version != erlang_version:
fail("Mismatched erlang versions", erlang_version, rabbitmq_home.erlang_version)
erl_libs = ":".join(
[p.short_path for p in rabbitmq_home.plugins],
)
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.executable,
substitutions = {
"{RABBITMQ_HOME}": ctx.attr.home.label.name,
"{ERL_LIBS}": erl_libs,
"{ERLANG_HOME}": ctx.attr._erlang_home[ErlangHomeProvider].path,
"{SNAME}": sanitize_sname("sbb-" + ctx.attr.name),
},
is_executable = True,
)
return [DefaultInfo(
runfiles = ctx.runfiles(ctx.attr.home[DefaultInfo].files.to_list()),
)]
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"),
"_erlang_version": attr.label(default = "@bazel-erlang//:erlang_version"),
"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,
)