Skip to content

Commit f68b1de

Browse files
authored
rpm: fix sub-RPM post_scriptlet and add %postun support (#934)
The existing implementation of `%post` neglected to actually include the contents of the `%post` scriptlet and simply added a `%post` section to the spec file without the body, e.g. %post sub %files sub ... With this change, I've also added support for `%postun` and included the scriptlet support in the `test_golden_sub_rpm_contents` test case.
1 parent 62cc323 commit f68b1de

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

pkg/rpm_pfg.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ PackageSubRPMInfo = provider(
4747
"group": "RPM subpackage `Group` tag",
4848
"description": "Multi-line description of this subpackage",
4949
"post_scriptlet": "RPM `$post` scriplet for this subpackage",
50+
"postun_scriptlet": "RPM `$postun` scriplet for this subpackage",
5051
"architecture": "Subpackage architecture",
5152
"epoch": "RPM `Epoch` tag for this subpackage",
5253
"version": "RPM `Version` tag for this subpackage",
@@ -384,6 +385,14 @@ def _process_subrpm(ctx, rpm_name, rpm_info, rpm_ctx, debuginfo_type):
384385
rpm_lines += [
385386
"",
386387
"%%post %s" % rpm_info.package_name,
388+
rpm_info.post_scriptlet,
389+
]
390+
391+
if rpm_info.postun_scriptlet:
392+
rpm_lines += [
393+
"",
394+
"%%postun %s" % rpm_info.package_name,
395+
rpm_info.postun_scriptlet,
387396
]
388397

389398
if rpm_info.srcs:
@@ -1302,6 +1311,7 @@ def _pkg_sub_rpm_impl(ctx):
13021311
group = ctx.attr.group,
13031312
description = ctx.attr.description,
13041313
post_scriptlet = ctx.attr.post_scriptlet,
1314+
postun_scriptlet = ctx.attr.postun_scriptlet,
13051315
architecture = ctx.attr.architecture,
13061316
epoch = ctx.attr.epoch,
13071317
version = ctx.attr.version,
@@ -1339,6 +1349,7 @@ pkg_sub_rpm = rule(
13391349
),
13401350
"description": attr.string(doc = "Multi-line description of this subrpm"),
13411351
"post_scriptlet": attr.string(doc = "RPM `%post` scriplet for this subrpm"),
1352+
"postun_scriptlet": attr.string(doc = "RPM `%postun` scriplet for this subrpm"),
13421353
"architecture": attr.string(doc = "Sub RPM architecture"),
13431354
"epoch": attr.string(doc = "RPM `Epoch` tag for this subrpm"),
13441355
"version": attr.string(doc = "RPM `Version` tag for this subrpm"),

tests/rpm/BUILD

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ pkg_sub_rpm(
529529
":test_sub_rpm_files",
530530
],
531531
description = "Test subrpm2 description",
532+
post_scriptlet = "echo post",
533+
postun_scriptlet = "echo postun",
532534
summary = "Test subrpm2",
533535
)
534536

@@ -570,13 +572,13 @@ genrule(
570572
# pkg_rpm emits two outputs
571573
RPMS=($(SRCS))
572574
echo "===== main RPM =====" > $@
573-
rpm -qpi --list $${RPMS[0]} | \
575+
rpm -qpi --scripts --list $${RPMS[0]} | \
574576
grep -v 'Build Date' | grep -v 'Build Host' | grep -v 'Relocations' >> $@
575577
echo "===== sub RPM ======" >> $@
576-
rpm -qpi --list $${RPMS[1]} | \
578+
rpm -qpi --scripts --list $${RPMS[1]} | \
577579
grep -v 'Build Date' | grep -v 'Build Host' | grep -v 'Relocations' >> $@
578580
echo "===== sub RPM ======" >> $@
579-
rpm -qpi --list $${RPMS[2]} | \
581+
rpm -qpi --scripts --list $${RPMS[2]} | \
580582
grep -v 'Build Date' | grep -v 'Build Host' | grep -v 'Relocations' >> $@
581583
""",
582584
)

tests/rpm/test_sub_rpm_contents.txt.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ Source RPM : test_sub_rpm_main-1-0.src.rpm
4242
Summary : Test subrpm2
4343
Description :
4444
Test subrpm2 description
45+
postinstall scriptlet (using /bin/sh):
46+
echo post
47+
postuninstall scriptlet (using /bin/sh):
48+
echo postun
4549
/test_sub_rpm_file_input.txt

0 commit comments

Comments
 (0)