| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 def _CopyStringsFile(self, source, dest): | 80 def _CopyStringsFile(self, source, dest): |
| 81 """Copies a .strings file using iconv to reconvert the input into UTF-16.""" | 81 """Copies a .strings file using iconv to reconvert the input into UTF-16.""" |
| 82 input_code = self._DetectInputEncoding(source) or "UTF-8" | 82 input_code = self._DetectInputEncoding(source) or "UTF-8" |
| 83 | 83 |
| 84 # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call | 84 # Xcode's CpyCopyStringsFile / builtin-copyStrings seems to call |
| 85 # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints | 85 # CFPropertyListCreateFromXMLData() behind the scenes; at least it prints |
| 86 # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing | 86 # CFPropertyListCreateFromXMLData(): Old-style plist parser: missing |
| 87 # semicolon in dictionary. | 87 # semicolon in dictionary. |
| 88 # on invalid files. Do the same kind of validation. | 88 # on invalid files. Do the same kind of validation. |
| 89 import CoreFoundation | 89 import CoreFoundation |
| 90 s = open(source).read() | 90 s = open(source, 'rb').read() |
| 91 d = CoreFoundation.CFDataCreate(None, s, len(s)) | 91 d = CoreFoundation.CFDataCreate(None, s, len(s)) |
| 92 _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None) | 92 _, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None) |
| 93 if error: | 93 if error: |
| 94 return | 94 return |
| 95 | 95 |
| 96 fp = open(dest, 'w') | 96 fp = open(dest, 'wb') |
| 97 args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code', | 97 fp.write(s.decode(input_code).encode('UTF-16')) |
| 98 'UTF-16', source] | |
| 99 subprocess.call(args, stdout=fp) | |
| 100 fp.close() | 98 fp.close() |
| 101 | 99 |
| 102 def _DetectInputEncoding(self, file_name): | 100 def _DetectInputEncoding(self, file_name): |
| 103 """Reads the first few bytes from file_name and tries to guess the text | 101 """Reads the first few bytes from file_name and tries to guess the text |
| 104 encoding. Returns None as a guess if it can't detect it.""" | 102 encoding. Returns None as a guess if it can't detect it.""" |
| 105 fp = open(file_name, 'rb') | 103 fp = open(file_name, 'rb') |
| 106 try: | 104 try: |
| 107 header = fp.read(3) | 105 header = fp.read(3) |
| 108 except e: | 106 except e: |
| 109 fp.close() | 107 fp.close() |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 def _Relink(self, dest, link): | 220 def _Relink(self, dest, link): |
| 223 """Creates a symlink to |dest| named |link|. If |link| already exists, | 221 """Creates a symlink to |dest| named |link|. If |link| already exists, |
| 224 it is overwritten.""" | 222 it is overwritten.""" |
| 225 if os.path.lexists(link): | 223 if os.path.lexists(link): |
| 226 os.remove(link) | 224 os.remove(link) |
| 227 os.symlink(dest, link) | 225 os.symlink(dest, link) |
| 228 | 226 |
| 229 | 227 |
| 230 if __name__ == '__main__': | 228 if __name__ == '__main__': |
| 231 sys.exit(main(sys.argv[1:])) | 229 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |