Skip to content

Commit

Permalink
Bug 1575135 - Make configure complain on non-unicode strings. r=nalex…
Browse files Browse the repository at this point in the history
…ander

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
  • Loading branch information
glandium committed Aug 20, 2019
1 parent 1070c4c commit a01aea4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
28 changes: 28 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import sys
import textwrap
from collections import Iterable


base_dir = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -27,6 +28,7 @@
system_encoding,
)
import mozpack.path as mozpath
import six


def main(argv):
Expand All @@ -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
Expand All @@ -71,6 +94,11 @@ def sanitized_bools(v):
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.
Expand Down
11 changes: 0 additions & 11 deletions python/mozbuild/mozbuild/test/frontend/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,6 @@ def test_substitute_config_files(self):
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()

Expand Down

0 comments on commit a01aea4

Please sign in to comment.