Try to pass dependency options into dependencies().
[cdist.git] / cdist
diff --git a/cdist b/cdist
index 515e81b0e98fd8eeb7c265bd92065b9697a6942f..38d7810dcc415c9f274cd5c88bb44bc700d3fff7 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -16,6 +16,7 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+from __future__ import print_function
 import os
 import sys
 import shutil
@@ -328,7 +329,7 @@ class Target(object):
     def package(self, project, checkout):
         tree = globals.trees.get(project, checkout, self)
         tree.build_dependencies()
-        tree.build(tree)
+        tree.build()
         return tree.call('package', tree.version), tree.git_commit
 
     def test(self, tree):
@@ -421,7 +422,7 @@ class LinuxTarget(Target):
         self.set('CXXFLAGS', '-I%s/include' % self.directory)
         self.set('CPPFLAGS', '')
         self.set('LINKFLAGS', '-L%s/lib' % self.directory)
-        self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:/usr/local/lib/pkgconfig' % self.directory)
+        self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
         self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
 
 class ChrootTarget(LinuxTarget):
@@ -542,19 +543,27 @@ def target_factory(s, debug, work):
         if len(p) != 3:
             raise Error("Bad Linux target name `%s'; must be something like ubuntu-12.04-32 (i.e. distro-version-bits)" % s)
         target = ChrootTarget(p[0], p[1], int(p[2]), work)
+    elif s.startswith('arch-'):
+        p = s.split('-')
+        if len(p) != 2:
+            raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
+        target = ChrootTarget(p[0], None, p[1], work)
     elif s == 'raspbian':
         target = ChrootTarget(s, None, None, work)
     elif s == 'host':
+        if command_and_read('uname -m').read().strip() == 'x86_64':
+            bits = 64
+        else:
+            bits = 32
         try:
             f = open('/etc/fedora-release', 'r')
             l = f.readline().strip().split()
-            if command_and_read('uname -m').read().strip() == 'x86_64':
-                bits = 64
-            else:
-                bits = 32
             target = HostTarget("fedora", l[2], bits, work)
         except Exception as e:
-            raise Error("could not identify distribution for `host' target (%s)" % e)
+            if os.path.exists('/etc/arch-release'):
+                target = HostTarget("arch", None, bits, work)
+            else:
+                raise Error("could not identify distribution for `host' target (%s)" % e)
     elif s.startswith('osx-'):
         target = OSXSingleTarget(int(s.split('-')[1]), work)
     elif s == 'osx':
@@ -618,7 +627,7 @@ class Tree(object):
         proj = '%s/src/%s' % (target.directory, self.name)
 
         self.cscript = {}
-        execfile('%s/cscript' % proj, self.cscript)
+        exec(open('%s/cscript' % proj).read(), self.cscript)
 
         if os.path.exists('%s/wscript' % proj):
             v = read_wscript_variable(proj, "VERSION");
@@ -631,12 +640,16 @@ class Tree(object):
         with TreeDirectory(self):
             return self.cscript[function](self.target, *args)
 
-    def build_dependencies(self):
+    def build_dependencies(self, options=None):
         if 'dependencies' in self.cscript:
-            for d in self.cscript['dependencies'](self.target):
+            if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
+                deps = self.call('dependencies', options)
+            else:
+                deps = self.call('dependencies')
+
+            for d in deps:
                 log('Building dependency %s %s of %s' % (d[0], d[1], self.name))
                 dep = globals.trees.get(d[0], d[1], self.target)
-                dep.build_dependencies()
 
                 # Make the options to pass in from the option_defaults of the thing
                 # we are building and any options specified by the parent.
@@ -647,6 +660,7 @@ class Tree(object):
                         for k, v in d[2].items():
                             options[k] = v
 
+                dep.build_dependencies(options)
                 dep.build(options)
 
     def build(self, options=None):