From 25ed8595c34e2bd167de7b502d11ceef91f5f056 Mon Sep 17 00:00:00 2001 From: Rin Kuryloski Date: Fri, 30 Sep 2022 13:39:25 +0200 Subject: [PATCH] Turn the //tools:erlang_ls.config target into a generation script So that one can `bazel run tools:erlang_ls.config > erlang_ls.config` to generate a bazel friendly config --- tools/erlang_ls.bzl | 51 +++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/tools/erlang_ls.bzl b/tools/erlang_ls.bzl index b1dc8bbd0292..670a338f5f3b 100644 --- a/tools/erlang_ls.bzl +++ b/tools/erlang_ls.bzl @@ -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", @@ -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):