13 from xml.dom
import minidom
15 if len(sys.argv) < 2
or len(sys.argv) > 3:
17 [ERROR] Please specify a version.
19 ./update_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
22 ./update_version.py 3.7.1 2
26 NEW_VERSION = sys.argv[1]
27 NEW_VERSION_INFO = NEW_VERSION.split(
'.')
28 if len(NEW_VERSION_INFO) != 3:
30 [ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
33 ./update_version.py 3.7.3
39 RC_VERSION = int(sys.argv[2])
43 for child
in elem.childNodes:
44 if child.nodeName == tagname:
50 return Find(elem, tagname).cloneNode(
True)
54 elem.firstChild.replaceWholeText(text)
61 return '%s%s%s' % (NEW_VERSION, rc_suffix, RC_VERSION)
65 document = minidom.parse(filename)
71 content = document.toxml().replace(
'<?xml version="1.0" ?>',
'')
72 file_handle = open(filename,
'wb')
74 file_handle.write(
'<?xml version="1.0" encoding="UTF-8"?>\n')
75 file_handle.write(content)
76 file_handle.write(
'\n')
81 lines = open(filename,
'r').readlines()
84 updated_lines.append(line_rewriter(line))
85 if lines == updated_lines:
86 print '%s was not updated. Please double check.' % filename
87 f = open(filename,
'w')
88 f.write(
''.join(updated_lines))
95 r'^AC_INIT\(\[Protocol Buffers\],\[.*\],\[protobuf@googlegroups.com\],\[protobuf\]\)$',
96 (
'AC_INIT([Protocol Buffers],[%s],[protobuf@googlegroups.com],[protobuf])'
102 cpp_version =
'%s00%s00%s' % (
103 NEW_VERSION_INFO[0], NEW_VERSION_INFO[1], NEW_VERSION_INFO[2])
104 def RewriteCommon(line):
106 r'^#define GOOGLE_PROTOBUF_VERSION .*$',
107 '#define GOOGLE_PROTOBUF_VERSION %s' % cpp_version,
110 r'^#define PROTOBUF_VERSION .*$',
111 '#define PROTOBUF_VERSION %s' % cpp_version,
113 if NEW_VERSION_INFO[2] ==
'0':
115 r'^#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC .*$',
116 '#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC %s' % cpp_version,
119 r'^#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION .*$',
120 '#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION %s' % cpp_version,
123 r'^static const int kMinHeaderVersionForLibrary = .*$',
124 'static const int kMinHeaderVersionForLibrary = %s;' % cpp_version,
127 r'^static const int kMinHeaderVersionForProtoc = .*$',
128 'static const int kMinHeaderVersionForProtoc = %s;' % cpp_version,
131 def RewritePortDef(line):
133 r'^#define PROTOBUF_VERSION .*$',
134 '#define PROTOBUF_VERSION %s' % cpp_version,
136 if NEW_VERSION_INFO[2] ==
'0':
138 r'^#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC .*$',
139 '#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC %s' % cpp_version,
142 r'^#define PROTOBUF_MIN_PROTOC_VERSION .*$',
143 '#define PROTOBUF_MIN_PROTOC_VERSION %s' % cpp_version,
146 r'^#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION .*$',
147 '#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION %s' % cpp_version,
156 RewriteXml(
'csharp/src/Google.Protobuf/Google.Protobuf.csproj',
158 Find(
Find(document.documentElement,
'PropertyGroup'),
'VersionPrefix'),
160 add_xml_prefix=
False)
162 RewriteXml(
'csharp/Google.Protobuf.Tools.nuspec',
164 Find(
Find(document.documentElement,
'metadata'),
'version'),
179 Find(
Find(document.documentElement,
'parent'),
'version'),
184 Find(
Find(document.documentElement,
'parent'),
'version'),
189 Find(
Find(document.documentElement,
'parent'),
'version'),
199 lambda line : re.sub(
200 r'^ "version": ".*",$',
206 protobuf_version_offset = 11
207 expected_major_version =
'3'
208 if NEW_VERSION_INFO[0] != expected_major_version:
209 print """[ERROR] Major protobuf version has changed. Please update
210 update_version.py to readjust the protobuf_version_offset and
211 expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is
216 protobuf_version_info =
'%s:%s:0' % (
217 int(NEW_VERSION_INFO[1]) + protobuf_version_offset, NEW_VERSION_INFO[2])
219 lambda line : re.sub(
220 r'^PROTOBUF_VERSION = .*$',
221 'PROTOBUF_VERSION = %s' % protobuf_version_info,
227 lambda line : re.sub(
228 r"^ s.version = '.*'$",
234 def Callback(document):
235 def CreateNode(tagname, indent, children):
236 elem = document.createElement(tagname)
238 for child
in children:
239 elem.appendChild(document.createTextNode(
'\n' + (
' ' * indent)))
240 elem.appendChild(child)
242 elem.appendChild(document.createTextNode(
'\n' + (
' ' * indent)))
245 root = document.documentElement
246 now = datetime.datetime.now()
249 version =
Find(root,
'version')
252 stability =
Find(root,
'stability')
254 'stable' if RC_VERSION == 0
else 'beta')
255 ReplaceText(
Find(stability,
'api'),
'stable' if RC_VERSION == 0
else 'beta')
256 changelog =
Find(root,
'changelog')
257 for old_version
in changelog.getElementsByTagName(
'version'):
258 if Find(old_version,
'release').firstChild.nodeValue == NEW_VERSION:
259 print (
'[WARNING] Version %s already exists in the change log.'
262 changelog.appendChild(document.createTextNode(
' '))
263 release = CreateNode(
'release', 2, [
264 CreateNode(
'version', 3, [
268 CreateNode(
'stability', 3, [
277 changelog.appendChild(release)
278 changelog.appendChild(document.createTextNode(
'\n '))
279 RewriteXml(
'php/ext/google/protobuf/package.xml', Callback)
281 lambda line : re.sub(
282 r'PHP_PROTOBUF_VERSION ".*"$',
283 'PHP_PROTOBUF_VERSION "%s"' % NEW_VERSION,
287 lambda line : re.sub(
288 r"^#define PHP_PROTOBUF_VERSION .*$",
289 "#define PHP_PROTOBUF_VERSION \"%s\"" %
GetFullVersion(rc_suffix =
'RC'),
293 lambda line : re.sub(
294 r"^#define PHP_PROTOBUF_VERSION .*$",
295 "#define PHP_PROTOBUF_VERSION \"%s\"" %
GetFullVersion(rc_suffix =
'RC'),
300 lambda line : re.sub(
301 r"^__version__ = '.*'$",
307 lambda line : re.sub(
308 r'^ s.version = ".*"$',