rabbitmq-server/rabbitmq_home.bzl

182 lines
5.8 KiB
Python
Raw Normal View History

load("@rules_erlang//:erlang_app_info.bzl", "ErlangAppInfo", "flat_deps")
load("@rules_erlang//:util.bzl", "path_join")
load("@rules_erlang//:ct.bzl", "additional_file_dest_relative_path")
RabbitmqHomeInfo = provider(
doc = "An assembled RABBITMQ_HOME dir",
fields = {
"rabbitmqctl": "rabbitmqctl script from the sbin directory",
},
)
def _copy_script(ctx, script):
dest = ctx.actions.declare_file(
path_join(ctx.label.name, "sbin", script.basename),
)
ctx.actions.expand_template(
template = script,
output = dest,
substitutions = {},
is_executable = True,
)
return dest
def copy_escript(ctx, escript):
e = ctx.attr._rabbitmqctl_escript.files_to_run.executable
dest = ctx.actions.declare_file(
path_join(ctx.label.name, "escript", escript.basename),
)
ctx.actions.run(
inputs = [e],
outputs = [dest],
executable = "cp",
arguments = [e.path, dest.path],
)
return dest
def _plugins_dir_links(ctx, plugin):
lib_info = plugin[ErlangAppInfo]
plugin_path = path_join(
ctx.label.name,
"plugins",
lib_info.app_name,
)
links = []
for f in lib_info.include:
o = ctx.actions.declare_file(path_join(plugin_path, "include", f.basename))
ctx.actions.symlink(
output = o,
target_file = f,
)
links.append(o)
for f in lib_info.beam:
if f.is_directory:
if f.basename != "ebin":
fail("{} contains a directory in 'beam' that is not an ebin dir".format(lib_info.lib_name))
Use gazelle for some maintenance of bazel BUILD files (backport #6466) (backport #7931) (#7936) * Use gazelle generated bazel files Bazel build files are now maintained primarily with `bazel run gazelle`. This will analyze and merge changes into the build files as necessitated by certain code changes (e.g. the introduction of new modules). In some cases there hints to gazelle in the build files, such as `# gazelle:erlang...` or `# keep` comments. xref checks on plugins that depend on the cli are a good example. (cherry picked from commit 8de8f59d47ef00c077ec53ad7a0ee5610cfdf746) # Conflicts: # deps/rabbit/BUILD.bazel (cherry picked from commit 2aaf2176d413efe8dbd7e1f0be4b8535dc1951a0) # Conflicts: # BUILD.bazel # deps/amqp10_client/BUILD.bazel # deps/amqp_client/BUILD.bazel # deps/rabbit/BUILD.bazel # deps/rabbit/apps/rabbitmq_prelaunch/BUILD.bazel # deps/rabbit_common/BUILD.bazel # deps/rabbitmq_amqp1_0/BUILD.bazel # deps/rabbitmq_auth_backend_cache/BUILD.bazel # deps/rabbitmq_auth_backend_http/BUILD.bazel # deps/rabbitmq_auth_backend_ldap/BUILD.bazel # deps/rabbitmq_auth_backend_oauth2/BUILD.bazel # deps/rabbitmq_auth_mechanism_ssl/BUILD.bazel # deps/rabbitmq_aws/BUILD.bazel # deps/rabbitmq_consistent_hash_exchange/BUILD.bazel # deps/rabbitmq_ct_client_helpers/BUILD.bazel # deps/rabbitmq_ct_helpers/BUILD.bazel # deps/rabbitmq_event_exchange/BUILD.bazel # deps/rabbitmq_federation/BUILD.bazel # deps/rabbitmq_federation_management/BUILD.bazel # deps/rabbitmq_jms_topic_exchange/BUILD.bazel # deps/rabbitmq_management/BUILD.bazel # deps/rabbitmq_management_agent/BUILD.bazel # deps/rabbitmq_mqtt/BUILD.bazel # deps/rabbitmq_peer_discovery_aws/BUILD.bazel # deps/rabbitmq_peer_discovery_common/BUILD.bazel # deps/rabbitmq_peer_discovery_consul/BUILD.bazel # deps/rabbitmq_peer_discovery_etcd/BUILD.bazel # deps/rabbitmq_peer_discovery_k8s/BUILD.bazel # deps/rabbitmq_prometheus/BUILD.bazel # deps/rabbitmq_random_exchange/BUILD.bazel # deps/rabbitmq_recent_history_exchange/BUILD.bazel # deps/rabbitmq_sharding/BUILD.bazel # deps/rabbitmq_shovel/BUILD.bazel # deps/rabbitmq_shovel_management/BUILD.bazel # deps/rabbitmq_stomp/BUILD.bazel # deps/rabbitmq_stream/BUILD.bazel # deps/rabbitmq_stream_common/BUILD.bazel # deps/rabbitmq_stream_management/BUILD.bazel # deps/rabbitmq_top/BUILD.bazel # deps/rabbitmq_tracing/BUILD.bazel # deps/rabbitmq_trust_store/BUILD.bazel # deps/rabbitmq_web_dispatch/BUILD.bazel # deps/rabbitmq_web_mqtt/BUILD.bazel # deps/rabbitmq_web_mqtt_examples/BUILD.bazel # deps/rabbitmq_web_stomp/BUILD.bazel # deps/rabbitmq_web_stomp_examples/BUILD.bazel # rabbitmq.bzl * rabbit/BUILD.bazel: resolve conflicts, bazel run gazelle (cherry picked from commit c1c450b5dfad53689ede0f43632cea583a0ce3d1) * Resolve merge conflicts * Resolve merge conflicts: maybe expression * bazel run gazelle * Resolve conflicts: ignore_warnings not yet available on plt rule * Resolve more conflicts * Re-run `bazel run gazelle` * Delete non-existent suites * bazel run gazelle with pre-release gazelle * Ignore warnings for mqtt dialyze again as they were never fixed on this branch * Add missing test helpers * Run bazel run gazelle * Restore the original -include_lib statements from before #6466 since this broke erlang_ls requires rules_erlang 3.9.13 (cherry picked from commit 854d01d9a54b225681e2280b5efdcd12287e6fd3) --------- Co-authored-by: Rin Kuryloski <kuryloskip@vmware.com> Co-authored-by: Michael Klishin <michael@clojurewerkz.org>
2023-04-21 04:59:43 +08:00
o = ctx.actions.declare_directory(path_join(plugin_path, "ebin"))
else:
o = ctx.actions.declare_file(path_join(plugin_path, "ebin", f.basename))
ctx.actions.symlink(
output = o,
target_file = f,
)
links.append(o)
for f in lib_info.priv:
p = additional_file_dest_relative_path(plugin.label, f)
o = ctx.actions.declare_file(path_join(plugin_path, p))
ctx.actions.symlink(
output = o,
target_file = f,
)
links.append(o)
return links
def flatten(list_of_lists):
return [item for sublist in list_of_lists for item in sublist]
def _impl(ctx):
plugins = flat_deps(ctx.attr.plugins)
if not ctx.attr.is_windows:
source_scripts = ctx.files._scripts
else:
source_scripts = ctx.files._scripts_windows
scripts = [_copy_script(ctx, script) for script in source_scripts]
escripts = [copy_escript(ctx, escript) for escript in ctx.files._escripts]
plugins = flatten([_plugins_dir_links(ctx, plugin) for plugin in plugins])
rabbitmqctl = None
for script in scripts:
if script.basename == ("rabbitmqctl" if not ctx.attr.is_windows else "rabbitmqctl.bat"):
rabbitmqctl = script
if rabbitmqctl == None:
fail("could not find rabbitmqctl among", scripts)
return [
RabbitmqHomeInfo(
rabbitmqctl = rabbitmqctl,
),
DefaultInfo(
files = depset(scripts + escripts + plugins),
),
]
RABBITMQ_HOME_ATTRS = {
"_escripts": attr.label_list(
default = [
"//deps/rabbit:scripts/rabbitmq-diagnostics",
"//deps/rabbit:scripts/rabbitmq-plugins",
"//deps/rabbit:scripts/rabbitmq-queues",
"//deps/rabbit:scripts/rabbitmq-streams",
"//deps/rabbit:scripts/rabbitmq-upgrade",
"//deps/rabbit:scripts/rabbitmqctl",
"//deps/rabbit:scripts/vmware-rabbitmq",
],
allow_files = True,
),
"_scripts": attr.label_list(
default = [
"//deps/rabbit:scripts/rabbitmq-defaults",
"//deps/rabbit:scripts/rabbitmq-diagnostics",
"//deps/rabbit:scripts/rabbitmq-env",
"//deps/rabbit:scripts/rabbitmq-plugins",
"//deps/rabbit:scripts/rabbitmq-queues",
"//deps/rabbit:scripts/rabbitmq-server",
"//deps/rabbit:scripts/rabbitmq-streams",
"//deps/rabbit:scripts/rabbitmq-tanzu",
"//deps/rabbit:scripts/rabbitmq-upgrade",
"//deps/rabbit:scripts/rabbitmqctl",
"//deps/rabbit:scripts/vmware-rabbitmq",
],
allow_files = True,
),
"_scripts_windows": attr.label_list(
default = [
"//deps/rabbit:scripts/rabbitmq-defaults.bat",
"//deps/rabbit:scripts/rabbitmq-diagnostics.bat",
"//deps/rabbit:scripts/rabbitmq-env.bat",
"//deps/rabbit:scripts/rabbitmq-plugins.bat",
"//deps/rabbit:scripts/rabbitmq-queues.bat",
"//deps/rabbit:scripts/rabbitmq-server.bat",
"//deps/rabbit:scripts/rabbitmq-streams.bat",
"//deps/rabbit:scripts/rabbitmq-tanzu.bat",
"//deps/rabbit:scripts/rabbitmq-upgrade.bat",
"//deps/rabbit:scripts/rabbitmqctl.bat",
"//deps/rabbit:scripts/vmware-rabbitmq.bat",
],
allow_files = True,
),
"_rabbitmqctl_escript": attr.label(default = "//deps/rabbitmq_cli:rabbitmqctl"),
"is_windows": attr.bool(mandatory = True),
"plugins": attr.label_list(providers = [ErlangAppInfo]),
}
rabbitmq_home_private = rule(
implementation = _impl,
attrs = RABBITMQ_HOME_ATTRS,
)
def rabbitmq_home(**kwargs):
rabbitmq_home_private(
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
**kwargs
)
def _dirname(p):
return p.rpartition("/")[0]
def rabbitmq_home_short_path(rabbitmq_home):
short_path = rabbitmq_home[RabbitmqHomeInfo].rabbitmqctl.short_path
if rabbitmq_home.label.workspace_root != "":
short_path = path_join(rabbitmq_home.label.workspace_root, short_path)
return _dirname(_dirname(short_path))