Skip to content

Commit c7d98a5

Browse files
Merge pull request #8151 from rabbitmq/mergify/bp/v3.12.x/pr-8148
rabbitmq_cli dialyze enhancements (backport #8148)
2 parents d0a9c9f + 9a747c9 commit c7d98a5

File tree

13 files changed

+144
-53
lines changed

13 files changed

+144
-53
lines changed

.github/workflows/test-mixed-versions.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ jobs:
135135
uses: actions/[email protected]
136136
with:
137137
path: "/home/runner/repo-cache/"
138-
key: repo-cache
138+
key: ${{ runner.os }}-repo-cache-${{ hashFiles('MODULE.bazel','WORKSPACE','bazel/bzlmod/secondary_umbrella.bzl') }}
139+
restore-keys: |
140+
${{ runner.os }}-repo-cache-
139141
- name: CONFIGURE BAZEL
140142
run: |
141143
if [ -n "${{ secrets.BUILDBUDDY_API_KEY }}" ]; then
@@ -183,7 +185,9 @@ jobs:
183185
uses: actions/[email protected]
184186
with:
185187
path: "/home/runner/repo-cache/"
186-
key: repo-cache
188+
key: ${{ runner.os }}-repo-cache-${{ hashFiles('MODULE.bazel','WORKSPACE','bazel/bzlmod/secondary_umbrella.bzl') }}
189+
restore-keys: |
190+
${{ runner.os }}-repo-cache-
187191
- name: CONFIGURE BAZEL
188192
run: |
189193
ERLANG_HOME="$(dirname $(dirname $(which erl)))"

.github/workflows/test-selenium.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ jobs:
5050
uses: actions/[email protected]
5151
with:
5252
path: "/home/runner/repo-cache/"
53-
key: repo-cache
53+
key: ${{ runner.os }}-repo-cache-${{ hashFiles('MODULE.bazel','WORKSPACE','bazel/bzlmod/secondary_umbrella.bzl') }}
54+
restore-keys: |
55+
${{ runner.os }}-repo-cache-
5456
5557
- name: Configure Bazel
5658
run: |

.github/workflows/test.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ jobs:
4444
uses: actions/[email protected]
4545
with:
4646
path: "/home/runner/repo-cache/"
47-
key: repo-cache
47+
key: ${{ runner.os }}-repo-cache-${{ hashFiles('MODULE.bazel','WORKSPACE','bazel/bzlmod/secondary_umbrella.bzl') }}
48+
restore-keys: |
49+
${{ runner.os }}-repo-cache-
4850
- name: CONFIGURE BAZEL
4951
run: |
5052
if [ -n "${{ secrets.BUILDBUDDY_API_KEY }}" ]; then
@@ -96,7 +98,9 @@ jobs:
9698
uses: actions/[email protected]
9799
with:
98100
path: "/home/runner/repo-cache/"
99-
key: repo-cache
101+
key: ${{ runner.os }}-repo-cache-${{ hashFiles('MODULE.bazel','WORKSPACE','bazel/bzlmod/secondary_umbrella.bzl') }}
102+
restore-keys: |
103+
${{ runner.os }}-repo-cache-
100104
- name: CONFIGURE BAZEL
101105
run: |
102106
ERLANG_HOME="$(dirname $(dirname $(which erl)))"

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"bool_flag",
44
"string_flag",
55
)
6-
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
6+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
77
load("@bazel_gazelle//:def.bzl", "gazelle")
88
load("@rules_erlang//gazelle:def.bzl", "GAZELLE_ERLANG_RUNTIME_DEPS")
99
load("@rules_erlang//:erlang_bytecode2.bzl", "erlc_opts")

