ninja&make/mac: Convert .strings files to UTF-16LE, not just UTF-16.
OS X iconv makes "UTF-16" write UTF-16BE data. Just do the recoding in
Python, which lets "UTF-16" write UTF-16LE data (I guess it uses the host
byte order). Also saves a subprocess invocation while here.
(Using "UTF-16LE" explicitly lets both iconv and python omit the BOM, so it's
shorter to use "UTF-16" than "UTF-16LE" and explicitly writing a BOM.)
This matches Xcode's behavior (at least Xcode 4.5).
BUG=chromium:280718
R=rsesek@chromium.org
Review URL: https://codereview.chromium.org/23710010
git-svn-id: http://gyp.googlecode.com/svn/trunk@1707 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/mac_tool.py b/pylib/gyp/mac_tool.py
index 14dac52..664cf7a 100755
--- a/pylib/gyp/mac_tool.py
+++ b/pylib/gyp/mac_tool.py
@@ -87,16 +87,14 @@
# semicolon in dictionary.
# on invalid files. Do the same kind of validation.
import CoreFoundation
- s = open(source).read()
+ s = open(source, 'rb').read()
d = CoreFoundation.CFDataCreate(None, s, len(s))
_, error = CoreFoundation.CFPropertyListCreateFromXMLData(None, d, 0, None)
if error:
return
- fp = open(dest, 'w')
- args = ['/usr/bin/iconv', '--from-code', input_code, '--to-code',
- 'UTF-16', source]
- subprocess.call(args, stdout=fp)
+ fp = open(dest, 'wb')
+ fp.write(s.decode(input_code).encode('UTF-16'))
fp.close()
def _DetectInputEncoding(self, file_name):
diff --git a/test/mac/gyptest-app.py b/test/mac/gyptest-app.py
index c8468cf..36942f8 100755
--- a/test/mac/gyptest-app.py
+++ b/test/mac/gyptest-app.py
@@ -42,9 +42,13 @@
test.must_not_contain(info_plist, '${MACOSX_DEPLOYMENT_TARGET}');
# Resources
- test.built_file_must_exist(
+ strings = test.built_file_path(
'Test App Gyp.app/Contents/Resources/English.lproj/InfoPlist.strings',
chdir='app-bundle')
+ test.must_exist(strings)
+ # Xcodes writes UTF-16LE with BOM.
+ test.must_contain(strings, '\xff\xfe' + '/* Localized'.encode('utf-16le'))
+
test.built_file_must_exist(
'Test App Gyp.app/Contents/Resources/English.lproj/MainMenu.nib',
chdir='app-bundle')