xref: /aosp_15_r20/external/tinyxml2/setversion.py (revision 7485b22521f577cf944e5687361548d8993d8d2c)
1*7485b225SElliott Hughes#!/usr/bin/env python3
2*7485b225SElliott Hughes# Python program to set the version.
3*7485b225SElliott Hughes##############################################
4*7485b225SElliott Hughes
5*7485b225SElliott Hughesimport re
6*7485b225SElliott Hughesimport sys
7*7485b225SElliott Hughesimport optparse
8*7485b225SElliott Hughes
9*7485b225SElliott Hughesdef fileProcess( name, lineFunction ):
10*7485b225SElliott Hughes	filestream = open( name, 'r' )
11*7485b225SElliott Hughes	if filestream.closed:
12*7485b225SElliott Hughes		print( "file " + name + " not open." )
13*7485b225SElliott Hughes		return
14*7485b225SElliott Hughes
15*7485b225SElliott Hughes	output = ""
16*7485b225SElliott Hughes	print( "--- Processing " + name + " ---------" )
17*7485b225SElliott Hughes	while 1:
18*7485b225SElliott Hughes		line = filestream.readline()
19*7485b225SElliott Hughes		if not line: break
20*7485b225SElliott Hughes		output += lineFunction( line )
21*7485b225SElliott Hughes	filestream.close()
22*7485b225SElliott Hughes
23*7485b225SElliott Hughes	if not output: return			# basic error checking
24*7485b225SElliott Hughes
25*7485b225SElliott Hughes	print( "Writing file " + name )
26*7485b225SElliott Hughes	filestream = open( name, "w" );
27*7485b225SElliott Hughes	filestream.write( output );
28*7485b225SElliott Hughes	filestream.close()
29*7485b225SElliott Hughes
30*7485b225SElliott Hughesdef echoInput( line ):
31*7485b225SElliott Hughes	return line
32*7485b225SElliott Hughes
33*7485b225SElliott Hughesparser = optparse.OptionParser( "usage: %prog major minor build" )
34*7485b225SElliott Hughes(options, args) = parser.parse_args()
35*7485b225SElliott Hughesif len(args) != 3:
36*7485b225SElliott Hughes	parser.error( "incorrect number of arguments" );
37*7485b225SElliott Hughes
38*7485b225SElliott Hughesmajor = args[0]
39*7485b225SElliott Hughesminor = args[1]
40*7485b225SElliott Hughesbuild = args[2]
41*7485b225SElliott HughesversionStr = major + "." + minor + "." + build
42*7485b225SElliott Hughes
43*7485b225SElliott Hughesprint ("Setting dox,tinyxml2.h")
44*7485b225SElliott Hughesprint ("Version: " + major + "." + minor + "." + build)
45*7485b225SElliott Hughes
46*7485b225SElliott Hughes#### Write the tinyxml.h ####
47*7485b225SElliott Hughes
48*7485b225SElliott Hughesdef engineRule( line ):
49*7485b225SElliott Hughes
50*7485b225SElliott Hughes	matchMajor = "static const int TIXML2_MAJOR_VERSION"
51*7485b225SElliott Hughes	matchMinor = "static const int TIXML2_MINOR_VERSION"
52*7485b225SElliott Hughes	matchBuild = "static const int TIXML2_PATCH_VERSION"
53*7485b225SElliott Hughes
54*7485b225SElliott Hughes	if line[0:len(matchMajor)] == matchMajor:
55*7485b225SElliott Hughes		print( "1)tinyxml2.h Major found" )
56*7485b225SElliott Hughes		return matchMajor + " = " + major + ";\n"
57*7485b225SElliott Hughes
58*7485b225SElliott Hughes	elif line[0:len(matchMinor)] == matchMinor:
59*7485b225SElliott Hughes		print( "2)tinyxml2.h Minor found" )
60*7485b225SElliott Hughes		return matchMinor + " = " + minor + ";\n"
61*7485b225SElliott Hughes
62*7485b225SElliott Hughes	elif line[0:len(matchBuild)] == matchBuild:
63*7485b225SElliott Hughes		print( "3)tinyxml2.h Build found" )
64*7485b225SElliott Hughes		return matchBuild + " = " + build + ";\n"
65*7485b225SElliott Hughes
66*7485b225SElliott Hughes	else:
67*7485b225SElliott Hughes		return line;
68*7485b225SElliott Hughes
69*7485b225SElliott HughesfileProcess( "tinyxml2.h", engineRule )
70*7485b225SElliott Hughes
71*7485b225SElliott Hughesdef macroVersionRule( line ):
72*7485b225SElliott Hughes
73*7485b225SElliott Hughes	matchMajor = "#define TINYXML2_MAJOR_VERSION"
74*7485b225SElliott Hughes	matchMinor = "#define TINYXML2_MINOR_VERSION"
75*7485b225SElliott Hughes	matchBuild = "#define TINYXML2_PATCH_VERSION"
76*7485b225SElliott Hughes
77*7485b225SElliott Hughes	if line[0:len(matchMajor)] == matchMajor:
78*7485b225SElliott Hughes		print( "1)macro Major found" )
79*7485b225SElliott Hughes		return matchMajor + " " + major + "\n"
80*7485b225SElliott Hughes
81*7485b225SElliott Hughes	elif line[0:len(matchMinor)] == matchMinor:
82*7485b225SElliott Hughes		print( "2)macro Minor found" )
83*7485b225SElliott Hughes		return matchMinor + " " + minor + "\n"
84*7485b225SElliott Hughes
85*7485b225SElliott Hughes	elif line[0:len(matchBuild)] == matchBuild:
86*7485b225SElliott Hughes		print( "3)macro Build found" )
87*7485b225SElliott Hughes		return matchBuild + " " + build + "\n"
88*7485b225SElliott Hughes
89*7485b225SElliott Hughes	else:
90*7485b225SElliott Hughes		return line;
91*7485b225SElliott Hughes
92*7485b225SElliott HughesfileProcess("tinyxml2.h", macroVersionRule)
93*7485b225SElliott Hughes
94*7485b225SElliott Hughes#### Write the dox ####
95*7485b225SElliott Hughes
96*7485b225SElliott Hughesdef doxRule( line ):
97*7485b225SElliott Hughes
98*7485b225SElliott Hughes	match = "PROJECT_NUMBER"
99*7485b225SElliott Hughes
100*7485b225SElliott Hughes	if line[0:len( match )] == match:
101*7485b225SElliott Hughes		print( "dox project found" )
102*7485b225SElliott Hughes		return "PROJECT_NUMBER = " + major + "." + minor + "." + build + "\n"
103*7485b225SElliott Hughes
104*7485b225SElliott Hughes	else:
105*7485b225SElliott Hughes		return line;
106*7485b225SElliott Hughes
107*7485b225SElliott HughesfileProcess( "dox", doxRule )
108*7485b225SElliott Hughes
109*7485b225SElliott Hughes
110*7485b225SElliott Hughes#### Write the CMakeLists.txt ####
111*7485b225SElliott Hughes
112*7485b225SElliott Hughesdef cmakeRule( line ):
113*7485b225SElliott Hughes
114*7485b225SElliott Hughes	matchVersion = "project(tinyxml2 VERSION"
115*7485b225SElliott Hughes
116*7485b225SElliott Hughes	if line[0:len(matchVersion)] == matchVersion:
117*7485b225SElliott Hughes		print( "1)tinyxml2.h Major found" )
118*7485b225SElliott Hughes		return matchVersion + " " + major + "." + minor + "." + build + ")\n"
119*7485b225SElliott Hughes
120*7485b225SElliott Hughes	else:
121*7485b225SElliott Hughes		return line;
122*7485b225SElliott Hughes
123*7485b225SElliott HughesfileProcess( "CMakeLists.txt", cmakeRule )
124*7485b225SElliott Hughes
125*7485b225SElliott Hughes
126*7485b225SElliott Hughesdef mesonRule(line):
127*7485b225SElliott Hughes	match = re.search(r"(\s*version) : '(\d+.\d+.\d+)',", line)
128*7485b225SElliott Hughes	if match:
129*7485b225SElliott Hughes		print("1)meson.build version found.")
130*7485b225SElliott Hughes		return "{} : '{}.{}.{}',\n".format(match.group(1), major, minor, build)
131*7485b225SElliott Hughes	return line
132*7485b225SElliott Hughes
133*7485b225SElliott HughesfileProcess("meson.build", mesonRule)
134*7485b225SElliott Hughes
135*7485b225SElliott Hughesprint( "Release note:" )
136*7485b225SElliott Hughesprint( '1. Build.   g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe' )
137*7485b225SElliott Hughesprint( '2. Commit.  git commit -am"setting the version to ' + versionStr + '"' )
138*7485b225SElliott Hughesprint( '3. Tag.     git tag ' + versionStr )
139*7485b225SElliott Hughesprint( '   OR       git tag -a ' + versionStr + ' -m [tag message]' )
140*7485b225SElliott Hughesprint( 'Remember to "git push" both code and tag. For the tag:' )
141*7485b225SElliott Hughesprint( 'git push origin [tagname]')
142