makeversion.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Copyright (C) 1999-2006 Id Software, Inc. and contributors.
  2. # For a list of contributors, see the accompanying CONTRIBUTORS file.
  3. #
  4. # This file is part of GtkRadiant.
  5. #
  6. # GtkRadiant is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GtkRadiant is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GtkRadiant; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. # version and about message management
  20. # NOTE: this module is meant to be used on all platforms, it is not SCons centric
  21. # version:
  22. # input:
  23. # include/version.default
  24. # output:
  25. # include/version.h include/RADIANT_MAJOR include/RADIANT_MINOR
  26. # the header is used by C/C++ code, the straight text file by setup
  27. # about message
  28. # for non-official builds, we have a default message
  29. # otherwise, use environment variable $RADIANT_ABOUTMSG
  30. # input:
  31. # file pointed to by $RADIANT_ABOUTMSG if exists
  32. # else include/aboutmsg.default
  33. # ouput:
  34. # include/aboutmsg.h
  35. import sys, re, string, os
  36. import svn
  37. def get_version():
  38. # version
  39. f = open('include/version.default', 'r')
  40. buffer = f.read()
  41. line = string.split(buffer, '\n')[0]
  42. f.close()
  43. sys.stdout.write("version: %s\n" % line)
  44. exp = re.compile('^1\\.([^\\.]*)\\.([0-9]*)')
  45. (major, minor) = exp.findall(line)[0]
  46. sys.stdout.write("minor: %s major: %s\n" % (minor, major))
  47. return (line, major, minor)
  48. # you can pass an optional message to append to aboutmsg
  49. def radiant_makeversion(append_about):
  50. (line, major, minor) = get_version()
  51. f = open('include/version.h', 'w')
  52. f.write('// generated header, see makeversion.py\n')
  53. f.write('#define RADIANT_VERSION "%s"\n' % line)
  54. f.write('#define RADIANT_MINOR_VERSION "%s"\n' % minor)
  55. f.write('#define RADIANT_MAJOR_VERSION "%s"\n' % major)
  56. f.close()
  57. f = open('include/RADIANT_MINOR', 'w')
  58. f.write(minor)
  59. f.close()
  60. f = open('include/RADIANT_MAJOR', 'w')
  61. f.write(major)
  62. f.close()
  63. f = open('include/version', 'w')
  64. f.write(line)
  65. f.close()
  66. # aboutmsg
  67. aboutfile = 'include/aboutmsg.default'
  68. if ( os.environ.has_key('RADIANT_ABOUTMSG') ):
  69. aboutfile = os.environ['RADIANT_ABOUTMSG']
  70. line = None
  71. if os.path.isfile(aboutfile):
  72. sys.stdout.write("about message is in %s\n" % aboutfile)
  73. f = open(aboutfile, 'r')
  74. line = f.readline()
  75. f.close()
  76. else:
  77. line = "Custom build based on revision " + str(svn.getRevision(os.getcwd()))
  78. # optional additional message
  79. if ( not append_about is None ):
  80. line += append_about
  81. sys.stdout.write("about: %s\n" % line)
  82. f = open('include/aboutmsg.h', 'w')
  83. f.write('// generated header, see makeversion.py\n')
  84. f.write('#define RADIANT_ABOUTMSG "%s"\n' % line)
  85. f.close()
  86. # can be used as module (scons build), or by direct call
  87. if __name__ == '__main__':
  88. radiant_makeversion(None)