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