Skip to content

Commit 178d0b8

Browse files
committed
Support relocatable rpmbuild by adding data attribute to the toolchain
rpmbuild ships with runtime configuration files (lib/rpm/) that must be present for it to successfully build RPMs. When running under remote execution, these files were not being staged because the toolchain had no way to declare them as dependencies. Add a `data` attribute to `rpmbuild_toolchain` so that runtime files can be specified alongside the rpmbuild binary. These files are propagated through `RpmbuildInfo` and included as inputs to the MakeRpm action in `pkg_rpm`.
1 parent e15c331 commit 178d0b8

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

pkg/rpm_pfg.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ def _pkg_rpm_impl(ctx):
475475

476476
files = []
477477
tools = []
478+
toolchain_data = []
478479
debuginfo_type = DEBUGINFO_TYPE_NONE
479480
name = ctx.attr.package_name if ctx.attr.package_name else ctx.label.name
480481
rpm_ctx.make_rpm_args.append("--name=" + name)
@@ -500,6 +501,8 @@ def _pkg_rpm_impl(ctx):
500501
tools.append(executable_files)
501502
rpm_ctx.make_rpm_args.append("--rpmbuild=%s" % executable_files.executable.path)
502503

504+
toolchain_data = toolchain.data
505+
503506
if ctx.attr.debuginfo:
504507
debuginfo_type = toolchain.debuginfo_type
505508
rpm_ctx.make_rpm_args.append("--debuginfo_type=%s" % debuginfo_type)
@@ -885,7 +888,7 @@ def _pkg_rpm_impl(ctx):
885888
executable = ctx.executable._make_rpm,
886889
use_default_shell_env = True,
887890
arguments = rpm_ctx.make_rpm_args,
888-
inputs = files + (ctx.files.data or []),
891+
inputs = files + (ctx.files.data or []) + toolchain_data,
889892
outputs = rpm_ctx.output_rpm_files,
890893
env = {
891894
"LANG": "en_US.UTF-8",

tests/rpm/toolchain_tests.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def _toolchain_contents_test_impl(ctx):
5353
ctx.attr.expect_path,
5454
info.path,
5555
)
56+
asserts.equals(
57+
env,
58+
ctx.attr.expect_data_count,
59+
len(info.data),
60+
)
5661
return analysistest.end(env)
5762

5863
toolchain_contents_test = analysistest.make(
@@ -65,6 +70,7 @@ toolchain_contents_test = analysistest.make(
6570
allow_files = True,
6671
),
6772
"expect_path": attr.string(),
73+
"expect_data_count": attr.int(default = 0),
6874
},
6975
)
7076

@@ -119,6 +125,21 @@ def _create_toolchain_creation_tests():
119125
expect_path = "/usr/bin/foo",
120126
)
121127

128+
rpmbuild_toolchain(
129+
name = "tc_with_data",
130+
path = "/usr/bin/foo",
131+
data = [":toolchain_test.bzl"],
132+
tags = ["manual"],
133+
)
134+
toolchain_contents_test(
135+
name = "tc_with_data_test",
136+
target_under_test = ":tc_with_data",
137+
expect_valid = True,
138+
expect_label = None,
139+
expect_path = "/usr/bin/foo",
140+
expect_data_count = 1,
141+
)
142+
122143
# buildifier: disable=unnamed-macro
123144
def create_toolchain_analysis_tests():
124145
_create_toolchain_creation_tests()

toolchains/rpm/rpmbuild.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ RpmbuildInfo = provider(
2222
"path": "The path to a pre-built rpmbuild",
2323
"version": "The version string of rpmbuild",
2424
"debuginfo_type": "The variant of the underlying debuginfo config",
25+
"data": "Additional files needed at runtime by rpmbuild",
2526
},
2627
)
2728

@@ -37,6 +38,7 @@ def _rpmbuild_toolchain_impl(ctx):
3738
path = ctx.attr.path,
3839
version = ctx.attr.version,
3940
debuginfo_type = ctx.attr.debuginfo_type,
41+
data = ctx.files.data,
4042
),
4143
)
4244
return [toolchain_info]
@@ -64,6 +66,10 @@ rpmbuild_toolchain = rule(
6466
""",
6567
default = "none",
6668
),
69+
"data": attr.label_list(
70+
doc = "Additional files needed at runtime by rpmbuild.",
71+
allow_files = True,
72+
),
6773
},
6874
)
6975

0 commit comments

Comments
 (0)