Skip to content

Commit

Permalink
Copy rather than symlink rabbitmqctl in bazel
Browse files Browse the repository at this point in the history
when creating rabbitmq home folders
  • Loading branch information
HoloRin committed Dec 8, 2022
1 parent 31dffe7 commit 9e6d66e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 2 additions & 3 deletions dist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ load("@rules_erlang//:source_tree.bzl", "source_tree")
load(
":rabbitmq_home.bzl",
"RABBITMQ_HOME_ATTRS",
"RabbitmqHomeInfo",
"copy_escript",
"flatten",
"link_escript",
)
load(
":rabbitmq.bzl",
Expand Down Expand Up @@ -77,7 +76,7 @@ def _sbin_dir_private_impl(ctx):
]

def _escript_dir_private_impl(ctx):
escripts = [link_escript(ctx, escript) for escript in ctx.files._scripts]
escripts = [copy_escript(ctx, escript) for escript in ctx.files._scripts]

return [
DefaultInfo(
Expand Down
23 changes: 15 additions & 8 deletions rabbitmq_home.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,29 @@ RabbitmqHomeInfo = provider(
)

def _copy_script(ctx, script):
dest = ctx.actions.declare_file(path_join(ctx.label.name, "sbin", script.basename))
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 link_escript(ctx, escript):
def copy_escript(ctx, escript):
e = ctx.attr._rabbitmqctl_escript.files_to_run.executable
s = ctx.actions.declare_file(path_join(ctx.label.name, "escript", escript.basename))
ctx.actions.symlink(
output = s,
target_file = e,
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 s
return dest

def _plugins_dir_links(ctx, plugin):
lib_info = plugin[ErlangAppInfo]
Expand Down Expand Up @@ -80,7 +87,7 @@ def _impl(ctx):
source_scripts = ctx.files._scripts_windows
scripts = [_copy_script(ctx, script) for script in source_scripts]

escripts = [link_escript(ctx, escript) for escript in ctx.files._scripts]
escripts = [copy_escript(ctx, escript) for escript in ctx.files._scripts]

plugins = flatten([_plugins_dir_links(ctx, plugin) for plugin in plugins])

Expand Down

0 comments on commit 9e6d66e

Please sign in to comment.