Skip to content

Commit fd5af14

Browse files
Merge pull request #5947 from rabbitmq/mergify/bp/v3.10.x/pr-5946
2 parents 3a526e5 + 1612f46 commit fd5af14

File tree

3 files changed

+91
-28
lines changed

3 files changed

+91
-28
lines changed

deps/rabbitmq_amqp1_0/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ suites = [
8080
PACKAGE,
8181
name = "command_SUITE",
8282
size = "medium",
83+
runtime_deps = [
84+
"//deps/amqp10_client:erlang_app",
85+
],
8386
deps = [
8487
"//deps/amqp10_common:erlang_app",
8588
],

tools/BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
load(":erlang_ls.bzl", "erlang_ls_config")
1+
load("//:rabbitmq.bzl", "all_plugins")
2+
load(":erlang_ls.bzl", "erlang_ls_config", "erlang_ls_tree")
3+
4+
erlang_ls_tree(
5+
name = "erlang_ls_files",
6+
apps = all_plugins(
7+
rabbitmq_workspace = "",
8+
),
9+
)
210

311
erlang_ls_config(
412
name = "erlang_ls.config",

tools/erlang_ls.bzl

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,93 @@
11
load(
2-
"@rules_erlang//tools:erlang_toolchain.bzl",
3-
"erlang_dirs",
2+
"@rules_erlang//:erlang_app_info.bzl",
3+
"ErlangAppInfo",
4+
)
5+
load(
6+
"@rules_erlang//:util.bzl",
7+
"path_join",
8+
)
9+
load(
10+
"@rules_erlang//private:util.bzl",
11+
"additional_file_dest_relative_path",
412
)
513

6-
def _impl(ctx):
7-
out = ctx.actions.declare_file(ctx.label.name)
8-
9-
(erlang_home, _, _) = erlang_dirs(ctx)
14+
def _erlang_ls_config(ctx):
15+
runtime_prefix = path_join(
16+
ctx.bin_dir.path,
17+
ctx.label.package,
18+
ctx.label.name + ".runfiles",
19+
ctx.workspace_name,
20+
)
1021

1122
ctx.actions.write(
12-
output = out,
13-
content = """otp_path: {erlang_home}
23+
output = ctx.outputs.executable,
24+
content = """#!/usr/bin/env bash
25+
26+
set -euo pipefail
27+
28+
BAZEL_OUT_ABSOLUTE_PATH="${{PWD%/{}}}/bazel-out"
29+
30+
cat << EOF
1431
apps_dirs:
15-
- deps/*
16-
- deps/rabbit/apps/*
32+
- ${{BAZEL_OUT_ABSOLUTE_PATH}}/*/bin/tools/erlang_ls_files/apps/*
1733
deps_dirs:
18-
- bazel-bin/external/*
34+
- ${{BAZEL_OUT_ABSOLUTE_PATH}}/*/bin/tools/erlang_ls_files/deps/*
1935
include_dirs:
20-
- deps
21-
- deps/*
22-
- deps/*/include
23-
- deps/*/src
24-
- bazel-bin/external
25-
- bazel-bin/external/*/include
26-
plt_path: bazel-bin/deps/rabbit/.base_plt.plt
27-
""".format(
28-
erlang_home = erlang_home,
29-
),
36+
- ${{BAZEL_OUT_ABSOLUTE_PATH}}/*/bin/tools/erlang_ls_files/apps
37+
- ${{BAZEL_OUT_ABSOLUTE_PATH}}/*/bin/tools/erlang_ls_files/apps/*/include
38+
- ${{BAZEL_OUT_ABSOLUTE_PATH}}/*/bin/tools/erlang_ls_files/deps
39+
- ${{BAZEL_OUT_ABSOLUTE_PATH}}/*/bin/tools/erlang_ls_files/deps/*/include
40+
EOF
41+
""".format(runtime_prefix),
3042
)
3143

44+
erlang_ls_config = rule(
45+
implementation = _erlang_ls_config,
46+
executable = True,
47+
)
48+
49+
def _erlang_app_files(ctx, app, directory):
50+
app_info = app[ErlangAppInfo]
51+
app_path = path_join(directory, app_info.app_name)
52+
files = []
53+
for f in app_info.srcs + app_info.beam:
54+
relative_path = additional_file_dest_relative_path(app.label, f)
55+
dest = ctx.actions.declare_file(path_join(app_path, relative_path))
56+
ctx.actions.symlink(output = dest, target_file = f)
57+
files.append(dest)
58+
return files
59+
60+
def _erlang_ls_tree(ctx):
61+
apps = ctx.attr.apps
62+
deps = []
63+
64+
for app in apps:
65+
app_info = app[ErlangAppInfo]
66+
for dep in app_info.deps:
67+
# this puts non rabbitmq plugins, like amqp10_client into deps,
68+
# but maybe those should be in apps? Does it matter?
69+
if dep not in deps and dep not in apps:
70+
deps.append(dep)
71+
72+
files = []
73+
for app in apps:
74+
files.extend(
75+
_erlang_app_files(ctx, app, path_join(ctx.label.name, "apps")),
76+
)
77+
for dep in deps:
78+
files.extend(
79+
_erlang_app_files(ctx, dep, path_join(ctx.label.name, "deps")),
80+
)
81+
3282
return [
33-
DefaultInfo(files = depset([out])),
83+
DefaultInfo(files = depset(files)),
3484
]
3585

36-
erlang_ls_config = rule(
37-
implementation = _impl,
38-
toolchains = [
39-
"@rules_erlang//tools:toolchain_type",
40-
],
86+
erlang_ls_tree = rule(
87+
implementation = _erlang_ls_tree,
88+
attrs = {
89+
"apps": attr.label_list(
90+
providers = [ErlangAppInfo],
91+
),
92+
},
4193
)

0 commit comments

Comments
 (0)