How to version RPM's

Tracy Reed treed at
Sat Jan 17 00:03:04 UTC 2009

I am trying to accomplish proper and safe versioning of my RPM's and
all of their constituents and would like to see how other people do
this and what the best practices are.

It seems best if the version numbering is automatic and based on a
version number provided by the version control system.

The version number appearing in the final package name should allow
proper yum upgrades to occur when the rpm is placed in my repository.

We need to version the tarball of software we create in-house used in
the rpm as well as version the spec file and any other patches/sources
used. And we need a final version of that tarball combined with that
specfile to produce the version of the final rpm.

We are working with CentOS 5.2 and occasionally RHEL 5.2 as the base
OS and using Mercurial for version control.

Things are currently arranged such that there is a repository for each
project which contains a makefile which tars up the project to make
the tarball for the rpm.

Then there is a repository which contains all of the sources such as
tarballs, patches, etc. Tarballs generated by the above process get
checked in here.

There is also a repository which contains the rpmbuild directory and
the specfiles as well as a script to grab all of the sources needed to
build the rpms from the specs.

Then we rpmbuild -bb the results of the above to make a new rpm which
should have a version number based on the above. If that all works ok
we check that into a repository which is checked out onto our update
server for our machines to upgrade from.

It is not quite clear to me how to link the version of the tarball
produced with the version of the specfile to version the final rpm. I
can't encode the version in the name of the tarball or I would always
have to change my spec file. I might be able to put a file called
VERSION in the tarball via the Makefile which does the tarring and
then extract that from the tar file and automatically put it into the
spec file somehow during rpm build time. Seems messy.

Another concern of mine is that someone might make a tarball or modify a
spec and build an RPM from it but not commit those changes. So it
seems I need to run a command from the Makefile which makes the
tarball and from within the SPEC file (preferably somehow via the
.rpmmacros file so it is automatic for any rpm we build) which checks
if there are outstanding commits and makes an appropriate note in the
version number. Something like:


So we will know that this isn't an official build just in case it
somehow makes it into circulation somewhere.

Since we use Hg it was suggested to me that number of ancestor-hash
might make a good version number to put in our rpms. This was
supposedly discussed on the Hg mailing list some time ago but I have
not been able to find it. I know that only hashes are portable between
repositories but supposedly using the number of ancestor:hash works
out to be ok even in the face of forks and merges and multiple heads
etc. So using this scheme an rpm might come out looking like:


if there are no outstanding commits or:


if there are. Where 60 is the number of the ancestor and de6004cddece
is the hash.

Any suggestions on how to accomplish this? Is there a simpler way? Am
I making this overly complicated?

Tracy Reed

More information about the Rpm-list mailing list