You can come pretty close without pointing at the actual git objects:

$ cat Tupfile
: foo.c |> gcc -DREV=\"`git rev-parse HEAD`\" %f -o foo |> %B
$ cat foo.c
#include <stdio.h>

#ifndef REV
#define REV "No Rev!"
#endif

int main() {
        printf("Rev: %s\n", REV);
        return 0;
}
$ tup && ./foo
[ tup ] [0.000s] Scanning filesystem...
[ tup ] [0.000s] Reading in new environment variables...
[ tup ] [0.000s] No Tupfiles to parse.
[ tup ] [0.000s] No files to delete.
[ tup ] [0.000s] No commands to execute.
[ tup ] [0.000s] Updated.
Rev: 2acfd44823c503c2fde71acb5ef0a16abc5cb26f

Now, with this approach, if something in git changes that isn’t in the 
dependency graph, the built output won’t get updated. At the same time, I’m not 
convinced that really matters. Using either commit would (by definition) create 
the same resulting executable. If the executable really in some way depends on 
something then it should be listed as an order-only input to tup, which will 
cause tup to rebuild whenever it changes.

HTH,

-Pat


On May 13, 2014 at 17:33:19, Gábor Márton ([email protected]) wrote:

Hi,

I am trying to make a header which depends on the actual git hash. It would be 
also nice to indicate whether the repo is dirty or not. 
(This would be handy because we could generate a log entry which contains our 
deployed process' version. We might have more prcocesses with different 
versions deployed.)
So far I've got the following:
strace -e trace=open git rev-parse HEAD
...
open(".git/HEAD", O_RDONLY)             = 3
open(".git/refs/heads/gitHash", O_RDONLY) = 3
open(".git/packed-refs", O_RDONLY)      = 3
...

Therefore I tried with this Tupfile:
include_rules
: $(PROJECT_ROOT)/.git/HEAD $(PROJECT_ROOT)/.git/refs/heads/* 
$(PROJECT_ROOT)/.git/packed-refs |> ./gitstuff.sh > %o |> gitHash.h
PROJECT_ROOT is defined in the upper most Tupfile. gitstuff is the script which 
wraps git rev-parse.

But tup upd is not willing to handle any hidden files. :(

So my next idea was to create a symlink of .git (ln -s .git git) and replace 
'.git' with 'git' in the Tupfile. However I've got the following error:
tup error: Expected node 'refs' to be in directory 'git', but it is not there.
tup error: Failed to find directory ID for dir '../git/refs/heads/*' relative 
to 518

Any idea how to move on? Is it possible at all to do such thing with tup?

Many Thanks,
Gábor



--
--
tup-users mailing list
email: [email protected]
unsubscribe: [email protected]
options: http://groups.google.com/group/tup-users?hl=en
---
You received this message because you are subscribed to the Google Groups 
"tup-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

-- 
-- 
tup-users mailing list
email: [email protected]
unsubscribe: [email protected]
options: http://groups.google.com/group/tup-users?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"tup-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to