Chromium Code Reviews| 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 print version_format, values, overrides | |
|
Olivier
2016/06/07 14:51:24
des bugs ?
sdefresne
2016/06/07 14:57:36
Good catch. Done.
| |
| 93 result = version_format | |
| 94 for key in values: | |
| 95 if overrides and key in overrides: | |
| 96 value = overrides[key] | |
| 97 else: | |
| 98 value = values[key] | |
| 99 print 'result = %r.replace(\'@%%s@\' %% %r, %r)' % (result, key, value) | |
|
Olivier
2016/06/07 14:51:24
ditto
sdefresne
2016/06/07 14:57:36
Done.
| |
| 100 result = result.replace('@%s@' % key, value) | |
| 101 print result | |
|
Olivier
2016/06/07 14:51:24
ditto
sdefresne
2016/06/07 14:57:36
Done.
| |
| 102 return result | |
| 103 | |
| 104 | |
| 105 def _AddVersionKeys( | |
| 106 plist, version_format_for_key, version=None, overrides=None): | |
| 90 """Adds the product version number into the plist. Returns True on success and | 107 """Adds the product version number into the plist. Returns True on success and |
| 91 False on error. The error will be printed to stderr.""" | 108 False on error. The error will be printed to stderr.""" |
| 92 if version: | 109 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. | 110 # Pull in the Chrome version number. |
| 103 VERSION_TOOL = os.path.join(TOP, 'build/util/version.py') | 111 VERSION_TOOL = os.path.join(TOP, 'build/util/version.py') |
| 104 VERSION_FILE = os.path.join(TOP, 'chrome/VERSION') | 112 VERSION_FILE = os.path.join(TOP, 'chrome/VERSION') |
| 113 (stdout, retval) = _GetOutput([ | |
| 114 VERSION_TOOL, '-f', VERSION_FILE, | |
| 115 '-t', '@MAJOR@.@MINOR@.@BUILD@.@PATCH@']) | |
| 105 | 116 |
| 106 (stdout, retval1) = _GetOutput([VERSION_TOOL, '-f', VERSION_FILE, '-t', | 117 # If the command finished with a non-zero return code, then report the |
| 107 '@MAJOR@.@MINOR@.@BUILD@.@PATCH@']) | 118 # error up. |
| 108 full_version = _ApplyVersionOverrides( | 119 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 | 120 return False |
| 120 | 121 |
| 121 # Add public version info so "Get Info" works. | 122 version = stdout.strip() |
| 122 plist['CFBundleShortVersionString'] = full_version | |
| 123 | 123 |
| 124 # Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1 | 124 # 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 | 125 # 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 | 126 # True if the string is composed only of digits (and thus match \d+ regexp). |
| 127 # enough to find out with "lsregister -dump). | 127 groups = version.split('.') |
| 128 # http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html | 128 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 | 129 print >>sys.stderr, 'Invalid version string specified: "%s"' % version |
| 130 # unique that meetings what LS wants. | 130 return False |
| 131 plist['CFBundleVersion'] = bundle_version | 131 values = dict(zip(('MAJOR', 'MINOR', 'BUILD', 'PATCH'), groups)) |
| 132 | |
| 133 for key in ('CFBundleVersion', 'CFBundleShortVersionString'): | |
| 134 plist[key] = _GetVersion(version_format_for_key[key], values, overrides) | |
| 132 | 135 |
| 133 # Return with no error. | 136 # Return with no error. |
| 134 return True | 137 return True |
| 135 | 138 |
| 136 | 139 |
| 137 def _DoSCMKeys(plist, add_keys): | 140 def _DoSCMKeys(plist, add_keys): |
| 138 """Adds the SCM information, visible in about:version, to property list. If | 141 """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.""" | 142 |add_keys| is True, it will insert the keys, otherwise it will remove them.""" |
| 140 scm_revision = None | 143 scm_revision = None |
| 141 if add_keys: | 144 if add_keys: |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 for pair in options.version_overrides: | 285 for pair in options.version_overrides: |
| 283 if not '=' in pair: | 286 if not '=' in pair: |
| 284 print >>sys.stderr, 'Invalid value for --version-overrides:', pair | 287 print >>sys.stderr, 'Invalid value for --version-overrides:', pair |
| 285 return 1 | 288 return 1 |
| 286 key, value = pair.split('=', 1) | 289 key, value = pair.split('=', 1) |
| 287 overrides[key] = value | 290 overrides[key] = value |
| 288 if key not in ('MAJOR', 'MINOR', 'BUILD', 'PATCH'): | 291 if key not in ('MAJOR', 'MINOR', 'BUILD', 'PATCH'): |
| 289 print >>sys.stderr, 'Unsupported key for --version-overrides:', key | 292 print >>sys.stderr, 'Unsupported key for --version-overrides:', key |
| 290 return 1 | 293 return 1 |
| 291 | 294 |
| 295 if options.platform == 'mac': | |
| 296 version_format_for_key = { | |
| 297 # Add public version info so "Get Info" works. | |
| 298 'CFBundleShortVersionString': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@', | |
| 299 | |
| 300 # Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1 | |
| 301 # into 6, 2, 2 digits. The limitation was present in Tiger, but it could | |
| 302 # have been fixed in later OS release, but hasn't been tested (it's easy | |
| 303 # enough to find out with "lsregister -dump). | |
| 304 # http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html | |
| 305 # BUILD will always be an increasing value, so BUILD_PATH gives us | |
| 306 # something unique that meetings what LS wants. | |
| 307 'CFBundleVersion': '@BUILD@.@PATCH@', | |
| 308 } | |
| 309 else: | |
| 310 version_format_for_key = { | |
| 311 'CFBundleShortVersionString': '@MAJOR@.@BUILD@.@PATCH@', | |
| 312 'CFBundleVersion': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@' | |
| 313 } | |
| 314 | |
| 292 # Insert the product version. | 315 # Insert the product version. |
| 293 if not _AddVersionKeys(plist, version=options.version, overrides=overrides): | 316 if not _AddVersionKeys( |
| 317 plist, version_format_for_key, version=options.version, | |
| 318 overrides=overrides): | |
| 294 return 2 | 319 return 2 |
| 295 | 320 |
| 296 # Add Breakpad if configured to do so. | 321 # Add Breakpad if configured to do so. |
| 297 if options.use_breakpad: | 322 if options.use_breakpad: |
| 298 if options.branding is None: | 323 if options.branding is None: |
| 299 print >>sys.stderr, 'Use of Breakpad requires branding.' | 324 print >>sys.stderr, 'Use of Breakpad requires branding.' |
| 300 return 1 | 325 return 1 |
| 301 # Map gyp "OS" / gn "target_os" passed via the --platform parameter to | 326 # Map gyp "OS" / gn "target_os" passed via the --platform parameter to |
| 302 # the platform as known by breakpad. | 327 # the platform as known by breakpad. |
| 303 platform = {'mac': 'Mac', 'ios': 'iOS'}[options.platform] | 328 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: | 361 with tempfile.NamedTemporaryFile() as temp_info_plist: |
| 337 plistlib.writePlist(plist, temp_info_plist.name) | 362 plistlib.writePlist(plist, temp_info_plist.name) |
| 338 | 363 |
| 339 # Convert Info.plist to the format requested by the --format flag. Any | 364 # Convert Info.plist to the format requested by the --format flag. Any |
| 340 # format would work on Mac but iOS requires specific format. | 365 # format would work on Mac but iOS requires specific format. |
| 341 return _ConvertPlist(temp_info_plist.name, output_path, options.format) | 366 return _ConvertPlist(temp_info_plist.name, output_path, options.format) |
| 342 | 367 |
| 343 | 368 |
| 344 if __name__ == '__main__': | 369 if __name__ == '__main__': |
| 345 sys.exit(Main(sys.argv[1:])) | 370 sys.exit(Main(sys.argv[1:])) |
| OLD | NEW |