X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=cdist;h=2474307b0f8397595d5c089fc303531c1cd9c2ef;hb=2040b172163bea277be6ffe712bfd8a04dcbdb86;hp=48eb9eb95c3cab861f875f1a9d99a307ce3581c2;hpb=3930f701f7cd012389fa5920deec60a7d2593277;p=cdist.git diff --git a/cdist b/cdist index 48eb9eb..2474307 100755 --- a/cdist +++ b/cdist @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # Copyright (C) 2012-2020 Carl Hetherington # @@ -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'), @@ -445,7 +446,7 @@ class Target(object): self.set('CCACHE_BASEDIR', os.path.realpath(self.directory)) self.set('CCACHE_NOHASHDIR', '') else: - self.directory = directory + self.directory = os.path.realpath(directory) self.rmdir = False @@ -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) @@ -541,14 +542,19 @@ class DockerTarget(Target): return '' return '-u %s' % getpass.getuser() + def _mount_option(self, d): + return '-v %s:%s ' % (os.path.realpath(d), os.path.realpath(d)) + def setup(self): - opts = '-v %s:%s ' % (self.directory, self.directory) + opts = self._mount_option(self.directory) for m in self.mounts: - opts += '-v %s:%s ' % (m, m) + opts += self._mount_option(m) + if config.has('git_reference'): + opts += self._mount_option(config.get('git_reference')) if self.privileged: opts += '--privileged=true ' 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 +779,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 +907,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 +927,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 +978,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)