Fix version format used on iOS by build/mac/tweak_info_plist.py.

Chrome on iOS uses different format by default for the "CFBundleVersion"
and "CFBundleShortVersionString" Info.plist values.

Change _AddVersionKeys function to take as parameter a dictionary from
Info.plist keys to version format using @MAJOR@, @MINOR@, @BUILD@ and
@PATCH@ patterns to represent the different component of the version,
and pass a different dictionary depending on the platform.

Refactor how the version is extracted using the build/util/version.py
script (it was invoked twice, but the second invocation can be removed
as the output needs to be post-processed).

BUG=502295,616750

Review-Url: https://codereview.chromium.org/2044893002
Cr-Original-Commit-Position: refs/heads/master@{#398323}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8001eee13920c32ca685f6700bbe2db77eed8046
This commit is contained in:
sdefresne 2016-06-07 10:38:12 -07:00 коммит произвёл Commit bot
Родитель d2f4b70565
Коммит dfe116dd65
1 изменённых файлов: 57 добавлений и 35 удалений

Просмотреть файл

@ -86,49 +86,49 @@ def _ApplyVersionOverrides(version, keys, overrides, separator='.'):
return separator.join(version_values)
def _AddVersionKeys(plist, version=None, overrides=None):
def _GetVersion(version_format, values, overrides=None):
"""Generates a version number according to |version_format| using the values
from |values| or |overrides| if given."""
result = version_format
for key in values:
if overrides and key in overrides:
value = overrides[key]
else:
value = values[key]
result = result.replace('@%s@' % key, value)
return result
def _AddVersionKeys(
plist, version_format_for_key, version=None, overrides=None):
"""Adds the product version number into the plist. Returns True on success and
False on error. The error will be printed to stderr."""
if version:
match = re.match('\d+\.\d+\.(\d+\.\d+)$', version)
if not match:
print >>sys.stderr, 'Invalid version string specified: "%s"' % version
return False
full_version = match.group(0)
bundle_version = match.group(1)
else:
if not version:
# Pull in the Chrome version number.
VERSION_TOOL = os.path.join(TOP, 'build/util/version.py')
VERSION_FILE = os.path.join(TOP, 'chrome/VERSION')
(stdout, retval) = _GetOutput([
VERSION_TOOL, '-f', VERSION_FILE,
'-t', '@MAJOR@.@MINOR@.@BUILD@.@PATCH@'])
(stdout, retval1) = _GetOutput([VERSION_TOOL, '-f', VERSION_FILE, '-t',
'@MAJOR@.@MINOR@.@BUILD@.@PATCH@'])
full_version = _ApplyVersionOverrides(
stdout.rstrip(), ('MAJOR', 'MINOR', 'BUILD', 'PATCH'), overrides)
(stdout, retval2) = _GetOutput([VERSION_TOOL, '-f', VERSION_FILE, '-t',
'@BUILD@.@PATCH@'])
bundle_version = _ApplyVersionOverrides(
stdout.rstrip(), ('BUILD', 'PATCH'), overrides)
# If either of the two version commands finished with non-zero returncode,
# report the error up.
if retval1 or retval2:
# If the command finished with a non-zero return code, then report the
# error up.
if retval != 0:
return False
# Add public version info so "Get Info" works.
plist['CFBundleShortVersionString'] = full_version
version = stdout.strip()
# Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1
# into 6, 2, 2 digits. The limitation was present in Tiger, but it could
# have been fixed in later OS release, but hasn't been tested (it's easy
# enough to find out with "lsregister -dump).
# http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html
# BUILD will always be an increasing value, so BUILD_PATH gives us something
# unique that meetings what LS wants.
plist['CFBundleVersion'] = bundle_version
# Parse the given version number, that should be in MAJOR.MINOR.BUILD.PATCH
# format (where each value is a number). Note that str.isdigit() returns
# True if the string is composed only of digits (and thus match \d+ regexp).
groups = version.split('.')
if len(groups) != 4 or not all(element.isdigit() for element in groups):
print >>sys.stderr, 'Invalid version string specified: "%s"' % version
return False
values = dict(zip(('MAJOR', 'MINOR', 'BUILD', 'PATCH'), groups))
for key in ('CFBundleVersion', 'CFBundleShortVersionString'):
plist[key] = _GetVersion(version_format_for_key[key], values, overrides)
# Return with no error.
return True
@ -289,8 +289,30 @@ def Main(argv):
print >>sys.stderr, 'Unsupported key for --version-overrides:', key
return 1
if options.platform == 'mac':
version_format_for_key = {
# Add public version info so "Get Info" works.
'CFBundleShortVersionString': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@',
# Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1
# into 6, 2, 2 digits. The limitation was present in Tiger, but it could
# have been fixed in later OS release, but hasn't been tested (it's easy
# enough to find out with "lsregister -dump).
# http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html
# BUILD will always be an increasing value, so BUILD_PATH gives us
# something unique that meetings what LS wants.
'CFBundleVersion': '@BUILD@.@PATCH@',
}
else:
version_format_for_key = {
'CFBundleShortVersionString': '@MAJOR@.@BUILD@.@PATCH@',
'CFBundleVersion': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@'
}
# Insert the product version.
if not _AddVersionKeys(plist, version=options.version, overrides=overrides):
if not _AddVersionKeys(
plist, version_format_for_key, version=options.version,
overrides=overrides):
return 2
# Add Breakpad if configured to do so.