3

I'm building a project with tup and would like to include the current commit's SHA into the binary. The problem is that tup doesn't recognize dependencies in the .git directory and the version file is not rebuild when the git HEAD changes.

The problematic Tupfile contains:

: |> git rev-parse HEAD > %o |> version-file

The problem looks like this:

% tup
[...]
[ tup ] [0.068s] Executing Commands...
 1) [0.026s] git rev-parse HEAD > version-file                                                                                                                                                                    
 [ ] 100%
% git commit --allow-empty -m "Some commit"
[master b9a0874] Some commit
% tup
[ tup ] [0.000s] Scanning filesystem...
[ tup ] [0.001s] Reading in new environment variables...
[ tup ] [0.001s] No Tupfiles to parse.
[ tup ] [0.001s] No files to delete.
[ tup ] [0.001s] No commands to execute.
[ tup ] [0.001s] Updated.

Adding any files in .git as a dependencies results in:

tup error: You specified a path '.git/refs/heads/*' that contains a hidden filename (since it begins with a '.' character). Tup ignores these files - please remove references to it from the Tupfile.

How do I make tup rebuild version-file when the current Git commit changes?

Julian Stecklina
  • 1,271
  • 1
  • 10
  • 24
  • Know nothing about tup. I guess the version file is not rebuilt because no file under the repository except `.git` is touched when an empty commit is created. If true, touch a file after making the empty commit. But then why would you like an empty commit? If a hidden file name is ignored by tup, how about copying `.git/refs/heads/*` into a non-hidden path? – ElpieKay Aug 01 '17 at 02:05
  • The `git rev-parse` in the question has no dependencies in the actual git repository except the meta data. So changing files will not cause the command to be re-executed. Depending on `.git/refs/heads` may work, but is pretty ugly because it relies on implementation details of git. I'm looking more for the equivalent of phony targets in make. – Julian Stecklina May 23 '18 at 21:28

1 Answers1

0

Have you looked at the run ./script args functionality? You could have a rule in your Tupfile saying run generate_git_rule.sh, and in that shell script, you could first update a file with the git revision you want, and then specify that as an input for your actual rule.

parthy
  • 1
  • Emitting a rule that contains the Git revision doesn't work, because the script is not evaluated again when HEAD changes. Directly writing a file from a run script results in: `./gitrev.sh: line 6: gitrev.h: Operation not permitted` – Julian Stecklina Mar 15 '19 at 18:20