From 8326e7f3b9f8a0dd4bf84cb96cc77652d03eed4c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 10 Apr 2023 21:04:35 +0300 Subject: Add append/prepend support to pkg-bindist --fedora-dist-tag --- bpkg/pkg-bindist.cli | 12 ++++++---- bpkg/system-package-manager-fedora.cxx | 44 +++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) (limited to 'bpkg') diff --git a/bpkg/pkg-bindist.cli b/bpkg/pkg-bindist.cli index 65fbeae..1b86cbe 100644 --- a/bpkg/pkg-bindist.cli +++ b/bpkg/pkg-bindist.cli @@ -443,11 +443,13 @@ namespace bpkg string --fedora-dist-tag { "", - "Alternative distribution tag to use in the binary package release. If - empty value is specified, then no distribution tag is included. The - default is a value that identifies the distribution being used to build - the package, for example, \cb{fc35} for Fedora 35 or \cb{el8} for RHEL - 8." + "Alternative or additional distribution tag to use in the binary package + release. If the specified value starts/ends with \cb{+} then the value + (with \cb{+} removed) is added after/before the default distribution + tag. Otherwise it is used as is instead of the default tag. If empty + value is specified, then no distribution tag is included. The default + is a value that identifies the distribution being used to build the + package, for example, \cb{fc35} for Fedora 35 or \cb{el8} for RHEL 8." } string --fedora-packager diff --git a/bpkg/system-package-manager-fedora.cxx b/bpkg/system-package-manager-fedora.cxx index e22412c..4034932 100644 --- a/bpkg/system-package-manager-fedora.cxx +++ b/bpkg/system-package-manager-fedora.cxx @@ -2459,10 +2459,48 @@ namespace bpkg if (!dist.empty ()) { - // Insert the leading dot into the distribution tag if missing. + bool f (dist.front () == '+'); + bool b (dist.back () == '+'); + + if (f && b) // Note: covers just `+`. + fail << "invalid distribution tag '" << dist << "'"; + + // If the distribution tag is specified with a leading/trailing '+', + // then we query the default tag value and modify it using the + // specified suffix/prefix. // - if (dist.front () != '.') - dist.insert (dist.begin (), '.'); + // Note that we rely on the fact that the dist tag doesn't depend on + // the --target option which we also pass to rpmbuild. + // + if (f || b) + { + string affix (move (dist)); + strings expansions (rpm_eval (cstrings (), cstrings {"%{?dist}"})); + + if (expansions.size () != 1) + fail << "one line expected as an expansion of macro %{?dist}"; + + dist = move (expansions[0]); + + // Normally, the default distribution tag starts with the dot, in + // which case we insert the prefix after it. Note, however, that the + // tag can potentially be re/un-defined (for example in + // ~/.rpmmacros), so we need to also handle the potential absence of + // the leading dot inserting the prefix right at the beginning in + // this case. + // + if (f) + dist.append (affix, 1, affix.size () - 1); + else + dist.insert (dist[0] == '.' ? 1 : 0, affix, 0, affix.size () - 1); + } + else + { + // Insert the leading dot into the distribution tag if missing. + // + if (dist.front () != '.') + dist.insert (dist.begin (), '.'); + } common_opts.push_back ("--define=dist " + dist); } -- cgit v1.1