Bug 1362872 - Use mbcs encoding for vswhere output. r?gps
We add vswhere.exe to support VS2017. But the description output of this command is localized, so it causes UnicodeDecodeError.
So we should use 'mbcs' encoding for this output on Windows platform. And for minor languages, we should also use replace to avoid decode error.
test_toolchain_configure.py calls vc_compiler_path without correct host.kernel, so we should check current python platform.
MozReview-Commit-ID: AkryAzrgSzs
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -408,19 +408,21 @@ def check_compiler(compiler, language, t
target_endianness=info.endianness,
flags=flags,
)
@imports(_from='__builtin__', _import='open')
@imports('json')
@imports('subprocess')
+@imports('sys')
def get_vc_paths(topsrcdir):
def vswhere(args):
- return json.loads(subprocess.check_output([os.path.join(topsrcdir, 'build/win32/vswhere.exe'), '-format', 'json'] + args))
+ encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
+ return json.loads(subprocess.check_output([os.path.join(topsrcdir, 'build/win32/vswhere.exe'), '-format', 'json'] + args).decode(encoding, 'replace'))
# Can't pass -requires with -legacy, so query each separately.
# Legacy versions first (VS2015)
for install in vswhere(['-legacy', '-version', '[14.0,15.0)']):
version = Version(install['installationVersion'])
# Skip anything older than VS2015.
if version < '14':
continue