Fix unreference variable.
[cdist.git] / cdist
diff --git a/cdist b/cdist
index 48eb9eb95c3cab861f875f1a9d99a307ce3581c2..682924413cc5f5001a300873ac20e38cff882ab6 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 #    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
 #
@@ -103,6 +103,7 @@ class Config:
     def __init__(self):
         self.options = [ Option('mxe_prefix'),
                          Option('git_prefix'),
+                         Option('git_reference'),
                          Option('osx_environment_prefix'),
                          Option('osx_sdk_prefix'),
                          Option('osx_sdk'),
@@ -461,11 +462,11 @@ class Target(object):
             log_normal("Deprecated cscript package() method with no options parameter")
             packages = tree.call('package', tree.version)
 
-        if isinstance(packages, (str, unicode)):
-            copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
-        else:
+        if isinstance(packages, list):
             for p in packages:
                 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
+        else:
+            copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
 
     def build(self, project, checkout, options):
         tree = globals.trees.get(project, checkout, self)
@@ -547,8 +548,10 @@ class DockerTarget(Target):
             opts += '-v %s:%s ' % (m, m)
         if self.privileged:
             opts += '--privileged=true '
+        if config.has('git_reference'):
+            opts += '-v %s:%s ' % (config.get('git_reference'), config.get('git_reference'))
         if self.ccache:
-            opts += "-e CCACHE_DIR=/ccache --volumes-from ccache-%s" % self.image
+            opts += "-e CCACHE_DIR=/ccache/%s --mount source=ccache,target=/ccache" % self.image
 
         tag = self.image
         if config.has('docker_hub_repository'):
@@ -773,7 +776,7 @@ class OSXUniversalTarget(OSXTarget):
 
         tree = globals.trees.get(project, checkout, self)
         with TreeDirectory(tree):
-            if len(inspect.getargspec(tree.cscript['package']).args) == 3:
+            if len(inspect.getfullargspec(tree.cscript['package']).args) == 3:
                 packages = tree.call('package', tree.version, options)
             else:
                 log_normal("Deprecated cscript package() method with no options parameter")
@@ -901,7 +904,11 @@ class Tree(object):
         if globals.quiet:
             flags = '-q'
             redirect = '>/dev/null'
-        command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
+        if config.has('git_reference'):
+            ref = '--reference-if-able %s/%s.git' % (config.get('git_reference'), self.name)
+        else:
+            ref = ''
+        command('git clone %s %s %s/%s.git %s/src/%s' % (flags, ref, config.get('git_prefix'), self.name, target.directory, self.name))
         os.chdir('%s/src/%s' % (target.directory, self.name))
 
         spec = self.specifier
@@ -917,9 +924,19 @@ class Tree(object):
         exec(open('%s/cscript' % proj).read(), self.cscript)
 
         # cscript can include submodules = False to stop submodules being fetched
-        if not 'submodules' in self.cscript or self.cscript['submodules'] == True:
-            command('git submodule init --quiet')
-            command('git submodule update --quiet')
+        if (not 'submodules' in self.cscript or self.cscript['submodules'] == True) and os.path.exists('.gitmodules'):
+            command('git submodule --quiet init')
+            paths = command_and_read('git config --file .gitmodules --get-regexp path')
+            urls = command_and_read('git config --file .gitmodules --get-regexp url')
+            for path, url in zip(paths, urls):
+                path = path.split(' ')[1]
+                url = url.split(' ')[1]
+            ref = ''
+            if config.has('git_reference'):
+                ref_path = os.path.join(config.get('git_reference'), os.path.basename(url))
+                if os.path.exists(ref_path):
+                    ref = '--reference %s' % ref_path
+            command('git submodule --quiet update %s %s' % (ref, path))
 
         if os.path.exists('%s/wscript' % proj):
             v = read_wscript_variable(proj, "VERSION");
@@ -958,7 +975,7 @@ class Tree(object):
         if not 'dependencies' in self.cscript:
             return
 
-        if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
+        if len(inspect.getfullargspec(self.cscript['dependencies']).args) == 2:
             self_options = copy.copy(options)
             self.add_defaults(self_options)
             deps = self.call('dependencies', self_options)