Lee Thomason | 2705731 | 2012-03-02 09:04:53 -0800 | [diff] [blame] | 1 | # Python program to set the version.
|
| 2 | ##############################################
|
| 3 |
|
| 4 | import re
|
| 5 | import sys
|
Lee Thomason | 5938e6f | 2014-03-15 15:00:54 -0700 | [diff] [blame^] | 6 | import optparse
|
Lee Thomason | 2705731 | 2012-03-02 09:04:53 -0800 | [diff] [blame] | 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 |
|
| 30 | def echoInput( line ):
|
| 31 | return line
|
| 32 |
|
Lee Thomason | 5938e6f | 2014-03-15 15:00:54 -0700 | [diff] [blame^] | 33 | parser = optparse.OptionParser( "usage: %prog major minor build" )
|
| 34 | (options, args) = parser.parse_args()
|
| 35 | if len(args) != 3:
|
| 36 | parser.error( "incorrect number of arguments" );
|
| 37 |
|
| 38 | major = args[0]
|
| 39 | minor = args[1]
|
| 40 | build = args[2]
|
| 41 | versionStr = major + "." + minor + "." + build
|
Lee Thomason | 2705731 | 2012-03-02 09:04:53 -0800 | [diff] [blame] | 42 |
|
| 43 | print "Setting dox,tinyxml2.h"
|
| 44 | print "Version: " + `major` + "." + `minor` + "." + `build`
|
| 45 |
|
| 46 | #### Write the tinyxml.h ####
|
| 47 |
|
| 48 | def engineRule( line ):
|
| 49 |
|
| 50 | matchMajor = "static const int TIXML2_MAJOR_VERSION"
|
| 51 | matchMinor = "static const int TIXML2_MINOR_VERSION"
|
| 52 | matchBuild = "static const int TIXML2_PATCH_VERSION"
|
| 53 |
|
| 54 | if line[0:len(matchMajor)] == matchMajor:
|
| 55 | print "1)tinyxml2.h Major found"
|
| 56 | return matchMajor + " = " + `major` + ";\n"
|
| 57 |
|
| 58 | elif line[0:len(matchMinor)] == matchMinor:
|
| 59 | print "2)tinyxml2.h Minor found"
|
| 60 | return matchMinor + " = " + `minor` + ";\n"
|
| 61 |
|
| 62 | elif line[0:len(matchBuild)] == matchBuild:
|
| 63 | print "3)tinyxml2.h Build found"
|
| 64 | return matchBuild + " = " + `build` + ";\n"
|
| 65 |
|
| 66 | else:
|
| 67 | return line;
|
| 68 |
|
| 69 | fileProcess( "tinyxml2.h", engineRule )
|
| 70 |
|
| 71 |
|
| 72 | #### Write the dox ####
|
| 73 |
|
| 74 | def doxRule( line ):
|
| 75 |
|
| 76 | match = "PROJECT_NUMBER"
|
| 77 |
|
| 78 | if line[0:len( match )] == match:
|
| 79 | print "dox project found"
|
| 80 | return "PROJECT_NUMBER = " + `major` + "." + `minor` + "." + `build` + "\n"
|
| 81 |
|
| 82 | else:
|
| 83 | return line;
|
| 84 |
|
| 85 | fileProcess( "dox", doxRule )
|
| 86 |
|
hasufell | aba89e3 | 2012-05-14 23:59:42 +0200 | [diff] [blame] | 87 |
|
| 88 | #### Write the CMakeLists.txt ####
|
| 89 |
|
| 90 | def cmakeRule1( line ):
|
| 91 |
|
| 92 | matchVersion = "set(GENERIC_LIB_VERSION"
|
| 93 |
|
| 94 | if line[0:len(matchVersion)] == matchVersion:
|
| 95 | print "1)tinyxml2.h Major found"
|
| 96 | return matchVersion + " \"" + `major` + "." + `minor` + "." + `build` + "\")" + "\n"
|
| 97 |
|
| 98 | else:
|
| 99 | return line;
|
| 100 |
|
| 101 | fileProcess( "CMakeLists.txt", cmakeRule1 )
|
| 102 |
|
| 103 | def cmakeRule2( line ):
|
| 104 |
|
| 105 | matchSoversion = "set(GENERIC_LIB_SOVERSION"
|
| 106 |
|
| 107 | if line[0:len(matchSoversion)] == matchSoversion:
|
| 108 | print "1)tinyxml2.h Major found"
|
| 109 | return matchSoversion + " \"" + `major` + "\")" + "\n"
|
| 110 |
|
| 111 | else:
|
| 112 | return line;
|
| 113 |
|
| 114 | fileProcess( "CMakeLists.txt", cmakeRule2 )
|
Lee Thomason | 5938e6f | 2014-03-15 15:00:54 -0700 | [diff] [blame^] | 115 |
|
| 116 | print( "Release note:" )
|
| 117 | print( '1. Build. Ex: g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
|
| 118 | print( '2. Commit. git commit -am"setting the version to ` + versionStr + '" )
|
| 119 | print( '3. Tag. git tag ' + versionStr )
|