Skip to content

Commit 612b4f7

Browse files
committed
Synchronize mixed versions approach with v3.8.x
(cherry picked from commit 8cc9806)
1 parent 54b7c2b commit 612b4f7

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

BUILD.package_generic_unix

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ load("@//:rabbitmqctl.bzl", "rabbitmqctl")
44

55
rabbitmq_package_generic_unix(
66
name = "broker-home",
7-
sbin = glob(["sbin/*"]),
8-
escript = glob(["escript/*"]),
9-
plugins = [
10-
"//plugins:standard_plugins",
11-
"//plugins:inet_tcp_proxy_ez",
12-
],
7+
additional_files =
8+
glob(
9+
[
10+
"sbin/*",
11+
"escript/*",
12+
],
13+
exclude = ["sbin/rabbitmqctl"],
14+
) + [
15+
"//plugins:standard_plugins",
16+
"//plugins:inet_tcp_proxy_ez",
17+
],
18+
rabbitmqctl = "sbin/rabbitmqctl",
1319
)
1420

1521
rabbitmq_run(
@@ -27,7 +33,6 @@ rabbitmq_run_command(
2733
rabbitmqctl(
2834
name = "rabbitmqctl",
2935
home = ":broker-home",
30-
# visibility = ["//visibility:public"],
3136
)
3237

3338
rabbitmqctl(

rabbitmq_home.bzl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ load("@bazel-erlang//:bazel_erlang_lib.bzl", "ErlangLibInfo", "flat_deps", "path
33
RabbitmqHomeInfo = provider(
44
doc = "An assembled RABBITMQ_HOME dir",
55
fields = {
6-
"sbin": "Files making up the sbin dir",
7-
"escript": "Files making up the escript dir",
8-
"plugins": "Files making up the plugins dir",
6+
"rabbitmqctl": "rabbitmqctl script from the sbin directory",
97
},
108
)
119

@@ -112,11 +110,16 @@ def _impl(ctx):
112110

113111
plugins = _flatten([_plugins_dir_links(ctx, plugin) for plugin in plugins])
114112

113+
rabbitmqctl = None
114+
for script in scripts:
115+
if script.basename == "rabbitmqctl":
116+
rabbitmqctl = script
117+
if rabbitmqctl == None:
118+
fail("could not find rabbitmqct among", scripts)
119+
115120
return [
116121
RabbitmqHomeInfo(
117-
sbin = scripts,
118-
escript = escripts,
119-
plugins = plugins,
122+
rabbitmqctl = rabbitmqctl,
120123
),
121124
DefaultInfo(
122125
files = depset(scripts + escripts + plugins),
@@ -147,7 +150,7 @@ def _dirname(p):
147150
return p.rpartition("/")[0]
148151

149152
def rabbitmq_home_short_path(rabbitmq_home):
150-
short_path = rabbitmq_home[RabbitmqHomeInfo].sbin[0].short_path
153+
short_path = rabbitmq_home[RabbitmqHomeInfo].rabbitmqctl.short_path
151154
if rabbitmq_home.label.workspace_root != "":
152155
short_path = path_join(rabbitmq_home.label.workspace_root, short_path)
153156
return _dirname(_dirname(short_path))

rabbitmq_package_generic_unix.bzl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
load("@//:rabbitmq_home.bzl", "RabbitmqHomeInfo")
22

33
def _impl(ctx):
4-
scripts = ctx.files.sbin
5-
escripts = ctx.files.escript
6-
plugins = ctx.files.plugins
7-
84
return [
95
RabbitmqHomeInfo(
10-
sbin = scripts,
11-
escript = escripts,
12-
plugins = plugins,
6+
rabbitmqctl = ctx.file.rabbitmqctl,
137
),
148
DefaultInfo(
15-
files = depset(scripts + escripts + plugins),
9+
files = depset(ctx.files.rabbitmqctl + ctx.files.additional_files),
1610
),
1711
]
1812

1913
rabbitmq_package_generic_unix = rule(
2014
implementation = _impl,
2115
attrs = {
22-
"sbin": attr.label_list(allow_files = True),
23-
"escript": attr.label_list(allow_files = True),
24-
"plugins": attr.label_list(allow_files = True),
16+
"rabbitmqctl": attr.label(allow_single_file = True),
17+
"additional_files": attr.label_list(allow_files = True),
2518
},
2619
)

rabbitmq_run.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load(":rabbitmq_home.bzl", "RabbitmqHomeInfo", "rabbitmq_home_short_path")
66
def _impl(ctx):
77
rabbitmq_home_path = rabbitmq_home_short_path(ctx.attr.home)
88

9+
# the rabbitmq-run.sh template only allows a single erl_libs currently
910
erl_libs = [path_join(rabbitmq_home_path, "plugins")]
1011

1112
ctx.actions.expand_template(

scripts/bazel/rabbitmq-run.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
rmq_realpath() {
5+
local path=$1
6+
7+
if [ -d "$path" ]; then
8+
cd "$path" && pwd
9+
elif [ -f "$path" ]; then
10+
cd "$(dirname "$path")" && echo $(pwd)/$(basename "$path")
11+
else
12+
echo "$path"
13+
fi
14+
}
15+
416
if [ -z ${TEST_SRCDIR+x} ]; then
517
BASE_DIR=$PWD
618
else
@@ -41,7 +53,7 @@ if [ ! -z ${EXTRA_PLUGINS_DIR+x} ]; then
4153
fi
4254

4355
TEST_TMPDIR=${TEST_TMPDIR:=${TMPDIR}/rabbitmq-test-instances}
44-
RABBITMQ_SCRIPTS_DIR=${BASE_DIR}/{RABBITMQ_HOME}/sbin
56+
RABBITMQ_SCRIPTS_DIR="$(rmq_realpath ${BASE_DIR}/{RABBITMQ_HOME}/sbin)"
4557
RABBITMQ_PLUGINS=${RABBITMQ_SCRIPTS_DIR}/rabbitmq-plugins
4658
RABBITMQ_SERVER=${RABBITMQ_SCRIPTS_DIR}/rabbitmq-server
4759
RABBITMQCTL=${RABBITMQ_SCRIPTS_DIR}/rabbitmqctl

0 commit comments

Comments
 (0)