Skip to content

Commit

Permalink
Add %posttrans scriptlet to RPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
k0walik committed Dec 21, 2023
1 parent a0d0deb commit 7322067
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/make_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def SetupWorkdir(self,
post_scriptlet_path=None,
preun_scriptlet_path=None,
postun_scriptlet_path=None,
posttrans_scriptlet_path=None,
changelog_file=None,
file_list_path=None):
"""Create the needed structure in the workdir."""
Expand Down Expand Up @@ -264,6 +265,8 @@ def SetupWorkdir(self,
SlurpFile(os.path.join(original_dir, preun_scriptlet_path)) if preun_scriptlet_path is not None else ''
self.postun_scriptlet = \
SlurpFile(os.path.join(original_dir, postun_scriptlet_path)) if postun_scriptlet_path is not None else ''
self.posttrans_scriptlet = \
SlurpFile(os.path.join(original_dir, posttrans_scriptlet_path)) if posttrans_scriptlet_path is not None else ''

# Then prepare for textual substitution. This is typically only the case for the
# experimental `pkg_rpm`.
Expand All @@ -272,6 +275,7 @@ def SetupWorkdir(self,
'POST_SCRIPTLET': ("%post\n" + self.post_scriptlet) if self.post_scriptlet else "",
'PREUN_SCRIPTLET': ("%preun\n" + self.preun_scriptlet) if self.preun_scriptlet else "",
'POSTUN_SCRIPTLET': ("%postun\n" + self.postun_scriptlet) if self.postun_scriptlet else "",
'POSTTRANS_SCRIPTLET': ("%posttrans\n" + self.posttrans_scriptlet) if self.posttrans_scriptlet else "",
'CHANGELOG': ""
}

Expand Down Expand Up @@ -430,6 +434,7 @@ def Build(self, spec_file, out_file,
post_scriptlet_path=None,
preun_scriptlet_path=None,
postun_scriptlet_path=None,
posttrans_scriptlet_path=None,
file_list_path=None,
changelog_file=None,
rpmbuild_args=None):
Expand All @@ -452,6 +457,7 @@ def Build(self, spec_file, out_file,
post_scriptlet_path=post_scriptlet_path,
preun_scriptlet_path=preun_scriptlet_path,
postun_scriptlet_path=postun_scriptlet_path,
posttrans_scriptlet_path=posttrans_scriptlet_path,
changelog_file=changelog_file)
status = self.CallRpmBuild(dirname, rpmbuild_args or [])
self.SaveResult(out_file)
Expand Down Expand Up @@ -501,6 +507,8 @@ def main(argv):
help='File containing the RPM %preun scriptlet, if to be substituted')
parser.add_argument('--postun_scriptlet',
help='File containing the RPM %postun scriptlet, if to be substituted')
parser.add_argument('--posttrans_scriptlet',
help='File containing the RPM %posttrans scriptlet, if to be substituted')
parser.add_argument('--changelog',
help='File containing the RPM changelog text')

Expand All @@ -526,6 +534,7 @@ def main(argv):
post_scriptlet_path=options.post_scriptlet,
preun_scriptlet_path=options.preun_scriptlet,
postun_scriptlet_path=options.postun_scriptlet,
posttrans_scriptlet_path=options.posttrans_scriptlet,
changelog_file=options.changelog,
rpmbuild_args=options.rpmbuild_args)
except NoRpmbuildFoundError:
Expand Down
4 changes: 3 additions & 1 deletion pkg/rpm/template.spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ ${PREUN_SCRIPTLET}

${POSTUN_SCRIPTLET}

${CHANGELOG}
${POSTTRANS_SCRIPTLET}

${CHANGELOG}
22 changes: 22 additions & 0 deletions pkg/rpm_pfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,18 @@ def _pkg_rpm_impl(ctx):
ctx.actions.write(scriptlet_file, ctx.attr.postun_scriptlet)
args.append("--postun_scriptlet=" + scriptlet_file.path)

if ctx.attr.posttrans_scriptlet_file:
if ctx.attr.posttrans_scriptlet:
fail("Both posttrans_scriptlet and posttrans_scriptlet_file attributes were specified")
posttrans_scriptlet_file = ctx.file.posttrans_scriptlet_file
files.append(posttrans_scriptlet_file)
args.append("--posttrans_scriptlet=" + posttrans_scriptlet_file.path)
elif ctx.attr.posttrans_scriptlet:
scriptlet_file = ctx.actions.declare_file(ctx.label.name + ".posttrans_scriptlet")
files.append(scriptlet_file)
ctx.actions.write(scriptlet_file, ctx.attr.posttrans_scriptlet)
args.append("--posttrans_scriptlet=" + scriptlet_file.path)

#### Expand the spec file template; prepare data files

spec_file = ctx.actions.declare_file("%s.spec" % rpm_name)
Expand Down Expand Up @@ -910,6 +922,16 @@ pkg_rpm = rule(
doc = """File containing the RPM `%postun` scriptlet""",
allow_single_file = True,
),
"posttrans_scriptlet": attr.string(
doc = """RPM `%posttrans` scriptlet. Currently only allowed to be a shell script.
`posttrans_scriptlet` and `posttrans_scriptlet_file` are mutually exclusive.
""",
),
"posttrans_scriptlet_file": attr.label(
doc = """File containing the RPM `%posttrans` scriptlet""",
allow_single_file = True,
),
"conflicts": attr.string_list(
doc = """List of capabilities that conflict with this package when it is installed.
Expand Down
4 changes: 4 additions & 0 deletions tests/rpm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pkg_rpm(
postun_scriptlet = """echo postun""",
pre_scriptlet = """echo pre""",
preun_scriptlet = """echo preun""",
posttrans_scriptlet = """echo posttrans""",
provides = ["test"],
release = "2222",
requires = ["test-lib > 1.0"],
Expand All @@ -164,6 +165,7 @@ pkg_rpm(
postun_scriptlet = """echo postun""",
pre_scriptlet = """echo pre""",
preun_scriptlet = """echo preun""",
posttrans_scriptlet = """echo posttrans""",
provides = ["test"],
release = "2222",
requires = ["test-lib > 1.0"],
Expand Down Expand Up @@ -191,6 +193,7 @@ pkg_rpm(
postun_scriptlet = """echo postun""",
pre_scriptlet = """echo pre""",
preun_scriptlet = """echo preun""",
posttrans_scriptlet = """echo posttrans""",
provides = ["test"],
release = "2222",
requires = ["test-lib > 1.0"],
Expand Down Expand Up @@ -285,6 +288,7 @@ genrule(
# NOTE: excludes 'rpmlib' requires that may be version-dependent
echo 'capability:sense'
# Common, automatically generated
echo '/bin/sh:interp,posttrans'
echo '/bin/sh:pre,interp'
echo '/bin/sh:post,interp'
echo '/bin/sh:preun,interp'
Expand Down
2 changes: 2 additions & 0 deletions tests/rpm/pkg_rpm_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def test_scriptlet_content(self):
echo preun
postuninstall scriptlet (using /bin/sh):
echo postun
posttrans scriptlet (using /bin/sh):
echo posttrans
"""

output = subprocess.check_output(
Expand Down
2 changes: 2 additions & 0 deletions tests/rpm/template-test.spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ ${POST_SCRIPTLET}
${PREUN_SCRIPTLET}

${POSTUN_SCRIPTLET}

${POSTTRANS_SCRIPTLET}

0 comments on commit 7322067

Please sign in to comment.