[jhbuild/desrt/master: 7/7] sysid: handle condition sets



commit 1d9ea03d8da639cb31666c4fe0e02c40abbaf977
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Jan 2 09:56:54 2015 -0500

    sysid: handle condition sets
    
    Move the determination of the default conditions for the system to a
    better home in the sysid module.  Add conditions for the ID and ID_LIKE
    that we find in the os-release file.  That means, for example, that an
    Ubuntu system will end up with "debian" and "ubuntu" conditions set by
    default.

 jhbuild/config.py      |   27 ++-------------------------
 jhbuild/utils/sysid.py |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 25 deletions(-)
---
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 81c7797..a8ee2dd 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -31,6 +31,7 @@ import __builtin__
 
 from jhbuild.environment import setup_env, setup_env_defaults, addpath
 from jhbuild.errors import FatalError
+from jhbuild.util import sysid
 
 if sys.platform.startswith('win'):
     # For munging paths for MSYS's benefit
@@ -79,30 +80,6 @@ def parse_relative_time(s):
     else:
         raise ValueError
 
-def get_default_conditions():
-    # the default conditions set.  We determine which set to used based on
-    # the first item in the list which is a prefix of 'sys.platform', which
-    # is a name like 'linux2', 'darwin', 'freebsd10', etc.
-    #
-    # if we watch to match (eg 'freebsd10' more closely than other versions
-    # of 'freebsd') then we just need to make sure the more-specific one
-    # comes first in the list
-    conditions_sets = [
-            ('linux', ['linux', 'wayland', 'udev', 'x11', 'systemd', 'gnu-elf']),
-            ('freebsd', ['freebsd', 'x11', 'bsd', 'gnu-elf']),
-            ('darwin', ['darwin', 'macos', 'quartz']),
-
-            # this must be left here so that at least one will be found
-            ('', ['x11'])
-        ]
-
-    for prefix, flags in conditions_sets:
-        if sys.platform.startswith(prefix):
-            return set(flags)
-
-    # we will only hit this if someone removed the '' entry above
-    raise FatalError('failed to find matching condition set...')
-
 def modify_conditions(conditions, conditions_modifiers):
     for flag in conditions_modifiers:
         for mod in flag.split(','):
@@ -183,7 +160,7 @@ class Config:
         # on it to set new autogenargs, for example) but also so that the
         # condition flags given on the commandline will ultimately override
         # those in jhbuildrc.
-        self._config['conditions'] = get_default_conditions()
+        self._config['conditions'] = sysid.get_default_conditions()
         modify_conditions(self._config['conditions'], conditions_modifiers)
         self.load(filename)
         modify_conditions(self.conditions, conditions_modifiers)
diff --git a/jhbuild/utils/sysid.py b/jhbuild/utils/sysid.py
index 2cf784f..ca9de14 100644
--- a/jhbuild/utils/sysid.py
+++ b/jhbuild/utils/sysid.py
@@ -23,6 +23,7 @@ import ast
 
 sys_id = None
 sys_name = None
+default_conditions = None
 
 def read_os_release():
     global sys_name
@@ -69,6 +70,11 @@ def read_os_release():
         # fall back
         sys_name = fields['ID'] + ' ' + fields['VERSION_ID']
 
+    default_conditions.add(fields['ID'])
+
+    if 'ID_LIKE' in fields:
+        default_conditions.union(fields['ID_LIKE'].split(' '))
+
     return True
 
 def get_macos_info():
@@ -93,6 +99,26 @@ def ensure_loaded():
     if sys_id is not None:
         return
 
+    # the default conditions set.  We determine which set to used based on
+    # the first item in the list which is a prefix of 'sys.platform', which
+    # is a name like 'linux2', 'darwin', 'freebsd10', etc.
+    #
+    # if we watch to match (eg 'freebsd10' more closely than other versions
+    # of 'freebsd') then we just need to make sure the more-specific one
+    # comes first in the list
+    conditions_sets = [
+            ('linux', ['linux', 'wayland', 'udev', 'x11', 'systemd', 'gnu-elf']),
+            ('freebsd', ['freebsd', 'x11', 'bsd', 'gnu-elf']),
+            ('darwin', ['darwin', 'macos', 'quartz']),
+
+            # this must be left here so that at least one will be found
+            ('', ['x11'])
+        ]
+
+    for prefix, flags in conditions_sets:
+        if sys.platform.startswith(prefix):
+            default_conditions = set(flags)
+
     # our first choice is to use os-release info
     if read_os_release():
         return


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]