Bug 945869 - Provide more granular OS version information in mozinfo. r=ted.mielczarek
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Thu, 01 May 2014 06:09:00 +0200
changeset 181500 e09e3bce7c0de625c4e90870e015c581f8e676e8
parent 181499 bd8c63e9eb926f64904def15a43ad923d988ce3d
child 181501 d685863eb71f876767ae116ff02e5bfbb96994b8
push idunknown
push userunknown
push dateunknown
reviewersted.mielczarek
bugs945869
milestone32.0a1
Bug 945869 - Provide more granular OS version information in mozinfo. r=ted.mielczarek
python/mozbuild/mozbuild/frontend/emitter.py
testing/mozbase/mozinfo/mozinfo/mozinfo.py
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -11,16 +11,18 @@ import traceback
 import sys
 import time
 
 from mach.mixin.logging import LoggingMixin
 
 import mozpack.path as mozpath
 import manifestparser
 
+import mozinfo
+
 from .data import (
     ConfigFileSubstitution,
     Defines,
     DirectoryTraversal,
     Exports,
     GeneratedEventWebIDLFile,
     GeneratedInclude,
     GeneratedWebIDLFile,
@@ -64,22 +66,26 @@ class TreeMetadataEmitter(LoggingMixin):
     module.
     """
 
     def __init__(self, config):
         self.populate_logger()
 
         self.config = config
 
-        # TODO add mozinfo into config or somewhere else.
-        mozinfo_path = mozpath.join(config.topobjdir, 'mozinfo.json')
-        if os.path.exists(mozinfo_path):
-            self.mozinfo = json.load(open(mozinfo_path, 'rt'))
-        else:
-            self.mozinfo = {}
+        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 = {}
         self._final_libs = []
 
     def emit(self, output):
         """Convert the BuildReader output into data structures.
 
         The return value from BuildReader.read_topsrcdir() (a generator) is
@@ -471,17 +477,17 @@ class TreeMetadataEmitter(LoggingMixin):
                 dupe_manifest='dupe-manifest' in defaults)
 
             filtered = m.tests
 
             if filter_inactive:
                 # We return tests that don't exist because we want manifests
                 # defining tests that don't exist to result in error.
                 filtered = m.active_tests(exists=False, disabled=False,
-                    **self.mozinfo)
+                    **self.info)
 
                 missing = [t['name'] for t in filtered if not os.path.exists(t['path'])]
                 if missing:
                     raise SandboxValidationError('Test manifest (%s) lists '
                         'test that does not exist: %s' % (
                         path, ', '.join(missing)))
 
             out_dir = mozpath.join(install_prefix, manifest_reldir)
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -26,52 +26,59 @@ class unknown(object):
     def __str__(self):
         return 'UNKNOWN'
 unknown = unknown() # singleton
 
 # get system information
 info = {'os': unknown,
         'processor': unknown,
         'version': unknown,
+        'os_version': unknown,
         'bits': unknown }
 (system, node, release, version, machine, processor) = platform.uname()
 (bits, linkage) = platform.architecture()
 
 # get os information and related data
 if system in ["Microsoft", "Windows"]:
     info['os'] = 'win'
     # There is a Python bug on Windows to determine platform values
     # http://bugs.python.org/issue7860
     if "PROCESSOR_ARCHITEW6432" in os.environ:
         processor = os.environ.get("PROCESSOR_ARCHITEW6432", processor)
     else:
         processor = os.environ.get('PROCESSOR_ARCHITECTURE', processor)
     system = os.environ.get("OS", system).replace('_', ' ')
-    service_pack = os.sys.getwindowsversion()[4]
+    (major, minor, _, _, service_pack) = os.sys.getwindowsversion()
     info['service_pack'] = service_pack
+    os_version = "%d.%d" % (major, minor)
 elif system == "Linux":
     if hasattr(platform, "linux_distribution"):
-        (distro, version, codename) = platform.linux_distribution()
+        (distro, os_version, codename) = platform.linux_distribution()
     else:
-        (distro, version, codename) = platform.dist()
-    version = "%s %s" % (distro, version)
+        (distro, os_version, codename) = platform.dist()
     if not processor:
         processor = machine
+    version = "%s %s" % (distro, os_version)
     info['os'] = 'linux'
+    info['linux_distro'] = distro
 elif system in ['DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD']:
     info['os'] = 'bsd'
-    version = sys.platform
+    version = os_version = sys.platform
 elif system == "Darwin":
     (release, versioninfo, machine) = platform.mac_ver()
     version = "OS X %s" % release
+    versionNums = release.split('.')[:2]
+    os_version = "%s.%s" % (versionNums[0], versionNums[1])
     info['os'] = 'mac'
 elif sys.platform in ('solaris', 'sunos5'):
     info['os'] = 'unix'
-    version = sys.platform
-info['version'] = version # os version
+    os_version = version = sys.platform
+
+info['version'] = version
+info['os_version'] = os_version
 
 # processor type and bits
 if processor in ["i386", "i686"]:
     if bits == "32bit":
         processor = "x86"
     elif bits == "64bit":
         processor = "x86_64"
 elif processor.upper() == "AMD64":
@@ -135,24 +142,26 @@ def find_and_update_from_json(*dirs):
     :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.
 
     Returns the full path to mozinfo.json if it was found, or None otherwise.
     """
     # First, see if we're in an objdir
     try:
-        from mozbuild.base import MozbuildObject
+        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:
         pass
+    except BuildEnvironmentNotFoundException:
+        pass
 
     for d in dirs:
         d = _os.path.abspath(d)
         json_path = _os.path.join(d, "mozinfo.json")
         if _os.path.isfile(json_path):
             update(json_path)
             return json_path