MODULE.bazel

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module(
55

66
bazel_dep(
77
name = "rules_pkg",
8-
version = "0.5.1",
8+
version = "0.9.1",
99
)
1010

1111
bazel_dep(
@@ -31,7 +31,7 @@ bazel_dep(
3131

3232
bazel_dep(
3333
name = "rules_erlang",
34-
version = "3.9.14",
34+
version = "3.10.0",
3535
)
3636

3737
erlang_config = use_extension(
@@ -110,20 +110,20 @@ use_repo(
110110
)
111111

112112
register_toolchains(
113-
"@erlang_config//24:toolchain",
114-
"@erlang_config//24:toolchain2",
115-
"@erlang_config//25_0:toolchain",
116-
"@erlang_config//25_0:toolchain2",
117-
"@erlang_config//25_1:toolchain",
118-
"@erlang_config//25_1:toolchain2",
119-
"@erlang_config//25_2:toolchain",
120-
"@erlang_config//25_2:toolchain2",
121-
"@erlang_config//25_3:toolchain",
122-
"@erlang_config//25_3:toolchain2",
123-
"@erlang_config//26:toolchain",
124-
"@erlang_config//26:toolchain2",
125-
"@erlang_config//git_master:toolchain",
126-
"@erlang_config//git_master:toolchain2",
113+
"@erlang_config//24:toolchain_major",
114+
"@erlang_config//24:toolchain_major_minor",
115+
"@erlang_config//25_0:toolchain_major",
116+
"@erlang_config//25_0:toolchain_major_minor",
117+
"@erlang_config//25_1:toolchain_major",
118+
"@erlang_config//25_1:toolchain_major_minor",
119+
"@erlang_config//25_2:toolchain_major",
120+
"@erlang_config//25_2:toolchain_major_minor",
121+
"@erlang_config//25_3:toolchain_major",
122+
"@erlang_config//25_3:toolchain_major_minor",
123+
"@erlang_config//26:toolchain_major",
124+
"@erlang_config//26:toolchain_major_minor",
125+
"@erlang_config//git_master:toolchain_major",
126+
"@erlang_config//git_master:toolchain_major_minor",
127127
"@elixir_config//external:toolchain",
128128
"@elixir_config//1_13:toolchain",
129129
"@elixir_config//1_14:toolchain",

WORKSPACE

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ workspace(name = "rabbitmq-server")
33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
44
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
55

6+
http_archive(
7+
name = "rules_pkg",
8+
urls = [
9+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
10+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
11+
],
12+
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
13+
)
14+
15+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
16+
17+
rules_pkg_dependencies()
18+
619
git_repository(
720
name = "rules_erlang",
821
remote = "https://github.com/rabbitmq/rules_erlang.git",
9-
tag = "3.9.14",
22+
tag = "3.10.0",
1023
)
1124

1225
load("@rules_erlang//:internal_deps.bzl", "rules_erlang_internal_deps")

bazel/elixir/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ elixir_as_app(
1212
name = "erlang_app",
1313
visibility = ["//visibility:public"],
1414
)
15+
16+
elixir_as_app(
17+
name = "logger",
18+
app = "logger",
19+
visibility = ["//visibility:public"],
20+
)
21+
22+
elixir_as_app(
23+
name = "iex",
24+
app = "iex",
25+
visibility = ["//visibility:public"],
26+
)

bazel/elixir/elixir_as_app.bzl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ load(
22
"@rules_erlang//:erlang_app_info.bzl",
33
"ErlangAppInfo",
44
)
5+
load(
6+
"@rules_erlang//:util.bzl",
7+
"path_join",
8+
)
59
load(
610
":elixir_toolchain.bzl",
711
"elixir_dirs",
812
)
913

1014
def _impl(ctx):
11-
ebin = ctx.actions.declare_directory("ebin")
15+
ebin = ctx.actions.declare_directory(path_join(ctx.label.name, "ebin"))
1216

1317
(elixir_home, elixir_runfiles) = elixir_dirs(ctx)
1418

@@ -17,17 +21,18 @@ def _impl(ctx):
1721
outputs = [ebin],
1822
command = """set -euo pipefail
1923
20-
cp -r "{elixir_home}"/lib/elixir/ebin/* {ebin}
24+
cp -r "{elixir_home}"/lib/{app}/ebin/* {ebin}
2125
""".format(
2226
elixir_home = elixir_home,
27+
app = ctx.attr.app,
2328
ebin = ebin.path,
2429
),
2530
)
2631

2732
return [
2833
DefaultInfo(files = depset([ebin])),
2934
ErlangAppInfo(
30-
app_name = "elixir",
35+
app_name = ctx.attr.app,
3136
include = [],
3237
beam = [ebin],
3338
priv = [],
@@ -39,6 +44,9 @@ cp -r "{elixir_home}"/lib/elixir/ebin/* {ebin}
3944

4045
elixir_as_app = rule(
4146
implementation = _impl,
47+
attrs = {
48+
"app": attr.string(default = "elixir"),
49+
},
4250
toolchains = [":toolchain_type"],
4351
provides = [ErlangAppInfo],
4452
)

bazel/elixir/mix_archive_build.bzl

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
load(
2-
"@rules_erlang//:util.bzl",
3-
"path_join",
4-
)
1+
load("@bazel_skylib//lib:shell.bzl", "shell")
52
load(
63
"@rules_erlang//private:util.bzl",
74
"additional_file_dest_relative_path",
@@ -20,24 +17,20 @@ def _impl(ctx):
2017
out = ctx.actions.declare_file(ctx.attr.out.name)
2118
mix_invocation_dir = ctx.actions.declare_directory("{}_mix".format(ctx.label.name))
2219

23-
package_dir = path_join(
24-
ctx.label.workspace_root,
25-
ctx.label.package,
26-
)
27-
2820
copy_srcs_commands = []
29-
for src in ctx.files.srcs:
30-
dest = additional_file_dest_relative_path(ctx.label, src)
31-
copy_srcs_commands.extend([
32-
'mkdir -p "$(dirname ${{MIX_INVOCATION_DIR}}/{dest})"'.format(
33-
dest = dest,
34-
),
35-
'cp {flags}"{src}" "${{MIX_INVOCATION_DIR}}/{dest}"'.format(
36-
flags = "-r " if src.is_directory else "",
37-
src = src.path,
38-
dest = dest,
39-
),
40-
])
21+
for src in ctx.attr.srcs:
22+
for src_file in src[DefaultInfo].files.to_list():
23+
dest = additional_file_dest_relative_path(src.label, src_file)
24+
copy_srcs_commands.extend([
25+
'mkdir -p "$(dirname ${{MIX_INVOCATION_DIR}}/{dest})"'.format(
26+
dest = dest,
27+
),
28+
'cp {flags}"{src}" "${{MIX_INVOCATION_DIR}}/{dest}"'.format(
29+
flags = "-r " if src_file.is_directory else "",
30+
src = src_file.path,
31+
dest = dest,
32+
),
33+
])
4134

4235
script = """set -euo pipefail
4336
@@ -60,11 +53,23 @@ MIX_INVOCATION_DIR="{mix_invocation_dir}"
6053
6154
{copy_srcs_commands}
6255
56+
ORIGINAL_DIR=$PWD
6357
cd "${{MIX_INVOCATION_DIR}}"
6458
export HOME="${{PWD}}"
6559
export MIX_ENV=prod
6660
export ERL_COMPILER_OPTIONS=deterministic
67-
"${{ABS_ELIXIR_HOME}}"/bin/mix archive.build -o "${{ABS_OUT_PATH}}"
61+
for archive in {archives}; do
62+
"${{ABS_ELIXIR_HOME}}"/bin/mix archive.install --force $ORIGINAL_DIR/$archive
63+
done
64+
if [[ -n "{ez_deps}" ]]; then
65+
mkdir -p _build/${{MIX_ENV}}/lib
66+
for ez_dep in {ez_deps}; do
67+
unzip -q $ORIGINAL_DIR/$ez_dep -d _build/${{MIX_ENV}}/lib
68+
done
69+
fi
70+
"${{ABS_ELIXIR_HOME}}"/bin/mix archive.build \\
71+
--no-deps-check \\
72+
-o "${{ABS_OUT_PATH}}"
6873
6974
# remove symlinks from the _build directory since it
7075
# is an unused output, and bazel does not allow them
@@ -75,7 +80,8 @@ find . -type l -delete
7580
elixir_home = elixir_home,
7681
mix_invocation_dir = mix_invocation_dir.path,
7782
copy_srcs_commands = "\n".join(copy_srcs_commands),
78-
package_dir = package_dir,
83+
archives = " ".join([shell.quote(a.path) for a in ctx.files.archives]),
84+
ez_deps = " ".join([shell.quote(a.path) for a in ctx.files.ez_deps]),
7985
out = out.path,
8086
)
8187

@@ -84,6 +90,8 @@ find . -type l -delete
8490
transitive = [
8591
erlang_runfiles.files,
8692
elixir_runfiles.files,
93+
depset(ctx.files.archives),
94+
depset(ctx.files.ez_deps),
8795
],
8896
)
8997

@@ -110,6 +118,12 @@ mix_archive_build = rule(
110118
mandatory = True,
111119
allow_files = True,
112120
),
121+
"archives": attr.label_list(
122+
allow_files = [".ez"],
123+
),
124+
"ez_deps": attr.label_list(
125+
allow_files = [".ez"],
126+
),
113127
"out": attr.output(),
114128
},
115129
toolchains = [

deps/rabbitmq_cli/BUILD.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@ load(":rabbitmqctl_test.bzl", "rabbitmqctl_test")
55
load("//:rabbitmq_home.bzl", "rabbitmq_home")
66
load("//:rabbitmq_run.bzl", "rabbitmq_run")
77
load("//:rabbitmq.bzl", "RABBITMQ_DIALYZER_OPTS", "STARTS_BACKGROUND_BROKER_TAG", "without")
8+
load(
9+
"@rabbitmq-server//bazel/elixir:mix_archive_build.bzl",
10+
"mix_archive_build",
11+
)
12+
13+
mix_archive_build(
14+
name = "parallel_stream_ez",
15+
srcs = ["@parallel_stream//:sources"],
16+
archives = ["@hex//:archive"],
17+
out = "parallel_stream.ez",
18+
)
19+
20+
mix_archive_build(
21+
name = "csv_ez",
22+
srcs = ["@csv//:sources"],
23+
archives = ["@hex//:archive"],
24+
ez_deps = [
25+
":parallel_stream_ez",
26+
],
27+
out = "csv.ez",
28+
)
29+
30+
mix_archive_build(
31+
name = "json_ez",
32+
srcs = ["@json//:sources"],
33+
archives = ["@hex//:archive"],
34+
out = "json.ez",
35+
)
836

937
# Note: All the various rabbitmq-* scripts are just copies of rabbitmqctl
1038
rabbitmqctl(
@@ -88,9 +116,15 @@ plt(
88116
libs = [":elixir"],
89117
deps = [
90118
":elixir",
119+
"//bazel/elixir:logger",
91120
"//deps/rabbit:erlang_app",
92121
"//deps/rabbit_common:erlang_app",
93122
],
123+
ez_deps = [
124+
":parallel_stream_ez",
125+
":csv_ez",
126+
":json_ez",
127+
],
94128
)
95129

96130
dialyze(

0 commit comments

Comments
 (0)