Expose some more stuff to OSXTarget.
[cdist.git] / cdist
diff --git a/cdist b/cdist
index c62777945f264cb68b6c9411dca59c3950608ed4..3bf9460a9690dcda316e339e2f8cecc6e568004f 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -28,7 +28,7 @@ import re
 import copy
 import inspect
 
-TEMPORARY_DIRECTORY = '/tmp'
+TEMPORARY_DIRECTORY = '/var/tmp'
 
 class Error(Exception):
     def __init__(self, value):
@@ -347,13 +347,13 @@ class Target(object):
 
     def append_with_space(self, k, v):
         if (not k in self.variables) or len(self.variables[k]) == 0:
-            self.variables[k] = v
+            self.variables[k] = '"%s"' % v
         else:
             e = self.variables[k]
             if e[0] == '"' and e[-1] == '"':
                 self.variables[k] = '"%s %s"' % (e[1:-1], v)
             else:
-                self.variables[k] = '%s %s' % (e, v)
+                self.variables[k] = '"%s %s"' % (e, v)
 
     def variables_string(self, escaped_quotes=False):
         e = ''
@@ -410,16 +410,24 @@ class WindowsTarget(Target):
         log('host -> %s' % c)
         command('%s %s' % (self.variables_string(), c))
 
-#
-# Linux
-#
-
 class LinuxTarget(Target):
+    """Parent for Linux targets"""
     def __init__(self, distro, version, bits, directory=None):
         super(LinuxTarget, self).__init__('linux', directory)
         self.distro = distro
         self.version = version
         self.bits = bits
+
+        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('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
+
+class ChrootTarget(LinuxTarget):
+    """Build in a chroot"""
+    def __init__(self, distro, version, bits, directory=None):
+        super(ChrootTarget, self).__init__(distro, version, bits, directory)
         # e.g. ubuntu-14.04-64
         if self.version is not None and self.bits is not None:
             self.chroot = '%s-%s-%d' % (self.distro, self.version, self.bits)
@@ -428,15 +436,18 @@ class LinuxTarget(Target):
         # e.g. /home/carl/Environments/ubuntu-14.04-64
         self.chroot_prefix = '%s/%s' % (config.get('linux_chroot_prefix'), self.chroot)
 
-        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('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
-
     def command(self, c):
         command('%s schroot -c %s -p -- %s' % (self.variables_string(), self.chroot, c))
 
+
+class HostTarget(LinuxTarget):
+    """Build directly on the host"""
+    def __init__(self, distro, version, bits, directory=None):
+        super(HostTarget, self).__init__(distro, version, bits, directory)
+
+    def command(self, c):
+        command('%s %s' % (self.variables_string(), c))
+
 #
 # OS X
 #
@@ -444,6 +455,8 @@ class LinuxTarget(Target):
 class OSXTarget(Target):
     def __init__(self, directory=None):
         super(OSXTarget, self).__init__('osx', directory)
+        self.sdk = config.get('osx_sdk')
+        self.sdk_prefix = config.get('osx_sdk_prefix')
 
     def command(self, c):
         command('%s %s' % (self.variables_string(False), c))
@@ -459,7 +472,7 @@ class OSXSingleTarget(OSXTarget):
         else:
             arch = 'x86_64'
 
-        flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (config.get('osx_sdk_prefix'), config.get('osx_sdk'), arch)
+        flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.osx_sdk, arch)
         enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
 
         # Environment variables
@@ -492,11 +505,8 @@ class OSXUniversalTarget(OSXTarget):
         with TreeDirectory(tree):
             return tree.call('package', tree.version), tree.git_commit
 
-#
-# Source
-#
-
 class SourceTarget(Target):
+    """Build a source .tar.bz2"""
     def __init__(self):
         super(SourceTarget, self).__init__('source')
 
@@ -530,11 +540,21 @@ def target_factory(s, debug, work):
     elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-'):
         p = s.split('-')
         if len(p) != 3:
-            print >>sys.stderr,"Bad Linux target name `%s'; must be something like ubuntu-12.04-32 (i.e. distro-version-bits)" % s
-            sys.exit(1)
-        target = LinuxTarget(p[0], p[1], int(p[2]), work)
+            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 == 'raspbian':
-        target = LinuxTarget(s, None, None, work)
+        target = ChrootTarget(s, None, None, work)
+    elif s == 'host':
+        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)
     elif s.startswith('osx-'):
         target = OSXSingleTarget(int(s.split('-')[1]), work)
     elif s == 'osx':
@@ -545,9 +565,10 @@ def target_factory(s, debug, work):
     elif s == 'source':
         target = SourceTarget()
 
-    if target is not None:
-        target.debug = debug
+    if target is None:
+        raise Error("Bad target `%s'" % s)
 
+    target.debug = debug
     return target