attempt to make buildnum.py generate a useful header
authorDiane Trout <diane@caltech.edu>
Tue, 17 Oct 2006 21:55:42 +0000 (21:55 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 17 Oct 2006 21:55:42 +0000 (21:55 +0000)
alas I couldn't get the CMake script to work reasonably well.

makelib/buildnum.py

index 863ce85cf787d6a395fd7509db3ac58f12edd913..bd496ea9871b7c5efe649b9c73f72bcf885ab575 100644 (file)
@@ -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