Backed out changeset dcba2a476ccf (bug 1305743) on request from jgraham for causing issues with mozinfo.json. a=backout

This commit is contained in:
Cosmin Sabou 2018-10-04 01:05:44 +03:00
Родитель d20960ffed
Коммит 7244d89e06
3 изменённых файлов: 24 добавлений и 74 удалений

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

@ -110,6 +110,18 @@ class TreeMetadataEmitter(LoggingMixin):
self.populate_logger()
self.config = config
mozinfo.find_and_update_from_json(config.topobjdir)
# Python 2.6 doesn't allow unicode keys to be used for keyword
# arguments. This gross hack works around the problem until we
# rid ourselves of 2.6.
self.info = {}
for k, v in mozinfo.info.items():
if isinstance(k, unicode):
k = k.encode('ascii')
self.info[k] = v
self._libs = OrderedDefaultDict(list)
self._binaries = OrderedDict()
self._compile_dirs = set()

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

@ -183,14 +183,13 @@ def sanitize(info):
def update(new_info):
"""Adds information from json file to the global symbol table.
Given the parameter new_info, this method will look for the file.
If found, the file is read into a buffer and assumed to be json.
"""
Update the info.
:param new_info: Either a dict containing the new info or a path/url
to a json file containing the new info.
"""
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
@ -216,29 +215,16 @@ def update(new_info):
globals()['isUnix'] = True
def find_and_update_from_json(*dirs, **kwargs):
"""Find a mozinfo.json file, load it, and update global symbol table.
def find_and_update_from_json(*dirs):
"""
Find a mozinfo.json file, load it, and update the info with the
contents.
This method will first check the relevant objdir directory for the
necessary mozinfo.json file, if the current script is being run from a
Mozilla objdir.
:param dirs: Directories in which to look for the file. They will be
searched after first looking in the root of the objdir
if the current script is being run from a Mozilla objdir.
If the objdir directory did not supply the necessary data, this method
will then look for the required mozinfo.json file from the provided
tuple of directories.
If file is found, the global symbols table is updated via a helper method.
If no valid files are found, an exception is raised.
:param tuple dirs: Directories in which to look for the file.
:param dict kwargs: optional values:
raise_exception: if this value is provided, the default
behavior of raising an exception is
overridden.
:returns: EnvironmentError: default behavior.
None: if exception raising is suppressed.
json_path: string representation of path.
Returns the full path to mozinfo.json if it was found, or None otherwise.
"""
# First, see if we're in an objdir
try:
@ -254,8 +240,6 @@ def find_and_update_from_json(*dirs, **kwargs):
except (BuildEnvironmentNotFoundException, MozconfigFindException):
pass
raise_exception = kwargs.get('raise_exception', True)
for d in dirs:
d = _os.path.abspath(d)
json_path = _os.path.join(d, "mozinfo.json")
@ -263,10 +247,7 @@ def find_and_update_from_json(*dirs, **kwargs):
update(json_path)
return json_path
if raise_exception:
raise EnvironmentError('{}: could not find any mozinfo.json.'.format(__name__))
else:
return None
return None
def output_to_file(path):

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

@ -75,13 +75,6 @@ class TestMozinfo(unittest.TestCase):
self.assertEqual(mozinfo.find_and_update_from_json(self.tempdir), j)
self.assertEqual(mozinfo.info["foo"], "abcdefg")
def test_find_and_update_file_no_argument(self):
"""Test that mozinfo.find_and_update_from_json can
handle not being given any arguments.
"""
with self.assertRaises(EnvironmentError):
self.assertEqual(mozinfo.find_and_update_from_json())
def test_find_and_update_file_invalid_json(self):
"""Test that mozinfo.find_and_update_from_json can
handle invalid JSON"""
@ -90,42 +83,6 @@ class TestMozinfo(unittest.TestCase):
f.write('invalid{"json":')
self.assertRaises(ValueError, mozinfo.find_and_update_from_json, self.tempdir)
def test_find_and_update_file_raise_exception(self):
"""Test that mozinfo.find_and_update_from_json raises
an IOError exception if a True boolean value is
provided as the only argument.
"""
with self.assertRaises(EnvironmentError):
mozinfo.find_and_update_from_json(raise_exception=True)
def test_find_and_update_file_raise_exception_multiple_arguments(self):
"""Test that mozinfo.find_and_update_from_json raises
an IOError exception if a True boolean value is
provided as last positional argument.
"""
with self.assertRaises(EnvironmentError):
mozinfo.find_and_update_from_json(self.tempdir, raise_exception=True)
def test_find_and_update_file_suppress_exception(self):
"""Test that mozinfo.find_and_update_from_json suppresses
an IOError exception if a False boolean value is
provided as the only argument.
"""
self.assertEqual(mozinfo.find_and_update_from_json(
raise_exception=False), None)
def test_find_and_update_file_suppress_exception_multiple_arguments(self):
"""Test that mozinfo.find_and_update_from_json suppresses
an IOError exception if a False boolean value is
provided as last positional argument.
"""
j = os.path.join(self.tempdir, "mozinfo.json")
with open(j, "w") as f:
f.write(json.dumps({"foo": "abcdefg"}))
self.assertEqual(mozinfo.find_and_update_from_json(
self.tempdir, raise_exception=False), j)
self.assertEqual(mozinfo.info["foo"], "abcdefg")
def test_find_and_update_file_mozbuild(self):
"""Test that mozinfo.find_and_update_from_json can
find mozinfo.json using the mozbuild module."""