setversion.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Python program to set the version.
  2. ##############################################
  3. import re
  4. import sys
  5. import optparse
  6. def fileProcess( name, lineFunction ):
  7. filestream = open( name, 'r' )
  8. if filestream.closed:
  9. print( "file " + name + " not open." )
  10. return
  11. output = ""
  12. print( "--- Processing " + name + " ---------" )
  13. while 1:
  14. line = filestream.readline()
  15. if not line: break
  16. output += lineFunction( line )
  17. filestream.close()
  18. if not output: return # basic error checking
  19. print( "Writing file " + name )
  20. filestream = open( name, "w" );
  21. filestream.write( output );
  22. filestream.close()
  23. def echoInput( line ):
  24. return line
  25. parser = optparse.OptionParser( "usage: %prog major minor build" )
  26. (options, args) = parser.parse_args()
  27. if len(args) != 3:
  28. parser.error( "incorrect number of arguments" );
  29. major = args[0]
  30. minor = args[1]
  31. build = args[2]
  32. versionStr = major + "." + minor + "." + build
  33. print "Setting dox,tinyxml2.h"
  34. print "Version: " + `major` + "." + `minor` + "." + `build`
  35. #### Write the tinyxml.h ####
  36. def engineRule( line ):
  37. matchMajor = "static const int TIXML2_MAJOR_VERSION"
  38. matchMinor = "static const int TIXML2_MINOR_VERSION"
  39. matchBuild = "static const int TIXML2_PATCH_VERSION"
  40. if line[0:len(matchMajor)] == matchMajor:
  41. print "1)tinyxml2.h Major found"
  42. return matchMajor + " = " + `major` + ";\n"
  43. elif line[0:len(matchMinor)] == matchMinor:
  44. print "2)tinyxml2.h Minor found"
  45. return matchMinor + " = " + `minor` + ";\n"
  46. elif line[0:len(matchBuild)] == matchBuild:
  47. print "3)tinyxml2.h Build found"
  48. return matchBuild + " = " + `build` + ";\n"
  49. else:
  50. return line;
  51. fileProcess( "tinyxml2.h", engineRule )
  52. #### Write the dox ####
  53. def doxRule( line ):
  54. match = "PROJECT_NUMBER"
  55. if line[0:len( match )] == match:
  56. print "dox project found"
  57. return "PROJECT_NUMBER = " + `major` + "." + `minor` + "." + `build` + "\n"
  58. else:
  59. return line;
  60. fileProcess( "dox", doxRule )
  61. #### Write the CMakeLists.txt ####
  62. def cmakeRule1( line ):
  63. matchVersion = "set(GENERIC_LIB_VERSION"
  64. if line[0:len(matchVersion)] == matchVersion:
  65. print "1)tinyxml2.h Major found"
  66. return matchVersion + " \"" + `major` + "." + `minor` + "." + `build` + "\")" + "\n"
  67. else:
  68. return line;
  69. fileProcess( "CMakeLists.txt", cmakeRule1 )
  70. def cmakeRule2( line ):
  71. matchSoversion = "set(GENERIC_LIB_SOVERSION"
  72. if line[0:len(matchSoversion)] == matchSoversion:
  73. print "1)tinyxml2.h Major found"
  74. return matchSoversion + " \"" + `major` + "\")" + "\n"
  75. else:
  76. return line;
  77. fileProcess( "CMakeLists.txt", cmakeRule2 )
  78. print( "Release note:" )
  79. print( '1. Build. Ex: g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
  80. print( '2. Commit. git commit -am"setting the version to ` + versionStr + '" )
  81. print( '3. Tag. git tag ' + versionStr )