Add "bazel run //tools:symlink_deps_for_erlang_ls"

for symlinking 3rd party deps into a place that erlang_ls can use them
This commit is contained in:
Rin Kuryloski 2023-01-05 12:41:07 +01:00
parent 06a330f553
commit a8658ae68d
5 changed files with 46 additions and 38 deletions

View File

@ -3,3 +3,4 @@
.erlang.mk
deps/osiris
deps/ra
extra_deps

1
.gitignore vendored
View File

@ -89,6 +89,7 @@ callgrand*
/user.bazelrc
/bazel-*
/extra_deps/
.vscode
.idea

View File

@ -4,6 +4,7 @@
deps_dirs:
- "deps/*"
- "deps/*/apps/*"
- "extra_deps/*"
diagnostics:
disabled:
- bound_var_in_pattern
@ -16,6 +17,7 @@ diagnostics:
include_dirs:
- "deps"
- "deps/*/include"
- "extra_deps/*/include"
lenses:
enabled:
- ct-run-test

View File

@ -1,16 +1,18 @@
load("//:rabbitmq.bzl", "all_plugins")
load(":erlang_ls.bzl", "erlang_ls_config", "erlang_ls_tree")
load(":erlang_ls.bzl", "deps_symlinks", "erlang_ls_config")
erlang_ls_tree(
name = "erlang_ls_files",
erlang_ls_config(
name = "erlang_ls.config",
)
deps_symlinks(
name = "symlink_deps_for_erlang_ls",
apps = all_plugins(
rabbitmq_workspace = "",
) + [
"//deps/rabbitmq_ct_helpers:erlang_app",
"//deps/rabbitmq_ct_client_helpers:erlang_app",
],
)
erlang_ls_config(
name = "erlang_ls.config",
dest = "extra_deps", # must also be listed in .bazelignore
tags = ["local"],
)

View File

@ -6,10 +6,6 @@ load(
"@rules_erlang//:util.bzl",
"path_join",
)
load(
"@rules_erlang//private:util.bzl",
"additional_file_dest_relative_path",
)
def _erlang_ls_config(ctx):
runtime_prefix = path_join(
@ -46,48 +42,54 @@ erlang_ls_config = rule(
executable = True,
)
def _erlang_app_files(ctx, app, directory):
app_info = app[ErlangAppInfo]
app_path = path_join(directory, app_info.app_name)
files = []
for f in app_info.srcs + app_info.beam:
relative_path = additional_file_dest_relative_path(app.label, f)
dest = ctx.actions.declare_file(path_join(app_path, relative_path))
ctx.actions.symlink(output = dest, target_file = f)
files.append(dest)
return files
def _erlang_ls_tree(ctx):
def _deps_symlinks(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:
if dep.label.workspace_name != "" and 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")),
)
output = ctx.actions.declare_file(ctx.label.name + ".sh")
return [
DefaultInfo(files = depset(files)),
commands = [
"set -euxo pipefail",
"",
"mkdir -p \"{}\"".format(path_join("$BUILD_WORKSPACE_DIRECTORY", ctx.attr.dest)),
"",
]
erlang_ls_tree = rule(
implementation = _erlang_ls_tree,
for dep in deps:
app_info = dep[ErlangAppInfo]
files.extend(app_info.srcs)
commands.append("ln -s \"{target}\" \"{source}\"".format(
target = path_join("$PWD", "external", dep.label.workspace_name),
source = path_join("$BUILD_WORKSPACE_DIRECTORY", ctx.attr.dest, app_info.app_name),
))
ctx.actions.write(
output = output,
content = "\n".join(commands),
)
return [DefaultInfo(
runfiles = ctx.runfiles(files = files),
executable = output,
)]
deps_symlinks = rule(
implementation = _deps_symlinks,
attrs = {
"apps": attr.label_list(
providers = [ErlangAppInfo],
),
"dest": attr.string(
mandatory = True,
),
},
executable = True,
)