Skip to content

Commit

Permalink
Add a rule for building a source archive
Browse files Browse the repository at this point in the history
that includes the external dependencies
  • Loading branch information
HoloRin committed Jun 14, 2022
1 parent 4fd20ad commit 34db1a3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 10 deletions.
4 changes: 3 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ load("//bazel/elixir:iex_eval.bzl", "iex_eval")
load(":rabbitmq_home.bzl", "rabbitmq_home")
load(":rabbitmq_run.bzl", "rabbitmq_run", "rabbitmq_run_command")
load(":rabbitmqctl.bzl", "rabbitmqctl")
load(":dist.bzl", "package_generic_unix")
load(":dist.bzl", "package_generic_unix", "source_archive")
load(":rabbitmq.bzl", "all_plugins")

exports_files([
Expand Down Expand Up @@ -94,6 +94,8 @@ iex_eval(

package_generic_unix(PLUGINS)

source_archive(PLUGINS + ["//deps/rabbitmq_cli:rabbitmqctl"])

genrule(
name = "test-logs",
outs = ["open-test-logs.sh"],
Expand Down
9 changes: 9 additions & 0 deletions deps/rabbitmq_cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:select_file.bzl", "select_file")
load(":rabbitmqctl.bzl", "rabbitmqctl")
load(":rabbitmqctl_test.bzl", "rabbitmqctl_test")
load("//:rabbitmq_home.bzl", "rabbitmq_home")
Expand All @@ -13,12 +14,20 @@ rabbitmqctl(
] + glob([
"lib/**/*.ex",
]),
license_files = glob(["LICENSE*"]),
visibility = ["//visibility:public"],
deps = [
"//deps/rabbit_common:erlang_app",
],
)

select_file(
name = "fetched_srcs",
srcs = ":rabbitmqctl",
subpath = "deps.tar",
visibility = ["//visibility:public"],
)

rabbitmq_home(
name = "broker-for-cli-tests-home",
testonly = True,
Expand Down
34 changes: 25 additions & 9 deletions deps/rabbitmq_cli/rabbitmqctl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _impl(ctx):
escript = ctx.actions.declare_file(path_join("escript", "rabbitmqctl"))
ebin = ctx.actions.declare_directory("ebin")
mix_invocation_dir = ctx.actions.declare_directory("{}_mix".format(ctx.label.name))
fetched_srcs = ctx.actions.declare_directory("fetched_srcs")
fetched_srcs = ctx.actions.declare_file("deps.tar")

deps = flat_deps(ctx.attr.deps)

Expand All @@ -67,7 +67,7 @@ else
fi
ABS_EBIN_DIR=$PWD/{ebin_dir}
ABS_ESCRIPT_PATH=$PWD/{escript_path}
ABS_FETCHED_SRCS_DIR=$PWD/{fetched_srcs}
ABS_FETCHED_SRCS=$PWD/{fetched_srcs}
export PATH="$ABS_ELIXIR_HOME"/bin:"{erlang_home}"/bin:${{PATH}}
Expand Down Expand Up @@ -101,7 +101,12 @@ cp escript/rabbitmqctl ${{ABS_ESCRIPT_PATH}}
cp _build/${{MIX_ENV}}/lib/rabbitmqctl/ebin/* ${{ABS_EBIN_DIR}}
cp _build/${{MIX_ENV}}/lib/rabbitmqctl/consolidated/* ${{ABS_EBIN_DIR}}
cp -r deps/* ${{ABS_FETCHED_SRCS_DIR}}
tar --sort=name \\
--owner=root:0 \\
--group=root:0 \\
--mtime='UTC 2019-01-01' \\
--file ${{ABS_FETCHED_SRCS}} \\
--create deps
# remove symlinks from the _build directory since it
# is not used, and bazel does not allow them
Expand Down Expand Up @@ -145,25 +150,36 @@ find . -type l -delete
return [
DefaultInfo(
executable = escript,
files = depset([ebin]),
files = depset([ebin, fetched_srcs]),
runfiles = runfiles,
),
ErlangAppInfo(
app_name = ctx.attr.name,
app_name = "rabbitmq_cli",
include = [],
beam = [ebin],
priv = [],
srcs = ctx.files.srcs + [fetched_srcs],
license_files = ctx.files.license_files,
srcs = ctx.files.srcs,
deps = deps,
),
]

rabbitmqctl_private = rule(
implementation = _impl,
attrs = {
"is_windows": attr.bool(mandatory = True),
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = [ErlangAppInfo]),
"is_windows": attr.bool(
mandatory = True,
),
"srcs": attr.label_list(
mandatory = True,
allow_files = True,
),
"license_files": attr.label_list(
allow_files = True,
),
"deps": attr.label_list(
providers = [ErlangAppInfo],
),
},
toolchains = [
"//bazel/elixir:toolchain_type",
Expand Down
43 changes: 43 additions & 0 deletions dist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load(
"erlang_dirs",
"maybe_install_erlang",
)
load("@rules_erlang//:source_tree.bzl", "source_tree")
load(
":rabbitmq_home.bzl",
"RABBITMQ_HOME_ATTRS",
Expand Down Expand Up @@ -282,3 +283,45 @@ def package_generic_unix(plugins):
"//deps/rabbit:manpages-dir",
],
)

# This macro must be invoked from the top level BUILD.bazel of rabbitmq-server
def source_archive(plugins):
source_tree(
name = "source-tree",
deps = plugins,
)

native.filegroup(
name = "root-licenses",
srcs = native.glob(["LICENSE*"]),
visibility = ["//visibility:public"],
)

pkg_tar(
name = "deps-archive",
srcs = [
":source-tree",
],
package_dir = "deps",
strip_prefix = "source-tree",
)

pkg_tar(
name = "cli-deps-archive",
deps = [
"//deps/rabbitmq_cli:fetched_srcs",
],
package_dir = "deps/rabbitmq_cli",
)

pkg_tar(
name = "source_archive",
srcs = [
":root-licenses",
],
deps = [
":deps-archive",
":cli-deps-archive",
],
visibility = ["//visibility:public"],
)

0 comments on commit 34db1a3

Please sign in to comment.