Skip to content

Commit

Permalink
Turn the //tools:erlang_ls.config target into a generation script
Browse files Browse the repository at this point in the history
So that one can `bazel run tools:erlang_ls.config > erlang_ls.config`
to generate a bazel friendly config
  • Loading branch information
HoloRin committed Sep 30, 2022
1 parent ec337d0 commit 25ed859
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions tools/erlang_ls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ load(
"@rules_erlang//:erlang_app_info.bzl",
"ErlangAppInfo",
)
load(
"@rules_erlang//tools:erlang_toolchain.bzl",
"erlang_dirs",
)
load(
"@rules_erlang//:util.bzl",
"path_join",
Expand All @@ -16,40 +12,37 @@ load(
)

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

(erlang_home, _, _) = erlang_dirs(ctx)
runtime_prefix = path_join(
ctx.label.package,
ctx.label.name + ".runfiles",
ctx.workspace_name,
)

ctx.actions.write(
output = out,
content = """otp_path: {erlang_home}
output = ctx.outputs.executable,
content = """#!/usr/bin/env bash
set -euo pipefail
BAZEL_BIN_ABSOLUTE_PATH="${{PWD%/{}}}"
cat << EOF
apps_dirs:
- deps/*
- deps/rabbit/apps/*
- ${{BAZEL_BIN_ABSOLUTE_PATH}}/tools/erlang_ls_files/apps/*
deps_dirs:
- bazel-bin/external/*
- ${{BAZEL_BIN_ABSOLUTE_PATH}}/tools/erlang_ls_files/deps/*
include_dirs:
- deps
- deps/*
- deps/*/include
- deps/*/src
- bazel-bin/external
- bazel-bin/external/*/include
plt_path: bazel-bin/deps/rabbit/.base_plt.plt
""".format(
erlang_home = erlang_home,
),
- ${{BAZEL_BIN_ABSOLUTE_PATH}}/tools/erlang_ls_files/apps
- ${{BAZEL_BIN_ABSOLUTE_PATH}}/tools/erlang_ls_files/apps/*/include
- ${{BAZEL_BIN_ABSOLUTE_PATH}}/tools/erlang_ls_files/deps
- ${{BAZEL_BIN_ABSOLUTE_PATH}}/tools/erlang_ls_files/deps/*/include
EOF
""".format(runtime_prefix),
)

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

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

def _erlang_app_files(ctx, app, directory):
Expand Down

0 comments on commit 25ed859

Please sign in to comment.