Skip to content

Commit 4052c70

Browse files
committed
Add Bazel build (#47)
Add Bazel build files corresponding to rabbitmq/rabbitmq-server#2938 The gnu make build should remain unchanged by theses additions
1 parent b2af652 commit 4052c70

File tree

7 files changed

+186
-49
lines changed

7 files changed

+186
-49
lines changed

.github/workflows/build.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build
2+
on: push
3+
jobs:
4+
test:
5+
name: build
6+
runs-on: ubuntu-18.04
7+
strategy:
8+
matrix:
9+
erlang_version:
10+
- "23.2"
11+
timeout-minutes: 10
12+
steps:
13+
- name: CHECKOUT REPOSITORY
14+
uses: actions/checkout@v2
15+
- name: CONFIGURE OTP & ELIXIR
16+
uses: actions/setup-elixir@v1
17+
with:
18+
otp-version: ${{ matrix.erlang_version }}
19+
elixir-version: 1.10.4
20+
- name: CONFIGURE BAZEL
21+
run: |
22+
ERLANG_HOME="$(dirname $(dirname $(which erl)))"
23+
cat << EOF >> .bazelrc
24+
build --@bazel-erlang//:erlang_version=${{ matrix.erlang_version }}
25+
build --@bazel-erlang//:erlang_home=${ERLANG_HOME}
26+
EOF
27+
#! - name: Setup tmate session
28+
#! uses: mxschmitt/action-tmate@v3
29+
- name: BUILD
30+
run: |
31+
bazelisk build :bazel_erlang_lib

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ terraform.tfstate*
2020

2121
/rabbitmq_ct_helpers.d
2222
/.rabbitmq_ct_helpers.plt
23+
24+
/.bazelrc
25+
/bazel-*

BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("@bazel-erlang//:bazel_erlang_lib.bzl", "erlang_lib")
2+
3+
erlang_lib(
4+
app_name = "rabbitmq_ct_helpers",
5+
app_version = "master",
6+
deps = [
7+
"@proper//:bazel_erlang_lib",
8+
"@rabbitmq-server//deps/rabbit_common:bazel_erlang_lib",
9+
],
10+
)

WORKSPACE.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
http_archive(
4+
name = "bazel-erlang",
5+
strip_prefix = "bazel-erlang-master",
6+
urls = ["https://github.com/rabbitmq/bazel-erlang/archive/master.zip"],
7+
)
8+
9+
http_archive(
10+
name = "rabbitmq-server",
11+
strip_prefix = "rabbitmq-server-master",
12+
urls = ["https://github.com/rabbitmq/rabbitmq-server/archive/master.zip"],
13+
)
14+
15+
load("@rabbitmq-server//:workspace_helpers.bzl", "rabbitmq_external_deps")
16+
17+
rabbitmq_external_deps()

src/rabbit_ct_broker_helpers.erl

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,27 @@
197197
%% -------------------------------------------------------------------
198198

199199
setup_steps() ->
200-
[
201-
fun run_make_dist/1,
202-
fun rabbit_ct_helpers:ensure_rabbitmqctl_cmd/1,
203-
fun rabbit_ct_helpers:ensure_rabbitmqctl_app/1,
204-
fun rabbit_ct_helpers:ensure_rabbitmq_plugins_cmd/1,
205-
fun set_lager_flood_limit/1,
206-
fun start_rabbitmq_nodes/1,
207-
fun share_dist_and_proxy_ports_map/1
208-
].
200+
case os:getenv("RABBITMQ_RUN") of
201+
false ->
202+
[
203+
fun run_make_dist/1,
204+
fun rabbit_ct_helpers:ensure_rabbitmqctl_cmd/1,
205+
fun rabbit_ct_helpers:ensure_rabbitmqctl_app/1,
206+
fun rabbit_ct_helpers:ensure_rabbitmq_plugins_cmd/1,
207+
fun set_lager_flood_limit/1,
208+
fun start_rabbitmq_nodes/1,
209+
fun share_dist_and_proxy_ports_map/1
210+
];
211+
_ ->
212+
[
213+
fun rabbit_ct_helpers:ensure_rabbitmqctl_cmd/1,
214+
fun rabbit_ct_helpers:load_rabbitmqctl_app/1,
215+
fun rabbit_ct_helpers:ensure_rabbitmq_plugins_cmd/1,
216+
fun set_lager_flood_limit/1,
217+
fun start_rabbitmq_nodes/1,
218+
fun share_dist_and_proxy_ports_map/1
219+
]
220+
end.
209221

210222
teardown_steps() ->
211223
[
@@ -641,13 +653,7 @@ do_start_rabbitmq_node(Config, NodeConfig, I) ->
641653
undefined ->
642654
ExtraArgs0;
643655
ExtraPluginsDir ->
644-
PathSep = case os:type() of
645-
{win32, _} -> ";";
646-
_ -> ":"
647-
end,
648-
RegularPluginsDir = filename:join(SrcDir, "plugins"),
649-
[{"RABBITMQ_PLUGINS_DIR=~s~s~s",
650-
[RegularPluginsDir, PathSep, ExtraPluginsDir]}
656+
[{"EXTRA_PLUGINS_DIR=~s", [ExtraPluginsDir]}
651657
| ExtraArgs0]
652658
end,
653659
StartWithPluginsDisabled = rabbit_ct_helpers:get_config(
@@ -712,17 +718,33 @@ do_start_rabbitmq_node(Config, NodeConfig, I) ->
712718
{"TEST_TMPDIR=~s", [PrivDir]}
713719
| ExtraArgs],
714720
Cmd = ["start-background-broker" | MakeVars],
715-
case rabbit_ct_helpers:make(Config, SrcDir, Cmd) of
716-
{ok, _} ->
717-
NodeConfig1 = rabbit_ct_helpers:set_config(
718-
NodeConfig,
719-
[{effective_srcdir, SrcDir},
720-
{make_vars_for_node_startup, MakeVars}]),
721-
query_node(Config, NodeConfig1);
722-
_ ->
723-
AbortCmd = ["stop-node" | MakeVars],
724-
_ = rabbit_ct_helpers:make(Config, SrcDir, AbortCmd),
725-
{skip, "Failed to initialize RabbitMQ"}
721+
case rabbit_ct_helpers:get_config(Config, rabbitmq_run_cmd) of
722+
undefined ->
723+
case rabbit_ct_helpers:make(Config, SrcDir, Cmd) of
724+
{ok, _} ->
725+
NodeConfig1 = rabbit_ct_helpers:set_config(
726+
NodeConfig,
727+
[{effective_srcdir, SrcDir},
728+
{make_vars_for_node_startup, MakeVars}]),
729+
query_node(Config, NodeConfig1);
730+
_ ->
731+
AbortCmd = ["stop-node" | MakeVars],
732+
_ = rabbit_ct_helpers:make(Config, SrcDir, AbortCmd),
733+
{skip, "Failed to initialize RabbitMQ"}
734+
end;
735+
RunCmd ->
736+
case rabbit_ct_helpers:exec([RunCmd, "-C", SrcDir] ++ Cmd) of
737+
{ok, _} ->
738+
NodeConfig1 = rabbit_ct_helpers:set_config(
739+
NodeConfig,
740+
[{effective_srcdir, SrcDir},
741+
{make_vars_for_node_startup, MakeVars}]),
742+
query_node(Config, NodeConfig1);
743+
_ ->
744+
AbortCmd = ["stop-node" | MakeVars],
745+
_ = rabbit_ct_helpers:exec([RunCmd | AbortCmd]),
746+
{skip, "Failed to initialize RabbitMQ"}
747+
end
726748
end.
727749

728750
query_node(Config, NodeConfig) ->
@@ -953,7 +975,12 @@ stop_rabbitmq_node(Config, NodeConfig) ->
953975
{"RABBITMQ_NODENAME_FOR_PATHS=~s", [InitialNodename]}
954976
],
955977
Cmd = ["stop-node" | MakeVars],
956-
rabbit_ct_helpers:make(Config, SrcDir, Cmd),
978+
case rabbit_ct_helpers:get_config(Config, rabbitmq_run_cmd) of
979+
undefined ->
980+
rabbit_ct_helpers:make(Config, SrcDir, Cmd);
981+
RunCmd ->
982+
rabbit_ct_helpers:exec([RunCmd | Cmd])
983+
end,
957984
NodeConfig.
958985

959986
%% -------------------------------------------------------------------

src/rabbit_ct_helpers.erl

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ensure_application_srcdir/4,
2222
ensure_rabbitmqctl_cmd/1,
2323
ensure_rabbitmqctl_app/1,
24+
load_rabbitmqctl_app/1,
2425
ensure_rabbitmq_plugins_cmd/1,
2526
ensure_rabbitmq_queues_cmd/1,
2627
start_long_running_testsuite_monitor/1,
@@ -67,24 +68,40 @@ run_setup_steps(Config) ->
6768
run_setup_steps(Config, []).
6869

6970
run_setup_steps(Config, ExtraSteps) ->
70-
Steps = [
71-
fun init_skip_as_error_flag/1,
72-
fun guess_tested_erlang_app_name/1,
73-
fun ensure_secondary_umbrella/1,
74-
fun ensure_current_srcdir/1,
75-
fun ensure_rabbitmq_ct_helpers_srcdir/1,
76-
fun ensure_erlang_mk_depsdir/1,
77-
fun ensure_secondary_erlang_mk_depsdir/1,
78-
fun ensure_secondary_current_srcdir/1,
79-
fun ensure_rabbit_common_srcdir/1,
80-
fun ensure_rabbitmq_cli_srcdir/1,
81-
fun ensure_rabbit_srcdir/1,
82-
fun ensure_make_cmd/1,
83-
fun ensure_erl_call_cmd/1,
84-
fun ensure_ssl_certs/1,
85-
fun start_long_running_testsuite_monitor/1,
86-
fun load_elixir/1
87-
],
71+
Steps = case os:getenv("RABBITMQ_RUN") of
72+
false ->
73+
[
74+
fun init_skip_as_error_flag/1,
75+
fun guess_tested_erlang_app_name/1,
76+
fun ensure_secondary_umbrella/1,
77+
fun ensure_current_srcdir/1,
78+
fun ensure_rabbitmq_ct_helpers_srcdir/1,
79+
fun ensure_erlang_mk_depsdir/1,
80+
fun ensure_secondary_erlang_mk_depsdir/1,
81+
fun ensure_secondary_current_srcdir/1,
82+
fun ensure_rabbit_common_srcdir/1,
83+
fun ensure_rabbitmq_cli_srcdir/1,
84+
fun ensure_rabbit_srcdir/1,
85+
fun ensure_make_cmd/1,
86+
fun ensure_erl_call_cmd/1,
87+
fun ensure_ssl_certs/1,
88+
fun start_long_running_testsuite_monitor/1,
89+
fun load_elixir/1
90+
];
91+
_ ->
92+
[
93+
fun init_skip_as_error_flag/1,
94+
% fun guess_tested_erlang_app_name/1,
95+
fun ensure_secondary_umbrella/1,
96+
fun ensure_current_srcdir/1,
97+
fun ensure_rabbitmq_ct_helpers_srcdir/1,
98+
% fun ensure_rabbit_srcdir/1,
99+
fun ensure_make_cmd/1,
100+
fun ensure_rabbitmq_run_cmd/1,
101+
fun ensure_ssl_certs/1,
102+
fun start_long_running_testsuite_monitor/1
103+
]
104+
end,
88105
run_steps(Config, Steps ++ ExtraSteps).
89106

90107
run_teardown_steps(Config) ->
@@ -117,8 +134,14 @@ run_steps(Config, [Step | Rest]) ->
117134
{skip, _} = Error ->
118135
run_teardown_steps(Config),
119136
Error;
120-
Config1 ->
121-
run_steps(Config1, Rest)
137+
Config1 when is_list(Config1) ->
138+
run_steps(Config1, Rest);
139+
Other ->
140+
ct:pal(?LOW_IMPORTANCE,
141+
"~p:~p/~p failed with ~p steps remaining (Config value ~p is not a proplist)",
142+
[?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY, length(Rest), Other]),
143+
run_teardown_steps(Config),
144+
exit("A setup step returned a non-proplist")
122145
end;
123146
run_steps(Config, []) ->
124147
Config.
@@ -137,7 +160,8 @@ init_skip_as_error_flag(Config) ->
137160
guess_tested_erlang_app_name(Config) ->
138161
case os:getenv("DIALYZER_PLT") of
139162
false ->
140-
ok;
163+
{skip,
164+
"plt file required, please set DIALYZER_PLT"};
141165
Filename ->
142166
AppName0 = filename:basename(Filename, ".plt"),
143167
AppName = string:strip(AppName0, left, $.),
@@ -328,6 +352,16 @@ ensure_make_cmd(Config) ->
328352
"please set MAKE or 'make_cmd' in ct config"}
329353
end.
330354

355+
ensure_rabbitmq_run_cmd(Config) ->
356+
case os:getenv("RABBITMQ_RUN") of
357+
false ->
358+
{skip,
359+
"Bazel helper rabbitmq-run required, " ++
360+
"please set RABBITMQ_RUN"};
361+
P ->
362+
set_config(Config, {rabbitmq_run_cmd, P})
363+
end.
364+
331365
ensure_erl_call_cmd(Config) ->
332366
ErlCallDir = code:lib_dir(erl_interface, bin),
333367
ErlCall = filename:join(ErlCallDir, "erl_call"),
@@ -419,6 +453,17 @@ ensure_rabbitmqctl_app(Config) ->
419453
"please build rabbitmq_cli and set MIX_ENV"}
420454
end.
421455

456+
load_rabbitmqctl_app(Config) ->
457+
case application:load(rabbitmqctl) of
458+
ok ->
459+
Config;
460+
{error, {already_loaded, rabbitmqctl}} ->
461+
Config;
462+
{error, _} ->
463+
{skip, "Application rabbitmqctl could not be loaded, " ++
464+
"please place compiled rabbitmq_cli on the code path"}
465+
end.
466+
422467
ensure_rabbitmq_plugins_cmd(Config) ->
423468
Rabbitmqplugins = case get_config(Config, rabbitmq_plugins_cmd) of
424469
undefined ->

tools/tls-certs/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
exports_files([
2+
"Makefile",
3+
"openssl.cnf.in",
4+
])

0 commit comments

Comments
 (0)