| Index: build/toolchain/mac/copy_bundle_data.py
|
| diff --git a/build/toolchain/mac/copy_bundle_data.py b/build/toolchain/mac/copy_bundle_data.py
|
| index 15127a0ce9bfc6a7fb17d9a91f7fc4f9df3c6d7b..0760f719b96cda3df049367f5ab10d1dcb37d706 100644
|
| --- a/build/toolchain/mac/copy_bundle_data.py
|
| +++ b/build/toolchain/mac/copy_bundle_data.py
|
| @@ -5,6 +5,8 @@
|
| import argparse
|
| import os
|
| import shutil
|
| +import stat
|
| +import subprocess
|
| import sys
|
|
|
|
|
| @@ -32,78 +34,97 @@ def DetectEncoding(data, default_encoding='UTF-8'):
|
|
|
|
|
| def CopyStringsFile(source, dest, strings_format):
|
| - """Copies a .strings file from |source| to |dest| and convert it to UTF-16.
|
| + """Copies a .strings file from |source| to |dest|.
|
|
|
| Args:
|
| source: string, path to the source file
|
| dest: string, path to the destination file
|
| + strings_format: convert .strings file to format
|
| """
|
| - with open(source, 'rb') as source_file:
|
| - data = source_file.read()
|
| -
|
| - # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call
|
| - # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints
|
| - # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing
|
| - # semicolon in dictionary.
|
| - # on invalid files. Do the same kind of validation.
|
| - import CoreFoundation as CF
|
| - cfdata = CF.CFDataCreate(None, data, len(data))
|
| - plist, error = CF.CFPropertyListCreateFromXMLData(None, cfdata, 0, None)
|
| - if error:
|
| - raise ValueError(error)
|
| -
|
| if strings_format == 'legacy':
|
| + with open(source, 'rb') as source_file:
|
| + data = source_file.read()
|
| encoding = DetectEncoding(data)
|
| with open(dest, 'wb') as dest_file:
|
| dest_file.write(data.decode(encoding).encode('UTF-16'))
|
| else:
|
| - cfformat = {
|
| - 'xml1': CF.kCFPropertyListXMLFormat_v1_0,
|
| - 'binary1': CF.kCFPropertyListBinaryFormat_v1_0,
|
| - }[strings_format]
|
| - cfdata, error = CF.CFPropertyListCreateData(
|
| - None, plist, CF.kCFPropertyListBinaryFormat_v1_0,
|
| - 0, None)
|
| - if error:
|
| - raise ValueError(error)
|
| -
|
| - data = CF.CFDataGetBytes(
|
| - cfdata, CF.CFRangeMake(0, CF.CFDataGetLength(cfdata)), None)
|
| + subprocess.check_call([
|
| + 'xcrun', 'plutil', '-convert', strings_format,
|
| + '-o', dest, source])
|
| +
|
| +
|
| +def CopyTree(source, dest):
|
| + """Copies a directory from |source| to |dest|."""
|
| + os.makedirs(dest)
|
| + for name in os.listdir(source):
|
| + source_name = os.path.join(source, name)
|
| + target_name = os.path.join(dest, name)
|
| + if os.path.isdir(source_name):
|
| + CopyTree(source_name, target_name)
|
| + else:
|
| + CopyFile(source_name, target_name)
|
| +
|
| +
|
| +def CopyFile(source, dest):
|
| + """Copies a file from |source| to |dest|.
|
| +
|
| + Args:
|
| + source: string, path to the source file
|
| + dest: string, path to the destination file
|
| + """
|
| + if os.path.islink(source):
|
| + linkto = os.readink(source_name)
|
| + os.symlink(linkto, dest)
|
| + return
|
| +
|
| + source_stat = os.stat(source)
|
| + if not stat.S_ISREG(source_stat.st_mode):
|
| + raise OSError('cannot copy special file: %s' % source)
|
| +
|
| + with open(source, 'rb') as source_file:
|
| with open(dest, 'wb') as dest_file:
|
| - dest_file.write(data)
|
| + while True:
|
| + data = source_file.read(16*1024)
|
| + if not data:
|
| + break
|
| + dest_file.write(data)
|
|
|
| + os.chmod(dest, stat.S_IMODE(source_stat.st_mode))
|
|
|
| -def CopyFile(source, dest, strings_format):
|
| +
|
| +def Copy(source, dest, strings_format):
|
| """Copies a file or directory from |source| to |dest|.
|
|
|
| Args:
|
| source: string, path to the source file
|
| dest: string, path to the destination file
|
| + strings_format: format to use when copying .strings files
|
| """
|
| if os.path.isdir(source):
|
| if os.path.exists(dest):
|
| shutil.rmtree(dest)
|
| - # Copy tree.
|
| - # TODO(thakis): This copies file attributes like mtime, while the
|
| - # single-file branch below doesn't. This should probably be changed to
|
| - # be consistent with the single-file branch.
|
| - shutil.copytree(source, dest, symlinks=True)
|
| +
|
| + CopyTree(source, dest)
|
| return
|
|
|
| if os.path.exists(dest):
|
| os.unlink(dest)
|
|
|
| - _, extension = os.path.splitext(source)
|
| - if extension == '.strings':
|
| + if os.path.splitext(source)[-1] == '.strings':
|
| CopyStringsFile(source, dest, strings_format)
|
| return
|
|
|
| - shutil.copy(source, dest)
|
| + CopyFile(source, dest)
|
|
|
|
|
| def Main():
|
| parser = argparse.ArgumentParser(
|
| description='copy source to destination for the creation of a bundle')
|
| + parser.add_argument(
|
| + '--version-for-gn', choices=('1',),
|
| + help='version need to be increased in this script and in the file '
|
| + '//build/toolchain/mac/BUILD.gn to force build until issue '
|
| + 'http://crbug.com/619083 is fixed')
|
| parser.add_argument('--strings-format',
|
| choices=('xml1', 'binary1', 'legacy'), default='legacy',
|
| help='convert .strings file to format (default: %(default)s)')
|
| @@ -111,7 +132,7 @@ def Main():
|
| parser.add_argument('dest', help='path to destination')
|
| args = parser.parse_args()
|
|
|
| - CopyFile(args.source, args.dest, args.strings_format)
|
| + Copy(args.source, args.dest, args.strings_format)
|
|
|
| if __name__ == '__main__':
|
| sys.exit(Main())
|
|
|