[jhbuild] sysdeps: Support alternative dependencies



commit 1ebdf58f7622612ba8088eeca12cb30cf781a43a
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Mon Sep 21 02:40:42 2015 +0800

    sysdeps: Support alternative dependencies
    
    Some system dependencies, such as LLVM, cannot be easily detected with
    single c_include or path because different distributions can install the
    same things in different places with different names.
    
    To resolve this problem, we add a new type of tag <altdep>, which can be
    used as a child node of <dep> in <systemdependencies> to specify the
    list of alternative c_include and path. The syntax of <altdep> and <dep>
    are the same, so we can reuse code used to process <dep>.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=754041

 jhbuild/commands/sysdeps.py      |    6 +++---
 jhbuild/modtypes/__init__.py     |    9 ++++++---
 jhbuild/modtypes/systemmodule.py |    4 ++--
 jhbuild/utils/systeminstall.py   |   23 +++++++++++++++++------
 modulesets/moduleset.dtd         |    7 ++++++-
 modulesets/moduleset.rnc         |    3 ++-
 6 files changed, 36 insertions(+), 16 deletions(-)
---
diff --git a/jhbuild/commands/sysdeps.py b/jhbuild/commands/sysdeps.py
index c54407e..55d5221 100644
--- a/jhbuild/commands/sysdeps.py
+++ b/jhbuild/commands/sysdeps.py
@@ -78,7 +78,7 @@ class cmd_sysdeps(cmd_build):
                         print 'pkgconfig:{0}'.format(module.pkg_config[:-3]) # remove .pc
 
                     if module.systemdependencies is not None:
-                        for dep_type, value in module.systemdependencies:
+                        for dep_type, value, altdeps in module.systemdependencies:
                             print '{0}:{1}'.format(dep_type, value)
 
             return
@@ -111,7 +111,7 @@ class cmd_sysdeps(cmd_build):
                         print 'pkgconfig:{0}'.format(module.pkg_config[:-3]) # remove .pc
 
                     if module.systemdependencies is not None:
-                        for dep_type, value in module.systemdependencies:
+                        for dep_type, value, altdeps in module.systemdependencies:
                             print '{0}:{1}'.format(dep_type, value)
 
             if have_too_old:
@@ -153,7 +153,7 @@ class cmd_sysdeps(cmd_build):
                 if module.pkg_config is not None:
                     uninstalled.append((module.name, 'pkgconfig', module.pkg_config[:-3])) # remove .pc
                 elif module.systemdependencies is not None:
-                    for dep_type, value in module.systemdependencies:
+                    for dep_type, value, altdeps in module.systemdependencies:
                         uninstalled.append((module.name, dep_type, value))
         if len(uninstalled) == 0:
             print _('    (none)')
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index 51ce4d2..41daa3d 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -78,9 +78,9 @@ def get_dependencies(node):
                             node.getAttribute('id'))
                 list.append(package)
 
-    def add_to_system_dependencies(lst, childnode):
+    def add_to_system_dependencies(lst, childnode, tag='dep'):
         for dep in childnode.childNodes:
