setversion.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env python3
  2. # Python program to set the version.
  3. ##############################################
  4. import re
  5. import sys
  6. import optparse
  7. def fileProcess( name, lineFunction ):
  8. filestream = open( name, 'r' )
  9. if filestream.closed:
  10. print( "file " + name + " not open." )
  11. return
  12. output = ""
  13. print( "--- Processing " + name + " ---------" )
  14. while 1:
  15. line = filestream.readline()
  16. if not line: break
  17. output += lineFunction( line )
  18. filestream.close()
  19. if not output: return # basic error checking
  20. print( "Writing file " + name )
  21. filestream = open( name, "w" );
  22. filestream.write( output );
  23. filestream.close()
  24. def echoInput( line ):
  25. return line
  26. parser = optparse.OptionParser( "usage: %prog major minor build" )
  27. (options, args) = parser.parse_args()
  28. if len(args) != 3:
  29. parser.error( "incorrect number of arguments" );
  30. major = args[0]
  31. minor = args[1]
  32. build = args[2]
  33. versionStr = major + "." + minor + "." + build
  34. print ("Setting dox,tinyxml2.h")
  35. print ("Version: " + major + "." + minor + "." + build)
  36. #### Write the tinyxml.h ####
  37. def engineRule( line ):
  38. matchMajor = "static const int TIXML2_MAJOR_VERSION"
  39. matchMinor = "static const int TIXML2_MINOR_VERSION"
  40. matchBuild = "static const int TIXML2_PATCH_VERSION"
  41. if line[0:len(matchMajor)] == matchMajor:
  42. print( "1)tinyxml2.h Major found" )
  43. return matchMajor + " = " + major + ";\n"
  44. elif line[0:len(matchMinor)] == matchMinor:
  45. print( "2)tinyxml2.h Minor found" )
  46. return matchMinor + " = " + minor + ";\n"
  47. elif line[0:len(matchBuild)] == matchBuild:
  48. print( "3)tinyxml2.h Build found" )
  49. return matchBuild + " = " + build + ";\n"
  50. else:
  51. return line;
  52. fileProcess( "tinyxml2.h", engineRule )
  53. def macroVersionRule( line ):
  54. matchMajor = "#define TINYXML2_MAJOR_VERSION"
  55. matchMinor = "#define TINYXML2_MINOR_VERSION"
  56. matchBuild = "#define TINYXML2_PATCH_VERSION"
  57. if line[0:len(matchMajor)] == matchMajor:
  58. print( "1)macro Major found" )
  59. return matchMajor + " " + major + "\n"
  60. elif line[0:len(matchMinor)] == matchMinor:
  61. print( "2)macro Minor found" )
  62. return matchMinor + " " + minor + "\n"
  63. elif line[0:len(matchBuild)] == matchBuild:
  64. print( "3)macro Build found" )
  65. return matchBuild + " " + build + "\n"
  66. else:
  67. return line;
  68. fileProcess("tinyxml2.h", macroVersionRule)
  69. #### Write the dox ####
  70. def doxRule( line ):
  71. match = "PROJECT_NUMBER"
  72. if line[0:len( match )] == match:
  73. print( "dox project found" )
  74. return "PROJECT_NUMBER = " + major + "." + minor + "." + build + "\n"
  75. else:
  76. return line;
  77. fileProcess( "dox", doxRule )
  78. #### Write the CMakeLists.txt ####
  79. def cmakeRule( line ):
  80. matchVersion = "project(tinyxml2 VERSION"
  81. if line[0:len(matchVersion)] == matchVersion:
  82. print( "1)tinyxml2.h Major found" )
  83. return matchVersion + " " + major + "." + minor + "." + build + ")\n"
  84. else:
  85. return line;
  86. fileProcess( "CMakeLists.txt", cmakeRule )
  87. def mesonRule(line):
  88. match = re.search(r"(\s*version) : '(\d+.\d+.\d+)',", line)
  89. if match:
  90. print("1)meson.build version found.")
  91. return "{} : '{}.{}.{}',\n".format(match.group(1), major, minor, build)
  92. return line
  93. fileProcess("meson.build", mesonRule)
  94. print( "Release note:" )
  95. print( '1. Build. g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
  96. print( '2. Commit. git commit -am"setting the version to ' + versionStr + '"' )
  97. print( '3. Tag. git tag ' + versionStr )
  98. print( ' OR git tag -a ' + versionStr + ' -m [tag message]' )
  99. print( 'Remember to "git push" both code and tag. For the tag:' )
  100. print( 'git push origin [tagname]')