From bd5aa6f3ef5c2969c719209270b5084c66147a1d Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 17 Oct 2006 21:55:42 +0000 Subject: [PATCH] attempt to make buildnum.py generate a useful header alas I couldn't get the CMake script to work reasonably well. --- makelib/buildnum.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/makelib/buildnum.py b/makelib/buildnum.py index 863ce85..bd496ea 100644 --- a/makelib/buildnum.py +++ b/makelib/buildnum.py @@ -1,5 +1,7 @@ #!/usr/bin/python +import getopt +import os import re import subprocess import sys @@ -16,5 +18,36 @@ def getBuildNumber(): build_num = len(_build_search.findall(data)) return build_num -if __name__ == '__main__': +def createVersionHeader(path): + """Create a header file contianing our version number. + """ + header = ['#ifdef _AUTOGEN_VERSION_HPP_', + '#define _AUTOGEN_VERSION_HPP_', + 'const char *app_version_id = "%s"' % (getBuildNumber()), + '#endif', + ''] + if os.path.exists(path): + # we need to see if its one of our headers + stream = open(path, 'r') + line = stream.readline().strip() + stream.close() + if line != header[0]: + raise RuntimeError("%s is not our header file" % path) + open(path,'w').writelines(os.linesep.join(header)) + +def main(arg_list): + """Basic command line driver script. + Call with something like sys.argv[1:] + """ + opts, args = getopt.getopt(arg_list, "h:", + ["header="]) + for option, argument in opts: + if option in ("-h", "--header"): + createVersionHeader(argument) + return 0 + print "%s" % (getBuildNumber()) + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) \ No newline at end of file -- 2.30.2