aboutsummaryrefslogtreecommitdiff
path: root/bpkg/system-package-manager-fedora.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-04-10 21:04:35 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-04-11 10:29:20 +0300
commit8326e7f3b9f8a0dd4bf84cb96cc77652d03eed4c (patch)
tree93cebf933ff2e7a32e658eff6979955adef56c86 /bpkg/system-package-manager-fedora.cxx
parent089893e5b5f139d6bfe8c0817b639c9290a6a551 (diff)
Add append/prepend support to pkg-bindist --fedora-dist-tag
Diffstat (limited to 'bpkg/system-package-manager-fedora.cxx')
-rw-r--r--bpkg/system-package-manager-fedora.cxx44
1 files changed, 41 insertions, 3 deletions
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);
}