Bug 1286900 - Add environment variable to define location of mozinfo.json; r=ted
☠☠ backed out by aed585286446 ☠ ☠
authorGregory Szorc <gps@mozilla.com>
Mon, 26 Sep 2016 15:51:32 -0700
changeset 315351 6b5f059a85ad581fe9078941c80a8e22869f8149
parent 315350 c5d6e4be64b0da45b32832f7df6f8eeac4a75eed
child 315352 01c3527edde5d90114b72e52e5890b43e6ba15cb
push id30748
push usercbook@mozilla.com
push dateWed, 28 Sep 2016 13:53:19 +0000
treeherdermozilla-central@8c84b7618840 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1286900
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286900 - Add environment variable to define location of mozinfo.json; r=ted As part of converting WPT to run from a source checkout in automation, I ran into problems where mozinfo.json wasn't being loaded, causing several tests to fail. This is because mozinfo.json is only found from a source directory or from a parent of the WPT meta directory. Before, mozinfo.json was provided by the "common" tests zip file and extracted to the base of the destination directory. WPT files were extracted to a "web-platform" sub-directory. So mozinfo.json was in a parent directory of "web-platform/meta" and was loaded automatically. Now that we want to run WPT out of the source directory, there is no mozinfo.json and the source directory and no mozinfo.json can be loaded. This commit teaches mozinfo.json to look in a MOZINFO_PATH environment variable for the path to mozinfo.json. This allows mozinfo.json to exist anywhere on the filesystem. This provides a lot more flexibility for loading the file. MozReview-Commit-ID: 1I1cxS1IeyY
testing/mozbase/mozinfo/mozinfo/mozinfo.py
testing/mozbase/mozinfo/tests/test.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -196,23 +196,30 @@ def update(new_info):
     if isLinux or isBsd:
         globals()['isUnix'] = True
 
 def find_and_update_from_json(*dirs):
     """
     Find a mozinfo.json file, load it, and update the info with the
     contents.
 
-    :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.
+    The search strategy is as follows. The first available file is used.
+
+    1) MOZINFO_PATH environment variable.
+    2) objdir (via a build system context)
+    3) Traversing directories ``dirs`` for a mozinfo.json file.
 
     Returns the full path to mozinfo.json if it was found, or None otherwise.
     """
-    # First, see if we're in an objdir
+    env_path = _os.environ.get('MOZINFO_PATH', None)
+    if env_path:
+        # Will raise if path does not exist or can't be loaded.
+        update(env_path)
+        return env_path
+
     try:
         from mozbuild.base import MozbuildObject, BuildEnvironmentNotFoundException
         build = MozbuildObject.from_environment()
         json_path = _os.path.join(build.topobjdir, "mozinfo.json")
         if _os.path.isfile(json_path):
             update(json_path)
             return json_path
     except ImportError:
--- a/testing/mozbase/mozinfo/tests/test.py
+++ b/testing/mozbase/mozinfo/tests/test.py
@@ -48,16 +48,31 @@ class TestMozinfo(unittest.TestCase):
 
     def test_update_file_invalid_json(self):
         """Test that mozinfo.update handles invalid JSON correctly"""
         j = os.path.join(self.tempdir,'test.json')
         with open(j, 'w') as f:
             f.write('invalid{"json":')
         self.assertRaises(ValueError,mozinfo.update,[j])
 
+    def test_find_and_update_file_env(self):
+        """mozinfo.find_and_update_json finds path from environment variable."""
+        j = os.path.join(self.tempdir, 'explicit_mozinfo.json')
+        with open(j, 'w') as fh:
+            json.dump({'foo': 'environment'}, fh)
+
+        old_env = dict(os.environ)
+        try:
+            os.environ['MOZINFO_PATH'] = j
+            self.assertEqual(mozinfo.find_and_update_from_json(), j)
+            self.assertEqual(mozinfo.info['foo'], 'environment')
+        finally:
+            os.environ.clear()
+            os.environ.update(old_env)
+
     def test_find_and_update_file(self):
         """Test that mozinfo.find_and_update_from_json can
         find mozinfo.json in a directory passed to it."""
         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), j)
         self.assertEqual(mozinfo.info["foo"], "abcdefg")