diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-02-20 11:47:03 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-02-20 11:47:03 +0100 |
commit | 4af673e161138fbed287a8e00cf7b2b0aafdd8b3 (patch) | |
tree | 90fb82bb98fdbcbb0c86c446e029c13bf999c8b0 /tools/gyp/pylib/gyp/mac_tool.py | |
parent | 7ae0d473a6b6ac8cb3e55d665528667566cd8e60 (diff) | |
download | android-node-v8-4af673e161138fbed287a8e00cf7b2b0aafdd8b3.tar.gz android-node-v8-4af673e161138fbed287a8e00cf7b2b0aafdd8b3.tar.bz2 android-node-v8-4af673e161138fbed287a8e00cf7b2b0aafdd8b3.zip |
gyp: update to r1214
Diffstat (limited to 'tools/gyp/pylib/gyp/mac_tool.py')
-rwxr-xr-x | tools/gyp/pylib/gyp/mac_tool.py | 150 |
1 files changed, 81 insertions, 69 deletions
diff --git a/tools/gyp/pylib/gyp/mac_tool.py b/tools/gyp/pylib/gyp/mac_tool.py index 64707762d3..42dd6c9923 100755 --- a/tools/gyp/pylib/gyp/mac_tool.py +++ b/tools/gyp/pylib/gyp/mac_tool.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2011 Google Inc. All rights reserved. +# Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -8,9 +8,10 @@ These functions are executed via gyp-mac-tool when using the Makefile generator. """ -import os import fcntl +import os import plistlib +import re import shutil import string import subprocess @@ -19,7 +20,9 @@ import sys def main(args): executor = MacTool() - executor.Dispatch(args) + exit_code = executor.Dispatch(args) + if exit_code is not None: + sys.exit(exit_code) class MacTool(object): @@ -32,18 +35,70 @@ class MacTool(object): raise Exception("Not enough arguments") method = "Exec%s" % self._CommandifyName(args[0]) - getattr(self, method)(*args[1:]) + return getattr(self, method)(*args[1:]) def _CommandifyName(self, name_string): """Transforms a tool name like copy-info-plist to CopyInfoPlist""" return name_string.title().replace('-', '') - def ExecFlock(self, lockfile, *cmd_list): - """Emulates the most basic behavior of Linux's flock(1).""" - # Rely on exception handling to report errors. - fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666) - fcntl.flock(fd, fcntl.LOCK_EX) - return subprocess.call(cmd_list) + def ExecCopyBundleResource(self, source, dest): + """Copies a resource file to the bundle/Resources directory, performing any + necessary compilation on each resource.""" + extension = os.path.splitext(source)[1].lower() + if os.path.isdir(source): + # Copy tree. + if os.path.exists(dest): + shutil.rmtree(dest) + shutil.copytree(source, dest) + elif extension == '.xib': + self._CopyXIBFile(source, dest) + elif extension == '.strings': + self._CopyStringsFile(source, dest) + # TODO: Given that files with arbitrary extensions can be copied to the + # bundle, we will want to get rid of this whitelist eventually. + elif extension in [ + '.icns', '.manifest', '.pak', '.pdf', '.png', '.sb', '.sh', + '.ttf', '.sdef']: + shutil.copyfile(source, dest) + else: + raise NotImplementedError( + "Don't know how to copy bundle resources of type %s while copying " + "%s to %s)" % (extension, source, dest)) + + def _CopyXIBFile(self, source, dest): + """Compiles a XIB file with ibtool into a binary plist in the bundle.""" + args = ['/Developer/usr/bin/ibtool', '--errors', '--warnings', + '--notices', '--output-format', 'human-readable-text', '--compile', + dest, source] + subprocess.call(args) + + def _CopyStringsFile(self, source, dest): + """Copies a .strings file using iconv to reconvert the input into UTF-16.""" + input_code = self._DetectInputEncoding(source) or "UTF-8" + fp = open(dest, 'w') + args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code', + 'UTF-16', source] + subprocess.call(args, stdout=fp) + fp.close() + + def _DetectInputEncoding(self, file_name): + """Reads the first few bytes from file_name and tries to guess the text + encoding. Returns None as a guess if it can't detect it.""" + fp = open(file_name, 'rb') + try: + header = fp.read(3) + except e: + fp.close() + return None + fp.close() + if header.startswith("\xFE\xFF"): + return "UTF-16BE" + elif header.startswith("\xFF\xFE"): + return "UTF-16LE" + elif header.startswith("\xEF\xBB\xBF"): + return "UTF-8" + else: + return None def ExecCopyInfoPlist(self, source, dest): """Copies the |source| Info.plist to the destination directory |dest|.""" @@ -92,6 +147,22 @@ class MacTool(object): fp.write('%s%s' % (package_type, signature_code)) fp.close() + def ExecFlock(self, lockfile, *cmd_list): + """Emulates the most basic behavior of Linux's flock(1).""" + # Rely on exception handling to report errors. + fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666) + fcntl.flock(fd, fcntl.LOCK_EX) + return subprocess.call(cmd_list) + + def ExecFilterLibtool(self, *cmd_list): + """Calls libtool and filters out 'libtool: file: foo.o has no symbols'.""" + libtool_re = re.compile(r'^libtool: file: .* has no symbols$') + libtoolout = subprocess.Popen(cmd_list, stderr=subprocess.PIPE) + for line in libtoolout.stderr: + if not libtool_re.match(line): + sys.stderr.write(line) + return libtoolout.returncode + def ExecPackageFramework(self, framework, version): """Takes a path to Something.framework and the Current version of that and sets up all the symlinks.""" @@ -128,65 +199,6 @@ class MacTool(object): os.remove(link) os.symlink(dest, link) - def ExecCopyBundleResource(self, source, dest): - """Copies a resource file to the bundle/Resources directory, performing any - necessary compilation on each resource.""" - extension = os.path.splitext(source)[1].lower() - if os.path.isdir(source): - # Copy tree. - if os.path.exists(dest): - shutil.rmtree(dest) - shutil.copytree(source, dest) - elif extension == '.xib': - self._CopyXIBFile(source, dest) - elif extension == '.strings': - self._CopyStringsFile(source, dest) - # TODO: Given that files with arbitrary extensions can be copied to the - # bundle, we will want to get rid of this whitelist eventually. - elif extension in [ - '.icns', '.manifest', '.pak', '.pdf', '.png', '.sb', '.sh', - '.ttf', '.sdef']: - shutil.copyfile(source, dest) - else: - raise NotImplementedError( - "Don't know how to copy bundle resources of type %s while copying " - "%s to %s)" % (extension, source, dest)) - - def _CopyXIBFile(self, source, dest): - """Compiles a XIB file with ibtool into a binary plist in the bundle.""" - args = ['/Developer/usr/bin/ibtool', '--errors', '--warnings', - '--notices', '--output-format', 'human-readable-text', '--compile', - dest, source] - subprocess.call(args) - - def _CopyStringsFile(self, source, dest): - """Copies a .strings file using iconv to reconvert the input into UTF-16.""" - input_code = self._DetectInputEncoding(source) or "UTF-8" - fp = open(dest, 'w') - args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code', - 'UTF-16', source] - subprocess.call(args, stdout=fp) - fp.close() - - def _DetectInputEncoding(self, file_name): - """Reads the first few bytes from file_name and tries to guess the text - encoding. Returns None as a guess if it can't detect it.""" - fp = open(file_name, 'rb') - try: - header = fp.read(3) - except e: - fp.close() - return None - fp.close() - if header.startswith("\xFE\xFF"): - return "UTF-16BE" - elif header.startswith("\xFF\xFE"): - return "UTF-16LE" - elif header.startswith("\xEF\xBB\xBF"): - return "UTF-8" - else: - return None - if __name__ == '__main__': sys.exit(main(sys.argv[1:])) |