klusta-team/klustakwik

Print latest commit number into log file

Closed this issue · 10 comments

Currently there's no way of knowing which version of the program was used.

In SVN you could have the revision number inserted into a string in the code using an SVN hook. Is there a way to do something similar with github?

Yep, although git hook probably not the best way of doing it.

I'd suggest something like this: http://stackoverflow.com/a/12368262/3134487

You want to do it or shall I?

I just checked your code for this (the print_version branch) and it works on Windows in the case where git is not present. I didn't check for the case when git exists because I don't have a command line version of git on my Windows machine! On the other hand, it won't work when building with MSVC because it doesn't use the makefile so VERSION is not defined. We should have the fallback defined in the C++ code rather than in the makefile, e.g.

#ifndef VERSION
#define VERSION 0.3.0
#endif

This fallback should only be in one place.

Maybe there is also a solution for MSVC to get the git information, but I don't know what it is.

I wonder if we could include the git describe code in KlustaKwik itself? i.e. it tries running that command and copying the output and if it fails falls back? That way it would work for both MSVC and gcc.

Yes to the ifndef. But shouldn't include the git describe code in KK.

  1. if the user compiles the binary then moves it somewhere else (like /usr/local/bin) the git command will fail
  2. more worryingly, if the user pulls a later version of KK or switches to a branch (but doesn't recompile) the code will report the wrong version (the binary will still be old, but will think it's newer).

Good points. OK, so too bad for MSVC I guess.

Actually, hm. Where will be the ifndef be? VERSION will always be defined if using the makefile. Or maybe I can put it in some conditional block...

It only needs to be in the file where VERSION is used.

Yes, but what I mean is that:

CFLAGS = -Wall -c -Wno-write-strings $(OPTIMISATIONS) -DVERSION=\"$(GIT_VERSION)\"

means that VERSION is always defined even if the git command fails (it's just ""). ... unless I'm wrong

That's OK: you won't use that makefile if you're on MSVC.