Where to store VCS version in RPM?

Solution 1:

Fedora (and very rarely RHEL) place this information in the Release tag.

For instance:

Name:           mypackage
Version:        0.0.1
Release:        20140114git0abcdef

Solution 2:

RPM actually has a poorly documented VCS tag.

It doesn't appear to have any sort of guidelines on its use, but it exists and is supported.

cat > test.spec <<'__END__'
Name: foo
Version: 1
Summary: foo
License: None
Release: 1
VCS: git:repo=my-repo:branch=my-branch:sha=1234deadbeef


$ rpmspec -q test.spec --qf "%{VCS}\n"

It appears to be limited to a single parse token. Still useful. I didn't find any documentation on a well defined format or structure for it, and its adoption is limited. On my Fedora 32 system I found two packages using it, with different formats:

$ rpm -qa --qf '%{Name} %{VCS}\n' |grep -v '(none)'
bcache-tools https://github.com/g2p/bcache-tools.git
libcue scm:git:https://github.com/lipnitsk/libcue.git

Frankly it's a real shame rpm doesn't give us the ability to inject custom tag info. I want to record the Jenkins build ID and job name, the git commit hash, and git branch or tag, but don't really want them in the changelog.

I can do this in debs with X-BS-foo tags.

You can see a list of allowed rpm tags with rpm --querytags.

The DISTURL tag appears to be reserved for another use but could be a candidate.

There's also URL; you could choose to embed SCM info there, and have a redirect that takes the URL to a reasonable location if visited by a browser.

You may see references to "rpm5" supporting custom tags. This seems to be a dead fork of rpm, not the rpm.org distribution used on most major distros.