#1264 Spec file versioning macros
Closed: nothingtodo by james. Opened by lecris.

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
- 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, cmake

Related issues:
redhat-rpm-config issue, rpm upstream


The project where RPM macros for Fedora are implemented is here:
https://src.fedoraproject.org/rpms/redhat-rpm-config

If you want to push this upstream, you'd want to work with RPM:
https://github.com/rpm-software-management/rpm

The Packaging Committee is only concerned with documenting tools and deciding on best practices, but we don't implement things ourselves.

Note that there's already a macro that implements a subset of what you need - %{version_no_tilde} - which can be used to convert RPM version back to "git style" / "semantic version" (i.e. replace ~ characters with -), and is used by Rust packaging.

There have been requests to move the macro from Rust-specific macro package to redhat-rpm-config:
https://pagure.io/fedora-rust/rust2rpm/issue/192
https://pagure.io/fedora-rust/rust2rpm/issue/218

But I wasn't comfortable with doing this, since the implementation is tailored towards the Rust packaging use case, and only supports replacing ~ characters with -, but nothing else.

A generic macro to support constructing valid RPM version strings from the upstream version (i.e. the inverse of %{version_no_tilde} with more features) would be nice, though. :)

Thank you for the detailed response @decathorpe. I guided @lecris to post here. I expect FPC is the expert body of RPM Packaging and people should discuss proposals here.

We appreciate your guidance on the next steps and best practices.

There's also https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/101 and https://github.com/rpm-software-management/rpm/issues/1219

I've added relevant issue in each upstreams and I'll try to keep each one up to date if relevant with references

people should discuss proposals here.

I recommend this list for discussion: https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject.org/

Metadata Update from @james:
- Issue close_status updated to: nothingtodo
- Issue status updated to: Closed (was: Open)

Metadata