Skip to content

Commit

Permalink
Improve handling of sub rpms. (bazelbuild#833)
Browse files Browse the repository at this point in the history
- Do not create the subrpms files when we don't have to
- Do not add `buildsubdir .`  That seems to cause rpmbuild failures with
  older rpmbuild.
- General cleanup: Remove tests against None which is needlessly brittle.
  • Loading branch information
aiuto authored Mar 25, 2024
1 parent 15d628d commit dcce3e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
20 changes: 11 additions & 9 deletions pkg/make_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,17 @@ def SetupWorkdir(self,

# Slurp in the scriptlets...
self.pre_scriptlet = \
SlurpFile(os.path.join(original_dir, pre_scriptlet_path)) if pre_scriptlet_path is not None else ''
SlurpFile(os.path.join(original_dir, pre_scriptlet_path)) if pre_scriptlet_path else ''
self.post_scriptlet = \
SlurpFile(os.path.join(original_dir, post_scriptlet_path)) if post_scriptlet_path is not None else ''
SlurpFile(os.path.join(original_dir, post_scriptlet_path)) if post_scriptlet_path else ''
self.preun_scriptlet = \
SlurpFile(os.path.join(original_dir, preun_scriptlet_path)) if preun_scriptlet_path is not None else ''
SlurpFile(os.path.join(original_dir, preun_scriptlet_path)) if preun_scriptlet_path else ''
self.postun_scriptlet = \
SlurpFile(os.path.join(original_dir, postun_scriptlet_path)) if postun_scriptlet_path is not None else ''
SlurpFile(os.path.join(original_dir, postun_scriptlet_path)) if postun_scriptlet_path else ''
self.posttrans_scriptlet = \
SlurpFile(os.path.join(original_dir, posttrans_scriptlet_path)) if posttrans_scriptlet_path is not None else ''
SlurpFile(os.path.join(original_dir, posttrans_scriptlet_path)) if posttrans_scriptlet_path else ''
self.subrpms = \
SlurpFile(os.path.join(original_dir, subrpms_file)) if subrpms_file is not None else ''
SlurpFile(os.path.join(original_dir, subrpms_file)) if subrpms_file else ''

# Then prepare for textual substitution. This is typically only the case for the
# experimental `pkg_rpm`.
Expand All @@ -279,7 +279,7 @@ def SetupWorkdir(self,
'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 "",
'SUBRPMS' : (self.subrpms if self.subrpms else ""),
'SUBRPMS' : self.subrpms,
'CHANGELOG': ""
}

Expand Down Expand Up @@ -362,11 +362,13 @@ def CallRpmBuild(self, dirname, rpmbuild_args):
args.append('-vv')

# Common options
# NOTE: There may be a need to add '--define', 'buildsubdir .' for some
# rpmbuild versions. But that breaks other rpmbuild versions, so before
# adding it back in, add extensive tests.
args += [
'--define', '_topdir %s' % dirname,
'--define', '_tmppath %s/TMP' % dirname,
'--define', '_builddir %s/BUILD' % dirname,
'--define', 'buildsubdir .',
'--bb',
'--buildroot=%s' % buildroot,
] # yapf: disable
Expand Down Expand Up @@ -467,7 +469,7 @@ def Build(self, spec_file, out_file, subrpm_out_files=None,
spec_file = os.path.join(original_dir, spec_file)
out_file = os.path.join(original_dir, out_file)

if subrpm_out_files is not None:
if subrpm_out_files:
subrpm_out_files = (s.split(':') for s in subrpm_out_files)
subrpm_out_files = [
(s[0], os.path.join(original_dir, s[1])) for s in subrpm_out_files]
Expand Down
18 changes: 6 additions & 12 deletions pkg/rpm_pfg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -666,27 +666,21 @@ def _pkg_rpm_impl(ctx):
_process_dep(dep, rpm_ctx)

#### subrpms
subrpm_file = ctx.actions.declare_file(
"{}.spec.subrpms".format(rpm_name),
)
if ctx.attr.subrpms:
subrpm_lines = []

for s in ctx.attr.subrpms:
subrpm_lines += _process_subrpm(ctx, rpm_name, s[PackageSubRPMInfo], rpm_ctx)
subrpm_lines.extend(_process_subrpm(ctx, rpm_name, s[PackageSubRPMInfo], rpm_ctx))

ctx.actions.write(
output = subrpm_file,
content = "\n".join(subrpm_lines),
subrpm_file = ctx.actions.declare_file(
"{}.spec.subrpms".format(rpm_name),
)
else:
ctx.actions.write(
output = subrpm_file,
content = "# no subrpms",
content = "\n".join(subrpm_lines),
)
files.append(subrpm_file)
rpm_ctx.make_rpm_args.append("--subrpms=" + subrpm_file.path)

files.append(subrpm_file)
rpm_ctx.make_rpm_args.append("--subrpms=" + subrpm_file.path)
#### Procedurally-generated scripts/lists (%install, %files)

# We need to write these out regardless of whether we are using
Expand Down

0 comments on commit dcce3e6

Please sign in to comment.