Bug 2180791

Summary: Spec file versioning macros
Product: [Fedora] Fedora Reporter: Cristian Le <fedora>
Component: redhat-rpm-configAssignee: Florian Festi <ffesti>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 39CC: ajax, carl, ffesti, fweimer, igor.raits, j, maxwell, mhroncok, ngompa13, nickc, pmatilai, sipoyare, torsava
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Cristian Le 2023-03-22 10:05:51 UTC
This is a reference from fedora packaging committee issue[1]:

> I would like to propose a few helper macros for dealing with version control:
> - Format git tag -> rpm version: e.g. `1.2.3-rc1`/`1.2.3rc` -> `1.2.3~rc1`. This could be detected from python's `packaging.version`[2]
> - Format rpm version -> git tag/free format: e.g. `1.2.3~rc1` -> `1.2.3-rc1`. An interface for this could be: `%{version_format -base 1.2.3 -prerel rc1 -format v{base}-{prerel}}` or if possible more automated `%{version_format -version %{version} -format v{base}-{prerel}}`
> - Detect version from git tag/`.git_archival.txt` similar to `setuptools_scm`. This would be incredibly useful for in-source packaging, but not in dist-gits
>
> These issues arose when trying to make packit be able to parse the version from git tags like v1.2.3-rc1. We can make a custom handling there, but it would be better to have a more standardized way to do this. The best case is to implement these upstream so that these can be used by OpenSuse as well.
> For reference here are a few workarounds that have to be maintained and are inconsistent with each other: bluefish[3], cmake[4]

There is also a proposal for migrating the macro used in rust packaging `%{version_no_tilde}`[5], but this is a more complete, and if it can be introduced here, it could be used from the start of the spec file.

I have also opened up an issue[6] on rpm upstream.

[1] https://pagure.io/packaging-committee/issue/1264
[2] https://packaging.pypa.io/en/stable/version.html
[3] https://src.fedoraproject.org/rpms/bluefish/blob/rawhide/f/bluefish.spec#_2
[4] https://src.fedoraproject.org/rpms/cmake/blob/rawhide/f/cmake.spec#_68
[5] https://pagure.io/fedora-rust/rust2rpm/issue/192
[6] https://github.com/rpm-software-management/rpm/issues/2443

Comment 1 Miro Hrončok 2023-03-22 10:15:04 UTC
It's unclear to me whether you propose to implement this or you would like somebody else to do it. Reimplementing packaging.version in RPM macros might be a tad tricky.

Comment 2 Cristian Le 2023-03-22 10:25:51 UTC
Well. We might need to discuss on how it can be designed, the name of the macros etc, and where should it be first implemented? Upstream, or here first. I think we can update here first to see what roadblocks we can encounter.

I thought rpm was using python, but I see that's not the case, so we would have to manually implement these. Can we use regex, python scripts, C++ functions with dependencies in macros? If so I think I can implement 1 and 2 with some pointers to where to start.

Comment 3 Miro Hrončok 2023-03-22 17:24:15 UTC
If you want to have it in redhat-rpm-config you can implement it in RPM macro syntax or Lua only.

Comment 4 Fedora Release Engineering 2023-08-16 07:12:18 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 39 development cycle.
Changing version to 39.