Narayan Kamath | 74c03bb | 2017-12-22 10:59:43 +0000 | [diff] [blame] | 1 | # Python program to set the version.
|
| 2 | ##############################################
|
| 3 |
|
| 4 | import re
|
| 5 | import sys
|
| 6 | import optparse
|
| 7 |
|
| 8 | def fileProcess( name, lineFunction ):
|
| 9 | filestream = open( name, 'r' )
|
| 10 | if filestream.closed:
|
| 11 | print( "file " + name + " not open." )
|
| 12 | return
|
| 13 |
|
| 14 | output = ""
|
| 15 | print( "--- Processing " + name + " ---------" )
|
| 16 | while 1:
|
| 17 | line = filestream.readline()
|
| 18 | if not line: break
|
| 19 | output += lineFunction( line )
|
| 20 | filestream.close()
|
| 21 |
|
| 22 | if not output: return # basic error checking
|
| 23 |
|
| 24 | print( "Writing file " + name )
|
| 25 | filestream = open( name, "w" );
|
| 26 | filestream.write( output );
|
| 27 | filestream.close()
|
| 28 |
|
| 29 | def echoInput( line ):
|
| 30 | return line
|
| 31 |
|
| 32 | parser = optparse.OptionParser( "usage: %prog major minor build" )
|
| 33 | (options, args) = parser.parse_args()
|
| 34 | if len(args) != 3:
|
| 35 | parser.error( "incorrect number of arguments" );
|
| 36 |
|
| 37 | major = args[0]
|
| 38 | minor = args[1]
|
| 39 | build = args[2]
|
| 40 | versionStr = major + "." + minor + "." + build
|
| 41 |
|
| 42 | print ("Setting dox,tinyxml2.h")
|
| 43 | print ("Version: " + major + "." + minor + "." + build)
|
| 44 |
|
| 45 | #### Write the tinyxml.h ####
|
| 46 |
|
| 47 | def engineRule( line ):
|
| 48 |
|
| 49 | matchMajor = "static const int TIXML2_MAJOR_VERSION"
|
| 50 | matchMinor = "static const int TIXML2_MINOR_VERSION"
|
| 51 | matchBuild = "static const int TIXML2_PATCH_VERSION"
|
| 52 |
|
| 53 | if line[0:len(matchMajor)] == matchMajor:
|
| 54 | print( "1)tinyxml2.h Major found" )
|
| 55 | return matchMajor + " = " + major + ";\n"
|
| 56 |
|
| 57 | elif line[0:len(matchMinor)] == matchMinor:
|
| 58 | print( "2)tinyxml2.h Minor found" )
|
| 59 | return matchMinor + " = " + minor + ";\n"
|
| 60 |
|
| 61 | elif line[0:len(matchBuild)] == matchBuild:
|
| 62 | print( "3)tinyxml2.h Build found" )
|
| 63 | return matchBuild + " = " + build + ";\n"
|
| 64 |
|
| 65 | else:
|
| 66 | return line;
|
| 67 |
|
| 68 | fileProcess( "tinyxml2.h", engineRule )
|
| 69 |
|
| 70 |
|
| 71 | #### Write the dox ####
|
| 72 |
|
| 73 | def doxRule( line ):
|
| 74 |
|
| 75 | match = "PROJECT_NUMBER"
|
| 76 |
|
| 77 | if line[0:len( match )] == match:
|
| 78 | print( "dox project found" )
|
| 79 | return "PROJECT_NUMBER = " + major + "." + minor + "." + build + "\n"
|
| 80 |
|
| 81 | else:
|
| 82 | return line;
|
| 83 |
|
| 84 | fileProcess( "dox", doxRule )
|
| 85 |
|
| 86 |
|
| 87 | #### Write the CMakeLists.txt ####
|
| 88 |
|
| 89 | def cmakeRule1( line ):
|
| 90 |
|
| 91 | matchVersion = "set(GENERIC_LIB_VERSION"
|
| 92 |
|
| 93 | if line[0:len(matchVersion)] == matchVersion:
|
| 94 | print( "1)tinyxml2.h Major found" )
|
| 95 | return matchVersion + " \"" + major + "." + minor + "." + build + "\")" + "\n"
|
| 96 |
|
| 97 | else:
|
| 98 | return line;
|
| 99 |
|
| 100 | fileProcess( "CMakeLists.txt", cmakeRule1 )
|
| 101 |
|
| 102 | def cmakeRule2( line ):
|
| 103 |
|
| 104 | matchSoversion = "set(GENERIC_LIB_SOVERSION"
|
| 105 |
|
| 106 | if line[0:len(matchSoversion)] == matchSoversion:
|
| 107 | print( "1)tinyxml2.h Major found" )
|
| 108 | return matchSoversion + " \"" + major + "\")" + "\n"
|
| 109 |
|
| 110 | else:
|
| 111 | return line;
|
| 112 |
|
| 113 | fileProcess( "CMakeLists.txt", cmakeRule2 )
|
| 114 |
|
| 115 | print( "Release note:" )
|
| 116 | print( '1. Build. g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
|
| 117 | print( '2. Commit. git commit -am"setting the version to ' + versionStr + '"' )
|
| 118 | print( '3. Tag. git tag ' + versionStr )
|
| 119 | print( ' OR git tag -a ' + versionStr + ' -m [tag message]' )
|
| 120 | print( 'Remember to "git push" both code and tag. For the tag:' )
|
| 121 | print( 'git push origin [tagname]')
|
| 122 |
|
| 123 | |