Skip to content

Commit

Permalink
Add //tools:erlang_ls_files that generates a tree for Erlang LS
Browse files Browse the repository at this point in the history
in the layout Erlang LS expects
  • Loading branch information
HoloRin committed Sep 30, 2022
1 parent 1639e3a commit 41a13e4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
6 changes: 3 additions & 3 deletions deps/rabbitmq_amqp1_0/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ suites = [
PACKAGE,
name = "command_SUITE",
size = "medium",
deps = [
"//deps/amqp10_common:erlang_app",
],
runtime_deps = [
"//deps/amqp10_client:erlang_app",
],
deps = [
"//deps/amqp10_common:erlang_app",
],
),
rabbitmq_integration_suite(
PACKAGE,
Expand Down
10 changes: 9 additions & 1 deletion tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
load(":erlang_ls.bzl", "erlang_ls_config")
load("//:rabbitmq.bzl", "all_plugins")
load(":erlang_ls.bzl", "erlang_ls_config", "erlang_ls_tree")

erlang_ls_tree(
name = "erlang_ls_files",
apps = all_plugins(
rabbitmq_workspace = "",
),
)

erlang_ls_config(
name = "erlang_ls.config",
Expand Down
62 changes: 60 additions & 2 deletions tools/erlang_ls.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
load(
"@rules_erlang//:erlang_app_info.bzl",
"ErlangAppInfo",
)
load(
"@rules_erlang//tools:erlang_toolchain.bzl",
"erlang_dirs",
)
load(
"@rules_erlang//:util.bzl",
"path_join",
)
load(
"@rules_erlang//private:util.bzl",
"additional_file_dest_relative_path",
)

def _impl(ctx):
def _erlang_ls_config(ctx):
out = ctx.actions.declare_file(ctx.label.name)

(erlang_home, _, _) = erlang_dirs(ctx)
Expand Down Expand Up @@ -34,8 +46,54 @@ plt_path: bazel-bin/deps/rabbit/.base_plt.plt
]

erlang_ls_config = rule(
implementation = _impl,
implementation = _erlang_ls_config,
toolchains = [
"@rules_erlang//tools:toolchain_type",
],
)

def _erlang_app_files(ctx, app, directory):
app_info = app[ErlangAppInfo]
app_path = path_join(directory, app_info.app_name)
files = []
for hdr in app_info.srcs + app_info.beam:
rp = additional_file_dest_relative_path(app.label, hdr)
dest = ctx.actions.declare_file(path_join(app_path, rp))
ctx.actions.symlink(output = dest, target_file = hdr)
files.append(dest)
return files

def _erlang_ls_tree(ctx):
apps = ctx.attr.apps
deps = []

for app in apps:
app_info = app[ErlangAppInfo]
for dep in app_info.deps:
# this puts non rabbitmq plugins, like amqp10_client into deps,
# but maybe those should be in apps? Does it matter?
if dep not in deps and dep not in apps:
deps.append(dep)

files = []
for app in apps:
files.extend(
_erlang_app_files(ctx, app, path_join(ctx.label.name, "apps")),
)
for dep in deps:
files.extend(
_erlang_app_files(ctx, dep, path_join(ctx.label.name, "deps")),
)

return [
DefaultInfo(files = depset(files)),
]

erlang_ls_tree = rule(
implementation = _erlang_ls_tree,
attrs = {
"apps": attr.label_list(
providers = [ErlangAppInfo],
),
},
)

0 comments on commit 41a13e4

Please sign in to comment.