Newer gcc swallow version control keywords

Newer gcc swallow version control keywords

Elazar Leibovich elazarl at gmail.com
Tue Oct 18 12:11:56 IST 2011


On Tue, Oct 18, 2011 at 11:50 AM, Nadav Har'El <nyh at math.technion.ac.il>wrote:

> On Tue, Oct 18, 2011, Elazar Leibovich wrote about "Re: Newer gcc swallow
> version control keywords":
> > Excuse the idiotic solution, but can't you just add an option to print it
> > out?
> >
> > int main(int argc,char**argv) {if (argc == 2 && strcmp(argv[1],"--ident")
> > puts(ident);...}
>
> The point in Oleg's trick (which is not Oleg's invention - it has been in
> use for decades) is to be able to tell not just a single version number for
> the executable (your "--ident" is basically the same as "--version"
> supported
> by many programs), but rather to be able to tell the exact version of each
> and every source code file which participated in creating this executable.
> You run "ident" on the executable, and get a list of dozens (or thousands)
> of source file names and their exact version numbers and dates. This could
> be useful if you have a lot of versions of your code running around, and
> you don't remember how exactly each executable was generated.
>

I didn't understand that, but anyhow. Same idea could apply.

For C++:
main.cc:
vector<string> __files;
int main(int argc,char**argv) {if (argc == 2 && string(argv)=="--ident")
{for (auto file:__files) cout << file << "\n";exit(0);}}

fileversion.h:
class FileVersion {FileVersion(const string& v){__files.push_back(v);}};

foo.cc:
static const FileVersion foo("$id$");

With some macro trickery you might be able to get .init-like behaviour for
C. (If you're willing to preprocess the C files with another utility, like
you do to replace the $Id$ strings, it's actually not hard at all).

This way, it's not ad-hoc, but a documented working way to get whatever you
want in the executable.

(I perfectly agree with you that today it's less relevant, but I'm taking
Oleg's stance for the sake of the discussion)


>
>
> > It seems like a good idea anyhow, to have a stable way of extracting this
> > ident string from the executable (what happens for instance if by
> accident
> > you have rcsident and rcs_ident? How would you know from the stripped
> > executable which one to trust?).
>
> The idea with ident(1) is that the content of the string, not the variable
> name holding it, has a recognizeable structure. In particular, it looks
> like
> this: $Id: something $ - with the word "something" replaced by anything you
> wish. ident(1) looks for such strings in any file you give it - whether it
> is an executable, source code, or whatever, and prints them.
>

I understood that, and it's still unstable. Since if some young team member
not aware of the $Id: trick, will write:
    log("$Id: %d $Name: %s\n",id,name)
ident will return garbage.
If you have documented way to get the ident strings, it's more stable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20111018/3bb87feb/attachment.html>


More information about the Linux-il mailing list