![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
https://dotat.at/@/2024-05-13-what-ident.html
There are a couple of version control commands that deserve wider
appreciation: SCCS what
and RCS ident
.
They allow you to find out what source a binary was built from,
without having to run it -- handy if it is a library!
keyword expansion
SCCS, RCS, cvs
, and svn
all have a way to expand keywords in a
file when it is checked out of version control.
The POSIX SCCS get
documentation describes its runes like
%W%
under the "identification keywords" heading.
RCS / cvs
/ svn
keyword substitution uses more descriptive
markers like $Revision$
.
a berkeley example
It was a BSD tradition to use keyword expansion everywhere. I first encountered it when I got involved in the Apache httpd project in the late 1990s -- Apache's CVS repository was hosted on a FreeBSD box and used a version of FreeBSD's CVS administrative scripts.
Here's an example from res_send.c
in FreeBSD's libc
resolver.
static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
static const char rcsid[] = "$Id: res_send.c,v 1.22 2009/01/22 23:49:23 tbox Exp $";
__FBSDID("$FreeBSD$");
There are geological strata of version control tags here:
- the
sccsid
from the Berkeley CSRG SCCS repository - the
rcsid
from ISC's BIND repository (tbox
was ISC's tinderbox build / CI system) - the
FBSDID
from FreeBSD'scvs
and latersvn
repositories (which has not been expanded)
an unifdef example
When unifdef
was uplifted to git, I wanted to keep its embedded
version control keywords -- I have a sentimental liking for this old
tradition. If you've installed cssc
, rcs
, and unifdef
on a
Debian box, you can run,
:; sccs what /usr/bin/unifdef
:; ident /usr/bin/unifdef
Both of those will produce similar output to
:; unifdef -V
On a Mac with the developer command-line tools installed,
:; what /Library/Developer/CommandLineTools/usr/bin/unifdef
You get the output twice because it's a fat binary!
versioning three ways
In unifdef.c
, the embedded version looks like,
static const char copyright[] =
"@(#) $Version: unifdef-2.12 $\n"
"@(#) $Date: 2020-02-14 16:49:56 +0000 $\n"
"@(#) $Author: Tony Finch (dot@dotat.at) $\n"
"@(#) $URL: http://dotat.at/prog/unifdef $\n"
;
Each line is prefixed with an SCCS magic marker @(#)
so that what
can find it, and wrapped in an RCS-style $Keyword$
so that ident
can find it. There's a fairly trivial version()
function that
spits out the copyright[]
string when you run unifdef -V
.
embedding versions from git
My projects have various horrible build scripts for embedding the
version number from git
. The basic idea is,
use an annotated or signed tag to mark a release, i.e.
git tag -a
orgit tag -s
use
git describe
to get a version string that includes an extra number counting commits since the last releasemaybe use
git show --pretty=format:%ai -s HEAD
to get a release datestuff the outputs from
git
into the$Version$
and$Date$
RCS keywords
retro cool
I enjoy keeping this old feature working, even though it isn't very useful if no-one knows about it! Maybe if I blog about it, it'll become more widespread?
no subject
Date: 2024-05-14 15:53 (UTC)My recollection is that on one system I was using the $Id$ etc. were not expanded in the environment where I built the executables where ident would have been useful. Or it might just have been that I didn't check in often enough for the datestamp or version number to vary usefully.
I do remember thinking that it interfered with reproducible binaries, but that should not be a problem. If $Id$ has changed the source should not be the same, and reproducible binaries should flag the difference.
I do note, however, that
ident unidef
on Ubuntu gives:Did you make any important changes in those twelve minutes and forty seconds, or is that just the timestamp of a git pull ?
It would be a pity if something like
git pull
makes this break reproducible binaries.GDAL has a macro CPL_CVSID which can be turned on or off at build time
https://github.com/OSGeo/gdal/blob/e187124a8462439d7a94581bc1cb062d9df51ac8/port/cpl_port.h#L905-L930
but cppcheck complains that it has no definition for the macro and I have stopped using it. :-(