Bug 1575135 - Make configure complain on non-unicode strings. r=nalexander

Make it a hard error when the sandbox returns non-unicode strings.
This should help quickly catch any remaining non-unicode string that
are not caught by automation.

Differential Revision: https://phabricator.services.mozilla.com/D42607

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2019-08-20 21:31:34 +00:00
Родитель e0be5605ec
Коммит d097494bcc
2 изменённых файлов: 28 добавлений и 11 удалений

Просмотреть файл

@ -10,6 +10,7 @@ import logging
import os
import sys
import textwrap
from collections import Iterable
base_dir = os.path.abspath(os.path.dirname(__file__))
@ -27,6 +28,7 @@ from mozbuild.util import (
system_encoding,
)
import mozpack.path as mozpath
import six
def main(argv):
@ -45,6 +47,27 @@ def main(argv):
return config_status(config)
def check_unicode(obj):
'''Recursively check that all strings in the object are unicode strings.'''
if isinstance(obj, dict):
result = True
for k, v in six.iteritems(obj):
if not check_unicode(k):
print("%s key is not unicode." % k, file=sys.stderr)
result = False
elif not check_unicode(v):
print("%s value is not unicode." % k, file=sys.stderr)
result = False
return result
if isinstance(obj, bytes):
return False
if isinstance(obj, six.text_type):
return True
if isinstance(obj, Iterable):
return all(check_unicode(o) for o in obj)
return True
def config_status(config):
# Sanitize config data to feed config.status
# Ideally, all the backend and frontend code would handle the booleans, but
@ -71,6 +94,11 @@ def config_status(config):
sanitized_config['topobjdir'] = config['TOPOBJDIR']
sanitized_config['mozconfig'] = config.get('MOZCONFIG')
if not check_unicode(sanitized_config):
print("Configuration should be all unicode.", file=sys.stderr)
print("Please file a bug for the above.", file=sys.stderr)
sys.exit(1)
# Create config.status. Eventually, we'll want to just do the work it does
# here, when we're able to skip configure tests/use cached results/not rely
# on autoconf.

Просмотреть файл

@ -334,17 +334,6 @@ class TestMozbuildSandbox(unittest.TestCase):
for item in sandbox['CONFIGURE_SUBST_FILES']:
self.assertIsInstance(item, SourcePath)
def test_invalid_utf8_substs(self):
"""Ensure invalid UTF-8 in substs is converted with an error."""
# This is really mbcs. It's a bunch of invalid UTF-8.
config = MockConfig(extra_substs={'BAD_UTF8': b'\x83\x81\x83\x82\x3A'})
sandbox = MozbuildSandbox(Context(VARIABLES, config))
self.assertEqual(sandbox['CONFIG']['BAD_UTF8'],
u'\ufffd\ufffd\ufffd\ufffd:')
def test_invalid_exports_set_base(self):
sandbox = self.sandbox()