OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | 2 # Copyright (c) 2012 Google Inc. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Utility functions to perform Xcode-style build steps. | 6 """Utility functions to perform Xcode-style build steps. |
7 | 7 |
8 These functions are executed via gyp-mac-tool when using the Makefile generator. | 8 These functions are executed via gyp-mac-tool when using the Makefile generator. |
9 """ | 9 """ |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 def ExecCopyBundleResource(self, source, dest): | 44 def ExecCopyBundleResource(self, source, dest): |
45 """Copies a resource file to the bundle/Resources directory, performing any | 45 """Copies a resource file to the bundle/Resources directory, performing any |
46 necessary compilation on each resource.""" | 46 necessary compilation on each resource.""" |
47 extension = os.path.splitext(source)[1].lower() | 47 extension = os.path.splitext(source)[1].lower() |
48 if os.path.isdir(source): | 48 if os.path.isdir(source): |
49 # Copy tree. | 49 # Copy tree. |
50 if os.path.exists(dest): | 50 if os.path.exists(dest): |
51 shutil.rmtree(dest) | 51 shutil.rmtree(dest) |
52 shutil.copytree(source, dest) | 52 shutil.copytree(source, dest) |
53 elif extension == '.xib': | 53 elif extension == '.xib': |
54 self._CopyXIBFile(source, dest) | 54 return self._CopyXIBFile(source, dest) |
55 elif extension == '.strings': | 55 elif extension == '.strings': |
56 self._CopyStringsFile(source, dest) | 56 self._CopyStringsFile(source, dest) |
57 # TODO: Given that files with arbitrary extensions can be copied to the | 57 # TODO: Given that files with arbitrary extensions can be copied to the |
58 # bundle, we will want to get rid of this whitelist eventually. | 58 # bundle, we will want to get rid of this whitelist eventually. |
59 elif extension in [ | 59 elif extension in [ |
60 '.icns', '.manifest', '.pak', '.pdf', '.png', '.sb', '.sh', | 60 '.icns', '.manifest', '.pak', '.pdf', '.png', '.sb', '.sh', |
61 '.ttf', '.sdef']: | 61 '.ttf', '.sdef']: |
62 shutil.copyfile(source, dest) | 62 shutil.copyfile(source, dest) |
63 else: | 63 else: |
64 raise NotImplementedError( | 64 raise NotImplementedError( |
65 "Don't know how to copy bundle resources of type %s while copying " | 65 "Don't know how to copy bundle resources of type %s while copying " |
66 "%s to %s)" % (extension, source, dest)) | 66 "%s to %s)" % (extension, source, dest)) |
67 | 67 |
68 def _CopyXIBFile(self, source, dest): | 68 def _CopyXIBFile(self, source, dest): |
69 """Compiles a XIB file with ibtool into a binary plist in the bundle.""" | 69 """Compiles a XIB file with ibtool into a binary plist in the bundle.""" |
70 args = ['/Developer/usr/bin/ibtool', '--errors', '--warnings', | 70 args = ['/Developer/usr/bin/ibtool', '--errors', '--warnings', |
71 '--notices', '--output-format', 'human-readable-text', '--compile', | 71 '--notices', '--output-format', 'human-readable-text', '--compile', |
72 dest, source] | 72 dest, source] |
73 subprocess.call(args) | 73 ibtool_section_re = re.compile(r'/\*.*\*/') |
74 ibtool_re = re.compile(r'.*note:.*is clipping its content') | |
75 ibtoolout = subprocess.Popen(args, stdout=subprocess.PIPE) | |
76 current_section_header = None | |
77 for line in ibtoolout.stdout: | |
78 if ibtool_section_re.match(line): | |
79 current_section_header = line | |
80 elif not ibtool_re.match(line): | |
81 if current_section_header: | |
82 sys.stdout.write(current_section_header) | |
83 current_section_header = None | |
Robert Sesek
2012/02/21 15:53:28
Can there be multiple lines of output under the sa
Nico
2012/02/21 16:23:46
Yes:
/* com.apple.ibtool.document.notices */
/b/b
| |
84 sys.stdout.write(line) | |
85 return ibtoolout.returncode | |
74 | 86 |
75 def _CopyStringsFile(self, source, dest): | 87 def _CopyStringsFile(self, source, dest): |
76 """Copies a .strings file using iconv to reconvert the input into UTF-16.""" | 88 """Copies a .strings file using iconv to reconvert the input into UTF-16.""" |
77 input_code = self._DetectInputEncoding(source) or "UTF-8" | 89 input_code = self._DetectInputEncoding(source) or "UTF-8" |
78 fp = open(dest, 'w') | 90 fp = open(dest, 'w') |
79 args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code', | 91 args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code', |
80 'UTF-16', source] | 92 'UTF-16', source] |
81 subprocess.call(args, stdout=fp) | 93 subprocess.call(args, stdout=fp) |
82 fp.close() | 94 fp.close() |
83 | 95 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 def _Relink(self, dest, link): | 207 def _Relink(self, dest, link): |
196 """Creates a symlink to |dest| named |link|. If |link| already exists, | 208 """Creates a symlink to |dest| named |link|. If |link| already exists, |
197 it is overwritten.""" | 209 it is overwritten.""" |
198 if os.path.lexists(link): | 210 if os.path.lexists(link): |
199 os.remove(link) | 211 os.remove(link) |
200 os.symlink(dest, link) | 212 os.symlink(dest, link) |
201 | 213 |
202 | 214 |
203 if __name__ == '__main__': | 215 if __name__ == '__main__': |
204 sys.exit(main(sys.argv[1:])) | 216 sys.exit(main(sys.argv[1:])) |
OLD | NEW |