diff --git a/examples/rpm/prebuilt_rpmbuild/local/BUILD b/examples/rpm/prebuilt_rpmbuild/local/BUILD index 7c273bf68..cfb147d37 100644 --- a/examples/rpm/prebuilt_rpmbuild/local/BUILD +++ b/examples/rpm/prebuilt_rpmbuild/local/BUILD @@ -16,6 +16,7 @@ load("@rules_pkg//toolchains/rpm:rpmbuild.bzl", "rpmbuild_toolchain") rpmbuild_toolchain( name = "prebuilt_rpmbuild", + data = glob(["lib/rpm/**"]), # You could also point to a target that builds rpmbuild from source. label = ":rpmbuild_binary", ) diff --git a/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/macros b/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/macros new file mode 100644 index 000000000..7f3e5be96 --- /dev/null +++ b/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/macros @@ -0,0 +1 @@ +# Replace me with real rpmbuild macros diff --git a/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/platform b/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/platform new file mode 100644 index 000000000..c2a8feeaf --- /dev/null +++ b/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/platform @@ -0,0 +1 @@ +# Replace me with real rpmbuild platform diff --git a/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/rpmrc b/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/rpmrc new file mode 100644 index 000000000..95b04eefa --- /dev/null +++ b/examples/rpm/prebuilt_rpmbuild/local/lib/rpm/rpmrc @@ -0,0 +1 @@ +# Replace me with real rpmbuild rpmrc diff --git a/pkg/rpm_pfg.bzl b/pkg/rpm_pfg.bzl index 941c4ed1a..205a62050 100644 --- a/pkg/rpm_pfg.bzl +++ b/pkg/rpm_pfg.bzl @@ -475,6 +475,7 @@ def _pkg_rpm_impl(ctx): files = [] tools = [] + toolchain_data = [] debuginfo_type = DEBUGINFO_TYPE_NONE name = ctx.attr.package_name if ctx.attr.package_name else ctx.label.name rpm_ctx.make_rpm_args.append("--name=" + name) @@ -500,6 +501,8 @@ def _pkg_rpm_impl(ctx): tools.append(executable_files) rpm_ctx.make_rpm_args.append("--rpmbuild=%s" % executable_files.executable.path) + toolchain_data = toolchain.data + if ctx.attr.debuginfo: debuginfo_type = toolchain.debuginfo_type rpm_ctx.make_rpm_args.append("--debuginfo_type=%s" % debuginfo_type) @@ -885,7 +888,7 @@ def _pkg_rpm_impl(ctx): executable = ctx.executable._make_rpm, use_default_shell_env = True, arguments = rpm_ctx.make_rpm_args, - inputs = files + (ctx.files.data or []), + inputs = files + (ctx.files.data or []) + toolchain_data, outputs = rpm_ctx.output_rpm_files, env = { "LANG": "en_US.UTF-8", diff --git a/tests/rpm/toolchain_tests.bzl b/tests/rpm/toolchain_tests.bzl index 9fffa8ea2..d9c237ea3 100644 --- a/tests/rpm/toolchain_tests.bzl +++ b/tests/rpm/toolchain_tests.bzl @@ -53,6 +53,11 @@ def _toolchain_contents_test_impl(ctx): ctx.attr.expect_path, info.path, ) + asserts.equals( + env, + ctx.attr.expect_data_count, + len(info.data), + ) return analysistest.end(env) toolchain_contents_test = analysistest.make( @@ -65,6 +70,7 @@ toolchain_contents_test = analysistest.make( allow_files = True, ), "expect_path": attr.string(), + "expect_data_count": attr.int(default = 0), }, ) @@ -119,6 +125,21 @@ def _create_toolchain_creation_tests(): expect_path = "/usr/bin/foo", ) + rpmbuild_toolchain( + name = "tc_with_data", + path = "/usr/bin/foo", + data = [":toolchain_test.bzl"], + tags = ["manual"], + ) + toolchain_contents_test( + name = "tc_with_data_test", + target_under_test = ":tc_with_data", + expect_valid = True, + expect_label = None, + expect_path = "/usr/bin/foo", + expect_data_count = 1, + ) + # buildifier: disable=unnamed-macro def create_toolchain_analysis_tests(): _create_toolchain_creation_tests() diff --git a/toolchains/rpm/rpmbuild.bzl b/toolchains/rpm/rpmbuild.bzl index ebc1016cb..f07f819a8 100644 --- a/toolchains/rpm/rpmbuild.bzl +++ b/toolchains/rpm/rpmbuild.bzl @@ -22,6 +22,7 @@ RpmbuildInfo = provider( "path": "The path to a pre-built rpmbuild", "version": "The version string of rpmbuild", "debuginfo_type": "The variant of the underlying debuginfo config", + "data": "Additional files needed at runtime by rpmbuild", }, ) @@ -37,6 +38,7 @@ def _rpmbuild_toolchain_impl(ctx): path = ctx.attr.path, version = ctx.attr.version, debuginfo_type = ctx.attr.debuginfo_type, + data = ctx.files.data, ), ) return [toolchain_info] @@ -64,6 +66,10 @@ rpmbuild_toolchain = rule( """, default = "none", ), + "data": attr.label_list( + doc = "Additional files needed at runtime by rpmbuild.", + allow_files = True, + ), }, )