3 # Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 from __future__ import print_function
32 TEMPORARY_DIRECTORY = '/var/tmp'
34 class Error(Exception):
35 def __init__(self, value):
44 Store for Tree objects which re-uses already-created objects
45 and checks for requests for different versions of the same thing.
51 def get(self, name, specifier, target):
53 if t.name == name and t.specifier == specifier and t.target == target:
55 elif t.name == name and t.specifier != specifier:
56 raise Error('conflicting versions of %s requested (%s and %s)' % (name, specifier, t.specifier))
58 nt = Tree(name, specifier, target)
76 def __init__(self, key, default=None):
80 def offer(self, key, value):
84 class BoolOption(object):
85 def __init__(self, key):
89 def offer(self, key, value):
91 self.value = (value == 'yes' or value == '1' or value == 'true')
95 self.options = [ Option('mxe_prefix'),
97 Option('osx_environment_prefix'),
98 Option('osx_sdk_prefix'),
100 BoolOption('docker_sudo'),
101 Option('parallel', 4) ]
104 f = open('%s/.config/cdist' % os.path.expanduser('~'), 'r')
110 if len(l) > 0 and l[0] == '#':
113 s = l.strip().split()
115 for k in self.options:
121 for o in self.options:
124 raise Error('Required setting %s not found' % k)
128 for o in self.options:
132 if self.get('docker_sudo'):
144 if not globals.quiet:
145 print('\x1b[33m* %s\x1b[0m' % m)
148 """Escape a host:filename string for use with an scp command"""
150 assert(len(s) == 1 or len(s) == 2)
152 return '%s:"\'%s\'"' % (s[0], s[1])
154 return '\"%s\"' % s[0]
157 log('copy %s -> %s' % (scp_escape(b), scp_escape(b)))
158 command('scp -r %s %s' % (scp_escape(a), scp_escape(b)))
161 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
162 command('scp %s %s' % (scp_escape(a), scp_escape(b)))
166 Make directories either locally or on a remote host; remotely if
167 d includes a colon, otherwise locally.
169 if d.find(':') == -1:
177 command('ssh %s -- mkdir -p %s' % (s[0], s[1]))
185 shutil.rmtree(a, ignore_errors=True)
191 raise Error('command %s failed' % c)
193 def command_and_read(c):
195 p = subprocess.Popen(c.split(), stdout=subprocess.PIPE)
196 f = os.fdopen(os.dup(p.stdout.fileno()))
199 def read_wscript_variable(directory, variable):
200 f = open('%s/wscript' % directory, 'r')
207 if len(s) == 3 and s[0] == variable:
214 def set_version_in_wscript(version):
215 f = open('wscript', 'rw')
216 o = open('wscript.tmp', 'w')
223 if len(s) == 3 and s[0] == "VERSION":
224 print("Writing %s" % version)
225 print("VERSION = '%s'" % version, file=o)
227 print(l, file=o, end="")
231 os.rename('wscript.tmp', 'wscript')
233 def append_version_to_changelog(version):
235 f = open('ChangeLog', 'r')
237 log('Could not open ChangeLog')
243 f = open('ChangeLog', 'w')
244 now = datetime.datetime.now()
245 f.write('%d-%02d-%02d Carl Hetherington <cth@carlh.net>\n\n\t* Version %s released.\n\n' % (now.year, now.month, now.day, version))
248 def append_version_to_debian_changelog(version):
249 if not os.path.exists('debian'):
250 log('Could not find debian directory')
253 command('dch -b -v %s-1 "New upstream release."' % version)
255 def devel_to_git(git_commit, filename):
256 if git_commit is not None:
257 filename = filename.replace('devel', '-%s' % git_commit)
261 def __init__(self, tree):
264 self.cwd = os.getcwd()
265 os.chdir('%s/src/%s' % (self.tree.target.directory, self.tree.name))
266 def __exit__(self, type, value, traceback):
274 def __init__(self, s):
277 if s.startswith("'"):
282 if s.endswith('devel'):
286 if s.endswith('pre'):
290 self.major = int(p[0])
291 self.minor = int(p[1])
293 self.micro = int(p[2])
297 def bump_minor(self):
301 def bump_micro(self):
307 def to_release(self):
311 s = '%d.%d.%d' % (self.major, self.minor, self.micro)
321 class Target(object):
323 Class representing the target that we are building for. This is exposed to cscripts,
324 though not all of it is guaranteed 'API'. cscripts may expect:
326 platform: platform string (e.g. 'windows', 'linux', 'osx')
327 parallel: number of parallel jobs to run
328 directory: directory to work in
329 variables: dict of environment variables
330 debug: True to build a debug version, otherwise False
331 set(a, b): set the value of variable 'a' to 'b'
332 unset(a): unset the value of variable 'a'
333 command(c): run the command 'c' in the build environment
337 def __init__(self, platform, directory=None):
339 platform -- platform string (e.g. 'windows', 'linux', 'osx')
340 directory -- directory to work in; if None we will use a temporary directory
341 Temporary directories will be removed after use; specified directories will not.
343 self.platform = platform
344 self.parallel = int(config.get('parallel'))
346 # self.directory is the working directory
347 if directory is None:
348 self.directory = tempfile.mkdtemp('', 'tmp', TEMPORARY_DIRECTORY)
351 self.directory = directory
354 # Environment variables that we will use when we call cscripts
358 def package(self, project, checkout, output_dir):
359 tree = globals.trees.get(project, checkout, self)
360 tree.build_dependencies()
362 packages = tree.call('package', tree.version)
363 if isinstance(packages, (str, unicode)):
364 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
367 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
369 def build(self, project, checkout):
370 tree = globals.trees.get(project, checkout, self)
371 tree.build_dependencies()
374 def test(self, tree, test):
375 """test is the test case to run, or None"""
376 tree.build_dependencies()
378 return tree.call('test', test)
381 self.variables[a] = b
384 del(self.variables[a])
387 return self.variables[a]
389 def append_with_space(self, k, v):
390 if (not k in self.variables) or len(self.variables[k]) == 0:
391 self.variables[k] = '"%s"' % v
393 e = self.variables[k]
394 if e[0] == '"' and e[-1] == '"':
395 self.variables[k] = '"%s %s"' % (e[1:-1], v)
397 self.variables[k] = '"%s %s"' % (e, v)
399 def variables_string(self, escaped_quotes=False):
401 for k, v in self.variables.items():
403 v = v.replace('"', '\\"')
404 e += '%s=%s ' % (k, v)
409 rmtree(self.directory)
412 class WindowsTarget(Target):
414 This target exposes the following additional API:
416 version: Windows version ('xp' or None)
417 bits: bitness of Windows (32 or 64)
418 name: name of our target e.g. x86_64-w64-mingw32.shared
419 library_prefix: path to Windows libraries
420 tool_path: path to toolchain binaries
422 def __init__(self, version, bits, directory=None):
423 super(WindowsTarget, self).__init__('windows', directory)
424 self.version = version
427 self.tool_path = '%s/usr/bin' % config.get('mxe_prefix')
429 self.name = 'i686-w64-mingw32.shared'
431 self.name = 'x86_64-w64-mingw32.shared'
432 self.library_prefix = '%s/usr/%s' % (config.get('mxe_prefix'), self.name)
434 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.library_prefix)
435 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
436 self.set('PATH', '%s/bin:%s:%s' % (self.library_prefix, self.tool_path, os.environ['PATH']))
437 self.set('CC', '%s-gcc' % self.name)
438 self.set('CXX', '%s-g++' % self.name)
439 self.set('LD', '%s-ld' % self.name)
440 self.set('RANLIB', '%s-ranlib' % self.name)
441 self.set('WINRC', '%s-windres' % self.name)
442 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
443 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
444 self.set('CXXFLAGS', '"%s"' % cxx)
445 self.set('CPPFLAGS', '')
446 self.set('LINKFLAGS', '"%s"' % link)
447 self.set('LDFLAGS', '"%s"' % link)
450 def windows_prefix(self):
451 log('Deprecated property windows_prefix')
452 return self.library_prefix
455 def mingw_prefixes(self):
456 log('Deprecated property mingw_prefixes')
457 return [self.library_prefix]
460 def mingw_path(self):
461 log('Deprecated property mingw_path')
462 return self.tool_path
465 def mingw_name(self):
466 log('Deprecated property mingw_name')
469 def command(self, c):
470 log('host -> %s' % c)
471 command('%s %s' % (self.variables_string(), c))
473 class LinuxTarget(Target):
475 Build for Linux in a docker container.
476 This target exposes the following additional API:
478 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
479 version: distribution version (e.g. '12.04', '8', '6.5')
480 bits: bitness of the distribution (32 or 64)
483 def __init__(self, distro, version, bits, directory=None):
484 super(LinuxTarget, self).__init__('linux', directory)
486 self.version = version
489 self.set('CXXFLAGS', '-I%s/include' % self.directory)
490 self.set('CPPFLAGS', '')
491 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
492 self.set('PKG_CONFIG_PATH',
493 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
494 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
496 class DockerTarget(LinuxTarget):
497 """Build in a docker container"""
498 def __init__(self, distro, version, bits, directory=None):
499 super(DockerTarget, self).__init__(distro, version, bits, directory)
501 def build(self, project, checkout):
503 if checkout is not None:
504 ch = '-c %s' % checkout
505 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
506 container = command_and_read('%s run -itd %s /bin/bash' % (config.docker(), target)).read().strip()
507 command('%s exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s build -w /cdist"' % (config.docker(), container, project, target, ch))
508 command('%s kill %s' % (config.docker(), container))
510 def package(self, project, checkout, output_dir):
512 if checkout is not None:
513 ch = '-c %s' % checkout
514 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
515 container = command_and_read('%s run -itd %s /bin/bash' % (config.docker(), target)).read().strip()
516 command('%s exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s package -w /cdist"' % (config.docker(), container, project, target, ch))
517 # I can't get wildcards to work with docker cp
518 debs = command_and_read('%s exec -t %s ls -1 /%s' % (config.docker(), container, target)).read().split('\n')
522 command('%s cp %s:/%s/%s %s' % (config.docker(), container, target, d, self.directory))
523 copyfile('%s/%s' % (self.directory, d), output_dir)
524 command('%s kill %s' % (config.docker(), container))
526 class DirectTarget(LinuxTarget):
527 """Build directly in the current environment"""
528 def __init__(self, distro, version, bits, directory=None):
529 super(DirectTarget, self).__init__(distro, version, bits, directory)
531 def command(self, c):
532 command('%s %s' % (self.variables_string(), c))
535 class OSXTarget(Target):
536 def __init__(self, directory=None):
537 super(OSXTarget, self).__init__('osx', directory)
538 self.sdk = config.get('osx_sdk')
539 self.sdk_prefix = config.get('osx_sdk_prefix')
540 self.environment_prefix = config.get('osx_environment_prefix')
542 def command(self, c):
543 command('%s %s' % (self.variables_string(False), c))
546 class OSXSingleTarget(OSXTarget):
547 def __init__(self, bits, directory=None):
548 super(OSXSingleTarget, self).__init__(directory)
556 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
557 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
559 # Environment variables
560 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
561 self.set('CPPFLAGS', '')
562 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
563 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
564 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
565 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
566 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
567 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
569 def package(self, project, checkout, output_dir):
570 raise Error('cannot package non-universal OS X versions')
573 class OSXUniversalTarget(OSXTarget):
574 def __init__(self, directory=None):
575 super(OSXUniversalTarget, self).__init__(directory)
577 def package(self, project, checkout, output_dir):
580 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
581 tree = globals.trees.get(project, checkout, target)
582 tree.build_dependencies()
585 tree = globals.trees.get(project, checkout, self)
586 with TreeDirectory(tree):
587 for p in tree.call('package', tree.version):
588 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
590 class SourceTarget(Target):
591 """Build a source .tar.bz2"""
593 super(SourceTarget, self).__init__('source')
595 def command(self, c):
596 log('host -> %s' % c)
597 command('%s %s' % (self.variables_string(), c))
600 rmtree(self.directory)
602 def package(self, project, checkout, output_dir):
603 tree = globals.trees.get(project, checkout, self)
604 with TreeDirectory(tree):
605 name = read_wscript_variable(os.getcwd(), 'APPNAME')
606 command('./waf dist')
607 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
608 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
610 # @param s Target string:
612 # or ubuntu-version-{32,64}
613 # or debian-version-{32,64}
614 # or centos-version-{32,64}
615 # or fedora-version-{32,64}
618 # @param debug True to build with debugging symbols (where possible)
619 def target_factory(s, direct, debug, work):
621 if s.startswith('windows-'):
624 target = WindowsTarget(None, int(x[1]), work)
626 target = WindowsTarget(x[1], int(x[2]), work)
628 raise Error("Bad Windows target name `%s'")
629 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora'):
632 raise Error("Bad Linux target name `%s'; must be something like ubuntu-12.04-32 (i.e. distro-version-bits)" % s)
634 target = DirectTarget(p[0], p[1], int(p[2]), work)
636 target = DockerTarget(p[0], p[1], int(p[2]), work)
637 elif s.startswith('arch-'):
640 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
641 target = DockerTarget(p[0], None, p[1], work)
642 elif s == 'raspbian':
643 target = DockerTarget(s, None, None, work)
644 elif s.startswith('osx-'):
645 target = OSXSingleTarget(int(s.split('-')[1]), work)
647 if globals.command == 'build':
648 target = OSXSingleTarget(64, work)
650 target = OSXUniversalTarget(work)
652 target = SourceTarget()
654 target = DockerTarget()
657 raise Error("Bad target `%s'" % s)
668 """Description of a tree, which is a checkout of a project,
669 possibly built. This class is never exposed to cscripts.
671 name -- name of git repository (without the .git)
672 specifier -- git tag or revision to use
673 target --- target object that we are using
674 version --- version from the wscript (if one is present)
675 git_commit -- git revision that is actually being used
676 built --- true if the tree has been built yet in this run
679 def __init__(self, name, specifier, target):
681 self.specifier = specifier
684 self.git_commit = None
693 redirect = '>/dev/null'
694 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
695 os.chdir('%s/src/%s' % (target.directory, self.name))
697 spec = self.specifier
701 command('git checkout %s %s %s' % (flags, spec, redirect))
702 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
703 command('git submodule init --quiet')
704 command('git submodule update --quiet')
706 proj = '%s/src/%s' % (target.directory, self.name)
709 exec(open('%s/cscript' % proj).read(), self.cscript)
711 if os.path.exists('%s/wscript' % proj):
712 v = read_wscript_variable(proj, "VERSION");
714 self.version = Version(v)
718 def call(self, function, *args):
719 with TreeDirectory(self):
720 return self.cscript[function](self.target, *args)
722 def build_dependencies(self, options=None):
724 if not 'dependencies' in self.cscript:
727 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
728 deps = self.call('dependencies', options)
730 log("Deprecated cscipt dependencies() method with no parameter")
731 deps = self.call('dependencies')
734 dep = globals.trees.get(d[0], d[1], self.target)
737 # Make the options to pass in from the option_defaults of the thing
738 # we are building and any options specified by the parent.
739 if 'option_defaults' in dep.cscript:
740 for k, v in dep.cscript['option_defaults']().items():
744 for k, v in d[2].items():
747 msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
749 msg += ' with options %s' % options
752 dep.build_dependencies(options)
755 def build(self, options=None):
759 variables = copy.copy(self.target.variables)
761 if not globals.dry_run:
762 if len(inspect.getargspec(self.cscript['build']).args) == 2:
763 self.call('build', options)
767 self.target.variables = variables
771 # Command-line parser
777 "build": "build project",
778 "package": "package and build project",
779 "release": "release a project using its next version number (changing wscript and tagging)",
780 "pot": "build the project's .pot files",
781 "changelog": "generate a simple HTML changelog",
782 "manual": "build the project's manual",
783 "doxygen": "build the project's Doxygen documentation",
784 "latest": "print out the latest version",
785 "test": "run the project's unit tests",
786 "shell": "build the project then start a shell",
787 "checkout": "check out the project",
788 "revision": "print the head git revision number"
791 one_of = "Command is one of:\n"
793 for k, v in commands.items():
794 one_of += "\t%s\t%s\n" % (k, v)
797 parser = argparse.ArgumentParser()
798 parser.add_argument('command', help=summary)
799 parser.add_argument('-p', '--project', help='project name')
800 parser.add_argument('--minor', help='minor version number bump', action='store_true')
801 parser.add_argument('--micro', help='micro version number bump', action='store_true')
802 parser.add_argument('--major', help='major version to return with latest', type=int)
803 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
804 parser.add_argument('-o', '--output', help='output directory', default='.')
805 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
806 parser.add_argument('-t', '--target', help='target')
807 parser.add_argument('-d', '--direct', help='build in the current environment', action='store_true')
808 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
809 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
810 parser.add_argument('-w', '--work', help='override default work directory')
811 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
812 parser.add_argument('--test', help='name of test to run (with `test''), defaults to all')
813 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
814 args = parser.parse_args()
816 # Override configured stuff
817 if args.git_prefix is not None:
818 config.set('git_prefix', args.git_prefix)
820 if args.output.find(':') == -1:
821 # This isn't of the form host:path so make it absolute
822 args.output = os.path.abspath(args.output) + '/'
824 if args.output[-1] != ':' and args.output[-1] != '/':
827 # Now, args.output is 'host:', 'host:path/' or 'path/'
829 if args.work is not None:
830 args.work = os.path.abspath(args.work)
832 if args.project is None and args.command != 'shell':
833 raise Error('you must specify -p or --project')
835 globals.quiet = args.quiet
836 globals.command = args.command
837 globals.dry_run = args.dry_run
839 if not globals.command in commands:
840 e = 'command must be one of:\n' + one_of
841 raise Error('command must be one of:\n%s' % one_of)
843 if globals.command == 'build':
844 if args.target is None:
845 raise Error('you must specify -t or --target')
847 target = target_factory(args.target, args.direct, args.debug, args.work)
848 target.build(args.project, args.checkout)
852 elif globals.command == 'package':
853 if args.target is None:
854 raise Error('you must specify -t or --target')
856 target = target_factory(args.target, args.direct, args.debug, args.work)
858 if target.platform == 'linux':
859 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
861 output_dir = args.output
864 target.package(args.project, args.checkout, output_dir)
869 elif globals.command == 'release':
870 if args.minor is False and args.micro is False:
871 raise Error('you must specify --minor or --micro')
873 target = SourceTarget()
874 tree = globals.trees.get(args.project, args.checkout, target)
876 version = tree.version
883 with TreeDirectory(tree):
884 set_version_in_wscript(version)
885 append_version_to_changelog(version)
886 append_version_to_debian_changelog(version)
888 command('git commit -a -m "Bump version"')
889 command('git tag -m "v%s" v%s' % (version, version))
892 set_version_in_wscript(version)
893 command('git commit -a -m "Bump version"')
895 command('git push --tags')
899 elif globals.command == 'pot':
900 target = SourceTarget()
901 tree = globals.trees.get(args.project, args.checkout, target)
903 pots = tree.call('make_pot')
905 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
909 elif globals.command == 'changelog':
910 target = SourceTarget()
911 tree = globals.trees.get(args.project, args.checkout, target)
913 with TreeDirectory(tree):
914 text = open('ChangeLog', 'r')
916 html = tempfile.NamedTemporaryFile()
927 if len(l) > 0 and l[0] == "\t":
929 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
932 if last is not None and len(changes) > 0:
933 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
934 print("<ul>", file=html)
936 print("<li>%s" % c, file=html)
937 print("</ul>", file=html)
947 changes.append(c[2:])
949 changes[-1] += " " + c
951 copyfile(html.file, '%schangelog.html' % args.output)
955 elif globals.command == 'manual':
956 target = SourceTarget()
957 tree = globals.trees.get(args.project, args.checkout, target)
959 outs = tree.call('make_manual')
961 if os.path.isfile(o):
962 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
964 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
968 elif globals.command == 'doxygen':
969 target = SourceTarget()
970 tree = globals.trees.get(args.project, args.checkout, target)
972 dirs = tree.call('make_doxygen')
973 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
977 copytree(d, args.output)
981 elif globals.command == 'latest':
982 target = SourceTarget()
983 tree = globals.trees.get(args.project, args.checkout, target)
985 with TreeDirectory(tree):
986 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
988 while latest is None:
990 m = re.compile(".*\((.*)\).*").match(t)
992 tags = m.group(1).split(', ')
997 if len(t) > 0 and t[0] == 'v':
999 if args.major is None or v.major == args.major:
1005 elif globals.command == 'test':
1006 if args.target is None:
1007 raise Error('you must specify -t or --target')
1011 target = target_factory(args.target, args.direct, args.debug, args.work)
1012 tree = globals.trees.get(args.project, args.checkout, target)
1013 with TreeDirectory(tree):
1014 target.test(tree, args.test)
1016 if target is not None:
1020 if target is not None:
1023 elif globals.command == 'shell':
1024 if args.target is None:
1025 raise Error('you must specify -t or --target')
1027 target = target_factory(args.target, args.direct, args.debug, args.work)
1028 target.command('bash')
1030 elif globals.command == 'revision':
1032 target = SourceTarget()
1033 tree = globals.trees.get(args.project, args.checkout, target)
1034 with TreeDirectory(tree):
1035 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1038 elif globals.command == 'checkout':
1040 if args.output is None:
1041 raise Error('you must specify -o or --output')
1043 target = SourceTarget()
1044 tree = globals.trees.get(args.project, args.checkout, target)
1045 with TreeDirectory(tree):
1046 shutil.copytree('.', args.output)
1050 raise Error('invalid command %s' % globals.command)
1055 print('cdist: %s' % str(e), file=sys.stderr)