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