-            if dep.nodeType == dep.ELEMENT_NODE and dep.nodeName == 'dep':
+            if dep.nodeType == dep.ELEMENT_NODE and dep.nodeName == tag:
                 typ = dep.getAttribute('type')
                 if not typ:
                     raise FatalError(_('%(node)s node for %(module)s module is'
@@ -95,7 +95,10 @@ def get_dependencies(node):
                                      {'node_name'   : 'dep',
                                       'module_name' : node.getAttribute('id'),
                                       'attribute'   : 'name'})
-                lst.append((typ, name))
+                altdeps = []
+                if dep.childNodes:
+                    add_to_system_dependencies(altdeps, dep, 'altdep')
+                lst.append((typ, name, altdeps))
 
     for childnode in node.childNodes:
         if childnode.nodeType != childnode.ELEMENT_NODE: continue
diff --git a/jhbuild/modtypes/systemmodule.py b/jhbuild/modtypes/systemmodule.py
index f2e430e..92b6483 100644
--- a/jhbuild/modtypes/systemmodule.py
+++ b/jhbuild/modtypes/systemmodule.py
@@ -27,13 +27,13 @@ __all__ = [ 'SystemModule' ]
 class SystemModule(Package):
     @classmethod
     def create_virtual(cls, name, branch, deptype, value):
-        return cls(name, branch=branch, systemdependencies=[(deptype, value)])
+        return cls(name, branch=branch, systemdependencies=[(deptype, value, [])])
 
 def parse_systemmodule(node, config, uri, repositories, default_repo):
     instance = SystemModule.parse_from_xml(node, config, uri, repositories,
                                            default_repo)
 
-    if any(deptype == 'xml' for deptype, value in instance.systemdependencies):
+    if any(deptype == 'xml' for deptype, value, altdeps in instance.systemdependencies):
         instance.dependencies += ['xmlcatalog']
 
     return instance
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 5b3432f..16f4c18 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -128,11 +128,12 @@ def systemdependencies_met(module_name, sysdeps, config):
         return paths
 
     c_include_search_paths = None
-    for dep_type, value in sysdeps:
+    for dep_type, value, altdeps in sysdeps:
+        dep_met = True
         if dep_type.lower() == 'path':
             if os.path.split(value)[0]:
                 if not os.path.isfile(value) and not os.access(value, os.X_OK):
-                    return False
+                    dep_met = False
             else:
                 pathdirs = set(os.environ.get('PATH', '').split(os.pathsep))
                 pathdirs.update(['/sbin', '/usr/sbin'])
@@ -141,7 +142,7 @@ def systemdependencies_met(module_name, sysdeps, config):
                     if os.path.isfile(filename) and os.access(filename, os.X_OK):
                         break
                 else:
-                    return False
+                    dep_met = False
         elif dep_type.lower() == 'c_include':
             if c_include_search_paths is None:
                 c_include_search_paths = get_c_include_search_paths(config)
@@ -152,13 +153,13 @@ def systemdependencies_met(module_name, sysdeps, config):
                     found = True
                     break
             if not found:
-                return False
+                dep_met = False
 
         elif dep_type == 'python2':
             try:
                 imp.find_module(value)
             except:
-                return False
+                dep_met = False
 
         elif dep_type == 'xml':
             xml_catalog = '/etc/xml/catalog'
@@ -174,7 +175,17 @@ def systemdependencies_met(module_name, sysdeps, config):
                 subprocess.check_output(['xmlcatalog', xml_catalog, value])
 
             except:
-                return False
+                dep_met = False
+
+        # check alternative dependencies
+        if not dep_met and altdeps:
+            for altdep in altdeps:
+                if systemdependencies_met(module_name, [ altdep ], config):
+                    dep_met = True
+                    break
+
+        if not dep_met:
+            return False
 
     return True
 
diff --git a/modulesets/moduleset.dtd b/modulesets/moduleset.dtd
index 9246053..a85c9b5 100644
--- a/modulesets/moduleset.dtd
+++ b/modulesets/moduleset.dtd
@@ -180,7 +180,7 @@
 <!ELEMENT suggests (dep|if)*>
 <!ELEMENT after (dep*)>
 <!ELEMENT systemdependencies (dep*)>
-<!ELEMENT dep EMPTY>
+<!ELEMENT dep (altdep*)>
 <!-- This is actually 2 different types of element: <dep package=""/> as used in <dependencies>
      and <dep type="" name=""/> as used in <systemdependencies>. The DTD can't specify both
      separately since they have the same element name. -->
@@ -188,6 +188,11 @@
        package CDATA   #IMPLIED
        type    CDATA   #IMPLIED
        name    CDATA   #IMPLIED>
+<!-- <altdep> is only used in <systemdependencies> to specify alternative dependencies. -->
+<!ELEMENT altdep EMPTY>
+<!ATTLIST altdep
+       type    CDATA   #IMPLIED
+       name    CDATA   #IMPLIED>
 
 <!ELEMENT branch (patch*,quilt*)>
 <!ATTLIST branch
diff --git a/modulesets/moduleset.rnc b/modulesets/moduleset.rnc
index 701e8d2..b25a36a 100644
--- a/modulesets/moduleset.rnc
+++ b/modulesets/moduleset.rnc
@@ -227,8 +227,9 @@ systemdependencies = element systemdependencies { attlist.systemdependencies, sy
 attlist.systemdependencies &= empty
 dep = element dep { attlist.dep, empty }
 attlist.dep &= attribute package { text }
-sysdep = element dep { attlist.sysdep, empty }
+sysdep = element dep { attlist.sysdep, altdep* }
 attlist.sysdep &= attribute type { text }, attribute name { text }
+altdep = element altdep { attlist.sysdep }
 branch = element branch { attlist.branch, patch*, quilt* }
 attlist.branch &=
   attribute repo { text }?,


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