Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: pylib/gyp/mac_tool.py

Issue 23710010: ninja&make/mac: Convert .strings files to UTF-16LE, not just UTF-16. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mac/gyptest-app.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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:]))
OLDNEW
« no previous file with comments | « no previous file | test/mac/gyptest-app.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698