OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # | 7 # |
8 # Xcode supports build variable substitutions and CPP; sadly, that doesn't work | 8 # Xcode supports build variable substitutions and CPP; sadly, that doesn't work |
9 # because: | 9 # because: |
10 # | 10 # |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 """ | 79 """ |
80 if not overrides: | 80 if not overrides: |
81 return version | 81 return version |
82 version_values = version.split(separator) | 82 version_values = version.split(separator) |
83 for i, (key, value) in enumerate(zip(keys, version_values)): | 83 for i, (key, value) in enumerate(zip(keys, version_values)): |
84 if key in overrides: | 84 if key in overrides: |
85 version_values[i] = overrides[key] | 85 version_values[i] = overrides[key] |
86 return separator.join(version_values) | 86 return separator.join(version_values) |
87 | 87 |
88 | 88 |
89 def _AddVersionKeys(plist, version=None, overrides=None): | 89 def _GetVersion(version_format, values, overrides=None): |
| 90 """Generates a version number according to |version_format| using the values |
| 91 from |values| or |overrides| if given.""" |
| 92 result = version_format |
| 93 for key in values: |
| 94 if overrides and key in overrides: |
| 95 value = overrides[key] |
| 96 else: |
| 97 value = values[key] |
| 98 result = result.replace('@%s@' % key, value) |
| 99 return result |
| 100 |
| 101 |
| 102 def _AddVersionKeys( |
| 103 plist, version_format_for_key, version=None, overrides=None): |
90 """Adds the product version number into the plist. Returns True on success and | 104 """Adds the product version number into the plist. Returns True on success and |
91 False on error. The error will be printed to stderr.""" | 105 False on error. The error will be printed to stderr.""" |
92 if version: | 106 if not version: |
93 match = re.match('\d+\.\d+\.(\d+\.\d+)$', version) | |
94 if not match: | |
95 print >>sys.stderr, 'Invalid version string specified: "%s"' % version | |
96 return False | |
97 | |
98 full_version = match.group(0) | |
99 bundle_version = match.group(1) | |
100 | |
101 else: | |
102 # Pull in the Chrome version number. | 107 # Pull in the Chrome version number. |
103 VERSION_TOOL = os.path.join(TOP, 'build/util/version.py') | 108 VERSION_TOOL = os.path.join(TOP, 'build/util/version.py') |
104 VERSION_FILE = os.path.join(TOP, 'chrome/VERSION') | 109 VERSION_FILE = os.path.join(TOP, 'chrome/VERSION') |
| 110 (stdout, retval) = _GetOutput([ |
| 111 VERSION_TOOL, '-f', VERSION_FILE, |
| 112 '-t', '@MAJOR@.@MINOR@.@BUILD@.@PATCH@']) |
105 | 113 |
106 (stdout, retval1) = _GetOutput([VERSION_TOOL, '-f', VERSION_FILE, '-t', | 114 # If the command finished with a non-zero return code, then report the |
107 '@MAJOR@.@MINOR@.@BUILD@.@PATCH@']) | 115 # error up. |
108 full_version = _ApplyVersionOverrides( | 116 if retval != 0: |
109 stdout.rstrip(), ('MAJOR', 'MINOR', 'BUILD', 'PATCH'), overrides) | |
110 | |
111 (stdout, retval2) = _GetOutput([VERSION_TOOL, '-f', VERSION_FILE, '-t', | |
112 '@BUILD@.@PATCH@']) | |
113 bundle_version = _ApplyVersionOverrides( | |
114 stdout.rstrip(), ('BUILD', 'PATCH'), overrides) | |
115 | |
116 # If either of the two version commands finished with non-zero returncode, | |
117 # report the error up. | |
118 if retval1 or retval2: | |
119 return False | 117 return False |
120 | 118 |
121 # Add public version info so "Get Info" works. | 119 version = stdout.strip() |
122 plist['CFBundleShortVersionString'] = full_version | |
123 | 120 |
124 # Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1 | 121 # Parse the given version number, that should be in MAJOR.MINOR.BUILD.PATCH |
125 # into 6, 2, 2 digits. The limitation was present in Tiger, but it could | 122 # format (where each value is a number). Note that str.isdigit() returns |
126 # have been fixed in later OS release, but hasn't been tested (it's easy | 123 # True if the string is composed only of digits (and thus match \d+ regexp). |
127 # enough to find out with "lsregister -dump). | 124 groups = version.split('.') |
128 # http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html | 125 if len(groups) != 4 or not all(element.isdigit() for element in groups): |
129 # BUILD will always be an increasing value, so BUILD_PATH gives us something | 126 print >>sys.stderr, 'Invalid version string specified: "%s"' % version |
130 # unique that meetings what LS wants. | 127 return False |
131 plist['CFBundleVersion'] = bundle_version | 128 values = dict(zip(('MAJOR', 'MINOR', 'BUILD', 'PATCH'), groups)) |
| 129 |
| 130 for key in ('CFBundleVersion', 'CFBundleShortVersionString'): |
| 131 plist[key] = _GetVersion(version_format_for_key[key], values, overrides) |
132 | 132 |
133 # Return with no error. | 133 # Return with no error. |
134 return True | 134 return True |
135 | 135 |
136 | 136 |
137 def _DoSCMKeys(plist, add_keys): | 137 def _DoSCMKeys(plist, add_keys): |
138 """Adds the SCM information, visible in about:version, to property list. If | 138 """Adds the SCM information, visible in about:version, to property list. If |
139 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" | 139 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" |
140 scm_revision = None | 140 scm_revision = None |
141 if add_keys: | 141 if add_keys: |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 for pair in options.version_overrides: | 282 for pair in options.version_overrides: |
283 if not '=' in pair: | 283 if not '=' in pair: |
284 print >>sys.stderr, 'Invalid value for --version-overrides:', pair | 284 print >>sys.stderr, 'Invalid value for --version-overrides:', pair |
285 return 1 | 285 return 1 |
286 key, value = pair.split('=', 1) | 286 key, value = pair.split('=', 1) |
287 overrides[key] = value | 287 overrides[key] = value |
288 if key not in ('MAJOR', 'MINOR', 'BUILD', 'PATCH'): | 288 if key not in ('MAJOR', 'MINOR', 'BUILD', 'PATCH'): |
289 print >>sys.stderr, 'Unsupported key for --version-overrides:', key | 289 print >>sys.stderr, 'Unsupported key for --version-overrides:', key |
290 return 1 | 290 return 1 |
291 | 291 |
| 292 if options.platform == 'mac': |
| 293 version_format_for_key = { |
| 294 # Add public version info so "Get Info" works. |
| 295 'CFBundleShortVersionString': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@', |
| 296 |
| 297 # Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1 |
| 298 # into 6, 2, 2 digits. The limitation was present in Tiger, but it could |
| 299 # have been fixed in later OS release, but hasn't been tested (it's easy |
| 300 # enough to find out with "lsregister -dump). |
| 301 # http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html |
| 302 # BUILD will always be an increasing value, so BUILD_PATH gives us |
| 303 # something unique that meetings what LS wants. |
| 304 'CFBundleVersion': '@BUILD@.@PATCH@', |
| 305 } |
| 306 else: |
| 307 version_format_for_key = { |
| 308 'CFBundleShortVersionString': '@MAJOR@.@BUILD@.@PATCH@', |
| 309 'CFBundleVersion': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@' |
| 310 } |
| 311 |
292 # Insert the product version. | 312 # Insert the product version. |
293 if not _AddVersionKeys(plist, version=options.version, overrides=overrides): | 313 if not _AddVersionKeys( |
| 314 plist, version_format_for_key, version=options.version, |
| 315 overrides=overrides): |
294 return 2 | 316 return 2 |
295 | 317 |
296 # Add Breakpad if configured to do so. | 318 # Add Breakpad if configured to do so. |
297 if options.use_breakpad: | 319 if options.use_breakpad: |
298 if options.branding is None: | 320 if options.branding is None: |
299 print >>sys.stderr, 'Use of Breakpad requires branding.' | 321 print >>sys.stderr, 'Use of Breakpad requires branding.' |
300 return 1 | 322 return 1 |
301 # Map gyp "OS" / gn "target_os" passed via the --platform parameter to | 323 # Map gyp "OS" / gn "target_os" passed via the --platform parameter to |
302 # the platform as known by breakpad. | 324 # the platform as known by breakpad. |
303 platform = {'mac': 'Mac', 'ios': 'iOS'}[options.platform] | 325 platform = {'mac': 'Mac', 'ios': 'iOS'}[options.platform] |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 with tempfile.NamedTemporaryFile() as temp_info_plist: | 358 with tempfile.NamedTemporaryFile() as temp_info_plist: |
337 plistlib.writePlist(plist, temp_info_plist.name) | 359 plistlib.writePlist(plist, temp_info_plist.name) |
338 | 360 |
339 # Convert Info.plist to the format requested by the --format flag. Any | 361 # Convert Info.plist to the format requested by the --format flag. Any |
340 # format would work on Mac but iOS requires specific format. | 362 # format would work on Mac but iOS requires specific format. |
341 return _ConvertPlist(temp_info_plist.name, output_path, options.format) | 363 return _ConvertPlist(temp_info_plist.name, output_path, options.format) |
342 | 364 |
343 | 365 |
344 if __name__ == '__main__': | 366 if __name__ == '__main__': |
345 sys.exit(Main(sys.argv[1:])) | 367 sys.exit(Main(sys.argv[1:])) |
OLD | NEW |