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
33 TEMPORARY_DIRECTORY = '/var/tmp'
35 class Error(Exception):
36 def __init__(self, value):
45 Store for Tree objects which re-uses already-created objects
46 and checks for requests for different versions of the same thing.
52 def get(self, name, specifier, target, required_by=None):
54 if t.name == name and t.specifier == specifier and t.target == target:
56 elif t.name == name and t.specifier != specifier:
58 if required_by is not None:
59 a += ' by %s' % required_by
61 if t.required_by is not None:
62 b += ' by %s' % t.required_by
63 raise Error('conflicting versions of %s required (%s versus %s)' % (name, a, b))
65 nt = Tree(name, specifier, target, required_by)
83 def __init__(self, key, default=None):
87 def offer(self, key, value):
91 class BoolOption(object):
92 def __init__(self, key):
96 def offer(self, key, value):
98 self.value = (value == 'yes' or value == '1' or value == 'true')
102 self.options = [ Option('mxe_prefix'),
103 Option('git_prefix'),
104 Option('osx_environment_prefix'),
105 Option('osx_sdk_prefix'),
107 BoolOption('docker_sudo'),
108 Option('parallel', 4) ]
111 f = open('%s/.config/cdist' % os.path.expanduser('~'), 'r')
117 if len(l) > 0 and l[0] == '#':
120 s = l.strip().split()
122 for k in self.options:
128 for o in self.options:
131 raise Error('Required setting %s not found' % k)
135 for o in self.options:
139 if self.get('docker_sudo'):
151 if not globals.quiet:
152 print('\x1b[33m* %s\x1b[0m' % m)
155 """Escape a host:filename string for use with an scp command"""
157 assert(len(s) == 1 or len(s) == 2)
159 return '%s:"\'%s\'"' % (s[0], s[1])
161 return '\"%s\"' % s[0]
164 log('copy %s -> %s' % (scp_escape(b), scp_escape(b)))
165 command('scp -r %s %s' % (scp_escape(a), scp_escape(b)))
168 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
169 command('scp %s %s' % (scp_escape(a), scp_escape(b)))
173 Make directories either locally or on a remote host; remotely if
174 d includes a colon, otherwise locally.
176 if d.find(':') == -1:
184 command('ssh %s -- mkdir -p %s' % (s[0], s[1]))
192 shutil.rmtree(a, ignore_errors=True)
198 raise Error('command %s failed' % c)
200 def command_and_read(c):
202 p = subprocess.Popen(c.split(), stdout=subprocess.PIPE)
203 f = os.fdopen(os.dup(p.stdout.fileno()))
206 def read_wscript_variable(directory, variable):
207 f = open('%s/wscript' % directory, 'r')
214 if len(s) == 3 and s[0] == variable:
221 def set_version_in_wscript(version):
222 f = open('wscript', 'rw')
223 o = open('wscript.tmp', 'w')
230 if len(s) == 3 and s[0] == "VERSION":
231 print("Writing %s" % version)
232 print("VERSION = '%s'" % version, file=o)
234 print(l, file=o, end="")
238 os.rename('wscript.tmp', 'wscript')
240 def append_version_to_changelog(version):
242 f = open('ChangeLog', 'r')
244 log('Could not open ChangeLog')
250 f = open('ChangeLog', 'w')
251 now = datetime.datetime.now()
252 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))
255 def append_version_to_debian_changelog(version):
256 if not os.path.exists('debian'):
257 log('Could not find debian directory')
260 command('dch -b -v %s-1 "New upstream release."' % version)
262 def devel_to_git(git_commit, filename):
263 if git_commit is not None:
264 filename = filename.replace('devel', '-%s' % git_commit)
268 def __init__(self, tree):
271 self.cwd = os.getcwd()
272 os.chdir('%s/src/%s' % (self.tree.target.directory, self.tree.name))
273 def __exit__(self, type, value, traceback):
281 def __init__(self, s):
284 if s.startswith("'"):
289 if s.endswith('devel'):
293 if s.endswith('pre'):
297 self.major = int(p[0])
298 self.minor = int(p[1])
300 self.micro = int(p[2])
304 def bump_minor(self):
308 def bump_micro(self):
314 def to_release(self):
318 s = '%d.%d.%d' % (self.major, self.minor, self.micro)
328 class Target(object):
330 Class representing the target that we are building for. This is exposed to cscripts,
331 though not all of it is guaranteed 'API'. cscripts may expect:
333 platform: platform string (e.g. 'windows', 'linux', 'osx')
334 parallel: number of parallel jobs to run
335 directory: directory to work in
336 variables: dict of environment variables
337 debug: True to build a debug version, otherwise False
338 set(a, b): set the value of variable 'a' to 'b'
339 unset(a): unset the value of variable 'a'
340 command(c): run the command 'c' in the build environment
344 def __init__(self, platform, directory=None):
346 platform -- platform string (e.g. 'windows', 'linux', 'osx')
347 directory -- directory to work in; if None we will use a temporary directory
348 Temporary directories will be removed after use; specified directories will not.
350 self.platform = platform
351 self.parallel = int(config.get('parallel'))
353 if directory is None:
354 self.directory = tempfile.mkdtemp('', 'tmp', TEMPORARY_DIRECTORY)
357 self.directory = directory
360 # Environment variables that we will use when we call cscripts
364 def package(self, project, checkout, output_dir):
365 tree = globals.trees.get(project, checkout, self)
366 tree.build_dependencies()
368 packages = tree.call('package', tree.version)
369 if isinstance(packages, (str, unicode)):
370 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
373 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
375 def build(self, project, checkout):
376 tree = globals.trees.get(project, checkout, self)
377 tree.build_dependencies()
380 def test(self, tree, test):
381 """test is the test case to run, or None"""
382 tree.build_dependencies()
384 return tree.call('test', test)
387 self.variables[a] = b
390 del(self.variables[a])
393 return self.variables[a]
395 def append(self, k, v, s):
396 if (not k in self.variables) or len(self.variables[k]) == 0:
397 self.variables[k] = '"%s"' % v
399 e = self.variables[k]
400 if e[0] == '"' and e[-1] == '"':
401 self.variables[k] = '"%s%s%s"' % (e[1:-1], s, v)
403 self.variables[k] = '"%s%s%s"' % (e, s, v)
405 def append_with_space(self, k, v):
406 return self.append(k, v, ' ')
408 def append_with_colon(self, k, v):
409 return self.append(k, v, ':')
411 def variables_string(self, escaped_quotes=False):
413 for k, v in self.variables.items():
415 v = v.replace('"', '\\"')
416 e += '%s=%s ' % (k, v)
421 rmtree(self.directory)
424 class WindowsTarget(Target):
426 This target exposes the following additional API:
428 version: Windows version ('xp' or None)
429 bits: bitness of Windows (32 or 64)
430 name: name of our target e.g. x86_64-w64-mingw32.shared
431 library_prefix: path to Windows libraries
432 tool_path: path to toolchain binaries
434 def __init__(self, version, bits, directory=None):
435 super(WindowsTarget, self).__init__('windows', directory)
436 self.version = version
439 self.tool_path = '%s/usr/bin' % config.get('mxe_prefix')
441 self.name = 'i686-w64-mingw32.shared'
443 self.name = 'x86_64-w64-mingw32.shared'
444 self.library_prefix = '%s/usr/%s' % (config.get('mxe_prefix'), self.name)
446 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.library_prefix)
447 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
448 self.set('PATH', '%s/bin:%s:%s' % (self.library_prefix, self.tool_path, os.environ['PATH']))
449 self.set('CC', '%s-gcc' % self.name)
450 self.set('CXX', '%s-g++' % self.name)
451 self.set('LD', '%s-ld' % self.name)
452 self.set('RANLIB', '%s-ranlib' % self.name)
453 self.set('WINRC', '%s-windres' % self.name)
454 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
455 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
456 self.set('CXXFLAGS', '"%s"' % cxx)
457 self.set('CPPFLAGS', '')
458 self.set('LINKFLAGS', '"%s"' % link)
459 self.set('LDFLAGS', '"%s"' % link)
462 def windows_prefix(self):
463 log('Deprecated property windows_prefix')
464 return self.library_prefix
467 def mingw_prefixes(self):
468 log('Deprecated property mingw_prefixes')
469 return [self.library_prefix]
472 def mingw_path(self):
473 log('Deprecated property mingw_path')
474 return self.tool_path
477 def mingw_name(self):
478 log('Deprecated property mingw_name')
481 def command(self, c):
482 log('host -> %s' % c)
483 command('%s %s' % (self.variables_string(), c))
485 class LinuxTarget(Target):
487 Build for Linux in a docker container.
488 This target exposes the following additional API:
490 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
491 version: distribution version (e.g. '12.04', '8', '6.5')
492 bits: bitness of the distribution (32 or 64)
495 def __init__(self, distro, version, bits, directory=None):
496 super(LinuxTarget, self).__init__('linux', directory)
498 self.version = version
501 self.set('CXXFLAGS', '-I%s/include' % self.directory)
502 self.set('CPPFLAGS', '')
503 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
504 self.set('PKG_CONFIG_PATH',
505 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
506 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
508 image = '%s-%s-%s' % (self.distro, self.version, self.bits)
509 self.container = command_and_read('%s run -u %s -v %s:%s -itd %s /bin/bash' % (config.docker(), getpass.getuser(), self.directory, self.directory, image)).read().strip()
511 def command(self, cmd):
512 dir = os.path.join(self.directory, os.path.relpath(os.getcwd(), self.directory))
513 command('%s exec -u %s -t %s /bin/bash -c \'export %s; cd %s; %s\'' % (config.docker(), getpass.getuser(), self.container, self.variables_string(), dir, cmd))
516 super(LinuxTarget, self).cleanup()
517 command('%s kill %s' % (config.docker(), self.container))
519 def test(self, tree, test):
520 self.append_with_colon('PATH', '%s/bin' % self.directory)
521 self.append_with_colon('LD_LIBRARY_PATH', '%s/lib' % self.directory)
522 super(LinuxTarget, self).test(tree, test)
524 class OSXTarget(Target):
525 def __init__(self, directory=None):
526 super(OSXTarget, self).__init__('osx', directory)
527 self.sdk = config.get('osx_sdk')
528 self.sdk_prefix = config.get('osx_sdk_prefix')
529 self.environment_prefix = config.get('osx_environment_prefix')
531 def command(self, c):
532 command('%s %s' % (self.variables_string(False), c))
535 class OSXSingleTarget(OSXTarget):
536 def __init__(self, bits, directory=None):
537 super(OSXSingleTarget, self).__init__(directory)
545 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
546 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
548 # Environment variables
549 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
550 self.set('CPPFLAGS', '')
551 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
552 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
553 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
554 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
555 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
556 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
558 def package(self, project, checkout, output_dir):
559 raise Error('cannot package non-universal OS X versions')
562 class OSXUniversalTarget(OSXTarget):
563 def __init__(self, directory=None):
564 super(OSXUniversalTarget, self).__init__(directory)
566 def package(self, project, checkout, output_dir):
569 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
570 tree = globals.trees.get(project, checkout, target)
571 tree.build_dependencies()
574 tree = globals.trees.get(project, checkout, self)
575 with TreeDirectory(tree):
576 for p in tree.call('package', tree.version):
577 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
579 class SourceTarget(Target):
580 """Build a source .tar.bz2"""
582 super(SourceTarget, self).__init__('source')
584 def command(self, c):
585 log('host -> %s' % c)
586 command('%s %s' % (self.variables_string(), c))
589 rmtree(self.directory)
591 def package(self, project, checkout, output_dir):
592 tree = globals.trees.get(project, checkout, self)
593 with TreeDirectory(tree):
594 name = read_wscript_variable(os.getcwd(), 'APPNAME')
595 command('./waf dist')
596 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
597 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
599 # @param s Target string:
601 # or ubuntu-version-{32,64}
602 # or debian-version-{32,64}
603 # or centos-version-{32,64}
604 # or fedora-version-{32,64}
605 # or mageia-version-{32,64}
608 # @param debug True to build with debugging symbols (where possible)
609 def target_factory(s, debug, work):
611 if s.startswith('windows-'):
614 target = WindowsTarget(None, int(x[1]), work)
616 target = WindowsTarget(x[1], int(x[2]), work)
618 raise Error("Bad Windows target name `%s'")
619 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora-') or s.startswith('mageia-'):
622 raise Error("Bad Linux target name `%s'; must be something like ubuntu-16.04-32 (i.e. distro-version-bits)" % s)
623 target = LinuxTarget(p[0], p[1], int(p[2]), work)
624 elif s.startswith('arch-'):
627 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
628 target = LinuxTarget(p[0], None, p[1], work)
629 elif s == 'raspbian':
630 target = LinuxTarget(s, None, None, work)
631 elif s.startswith('osx-'):
632 target = OSXSingleTarget(int(s.split('-')[1]), work)
634 if globals.command == 'build':
635 target = OSXSingleTarget(64, work)
637 target = OSXUniversalTarget(work)
639 target = SourceTarget()
642 raise Error("Bad target `%s'" % s)
653 """Description of a tree, which is a checkout of a project,
654 possibly built. This class is never exposed to cscripts.
656 name -- name of git repository (without the .git)
657 specifier -- git tag or revision to use
658 target -- target object that we are using
659 version -- version from the wscript (if one is present)
660 git_commit -- git revision that is actually being used
661 built -- true if the tree has been built yet in this run
662 required_by -- name of the tree that requires this one
665 def __init__(self, name, specifier, target, required_by):
667 self.specifier = specifier
670 self.git_commit = None
672 self.required_by = required_by
680 redirect = '>/dev/null'
681 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
682 os.chdir('%s/src/%s' % (target.directory, self.name))
684 spec = self.specifier
688 command('git checkout %s %s %s' % (flags, spec, redirect))
689 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
690 command('git submodule init --quiet')
691 command('git submodule update --quiet')
693 proj = '%s/src/%s' % (target.directory, self.name)
696 exec(open('%s/cscript' % proj).read(), self.cscript)
698 if os.path.exists('%s/wscript' % proj):
699 v = read_wscript_variable(proj, "VERSION");
701 self.version = Version(v)
705 def call(self, function, *args):
706 with TreeDirectory(self):
707 return self.cscript[function](self.target, *args)
709 def build_dependencies(self, options=None):
711 if not 'dependencies' in self.cscript:
714 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
715 deps = self.call('dependencies', options)
717 log("Deprecated cscipt dependencies() method with no options parameter")
718 deps = self.call('dependencies')
721 dep = globals.trees.get(d[0], d[1], self.target, self.name)
724 # Make the options to pass in from the option_defaults of the thing
725 # we are building and any options specified by the parent.
726 if 'option_defaults' in dep.cscript:
727 for k, v in dep.cscript['option_defaults']().items():
731 for k, v in d[2].items():
734 msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
736 msg += ' with options %s' % options
739 dep.build_dependencies(options)
742 def build(self, options=None):
746 variables = copy.copy(self.target.variables)
748 if not globals.dry_run:
749 if len(inspect.getargspec(self.cscript['build']).args) == 2:
750 self.call('build', options)
754 self.target.variables = variables
758 # Command-line parser
764 "build": "build project",
765 "package": "package and build project",
766 "release": "release a project using its next version number (changing wscript and tagging)",
767 "pot": "build the project's .pot files",
768 "changelog": "generate a simple HTML changelog",
769 "manual": "build the project's manual",
770 "doxygen": "build the project's Doxygen documentation",
771 "latest": "print out the latest version",
772 "test": "run the project's unit tests",
773 "shell": "build the project then start a shell",
774 "checkout": "check out the project",
775 "revision": "print the head git revision number"
778 one_of = "Command is one of:\n"
780 for k, v in commands.items():
781 one_of += "\t%s\t%s\n" % (k, v)
784 parser = argparse.ArgumentParser()
785 parser.add_argument('command', help=summary)
786 parser.add_argument('-p', '--project', help='project name')
787 parser.add_argument('--minor', help='minor version number bump', action='store_true')
788 parser.add_argument('--micro', help='micro version number bump', action='store_true')
789 parser.add_argument('--major', help='major version to return with latest', type=int)
790 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
791 parser.add_argument('-o', '--output', help='output directory', default='.')
792 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
793 parser.add_argument('-t', '--target', help='target')
794 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
795 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
796 parser.add_argument('-w', '--work', help='override default work directory')
797 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
798 parser.add_argument('--test', help='name of test to run (with `test''), defaults to all')
799 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
800 args = parser.parse_args()
802 # Override configured stuff
803 if args.git_prefix is not None:
804 config.set('git_prefix', args.git_prefix)
806 if args.output.find(':') == -1:
807 # This isn't of the form host:path so make it absolute
808 args.output = os.path.abspath(args.output) + '/'
810 if args.output[-1] != ':' and args.output[-1] != '/':
813 # Now, args.output is 'host:', 'host:path/' or 'path/'
815 if args.work is not None:
816 args.work = os.path.abspath(args.work)
818 if args.project is None and args.command != 'shell':
819 raise Error('you must specify -p or --project')
821 globals.quiet = args.quiet
822 globals.command = args.command
823 globals.dry_run = args.dry_run
825 if not globals.command in commands:
826 e = 'command must be one of:\n' + one_of
827 raise Error('command must be one of:\n%s' % one_of)
829 if globals.command == 'build':
830 if args.target is None:
831 raise Error('you must specify -t or --target')
833 target = target_factory(args.target, args.debug, args.work)
834 target.build(args.project, args.checkout)
838 elif globals.command == 'package':
839 if args.target is None:
840 raise Error('you must specify -t or --target')
842 target = target_factory(args.target, args.debug, args.work)
844 if target.platform == 'linux':
845 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
847 output_dir = args.output
850 target.package(args.project, args.checkout, output_dir)
855 elif globals.command == 'release':
856 if args.minor is False and args.micro is False:
857 raise Error('you must specify --minor or --micro')
859 target = SourceTarget()
860 tree = globals.trees.get(args.project, args.checkout, target)
862 version = tree.version
869 with TreeDirectory(tree):
870 set_version_in_wscript(version)
871 append_version_to_changelog(version)
872 append_version_to_debian_changelog(version)
874 command('git commit -a -m "Bump version"')
875 command('git tag -m "v%s" v%s' % (version, version))
878 set_version_in_wscript(version)
879 command('git commit -a -m "Bump version"')
881 command('git push --tags')
885 elif globals.command == 'pot':
886 target = SourceTarget()
887 tree = globals.trees.get(args.project, args.checkout, target)
889 pots = tree.call('make_pot')
891 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
895 elif globals.command == 'changelog':
896 target = SourceTarget()
897 tree = globals.trees.get(args.project, args.checkout, target)
899 with TreeDirectory(tree):
900 text = open('ChangeLog', 'r')
902 html = tempfile.NamedTemporaryFile()
913 if len(l) > 0 and l[0] == "\t":
915 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
918 if last is not None and len(changes) > 0:
919 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
920 print("<ul>", file=html)
922 print("<li>%s" % c, file=html)
923 print("</ul>", file=html)
933 changes.append(c[2:])
935 changes[-1] += " " + c
937 copyfile(html.file, '%schangelog.html' % args.output)
941 elif globals.command == 'manual':
942 target = SourceTarget()
943 tree = globals.trees.get(args.project, args.checkout, target)
945 outs = tree.call('make_manual')
947 if os.path.isfile(o):
948 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
950 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
954 elif globals.command == 'doxygen':
955 target = SourceTarget()
956 tree = globals.trees.get(args.project, args.checkout, target)
958 dirs = tree.call('make_doxygen')
959 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
963 copytree(d, args.output)
967 elif globals.command == 'latest':
968 target = SourceTarget()
969 tree = globals.trees.get(args.project, args.checkout, target)
971 with TreeDirectory(tree):
972 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
974 while latest is None:
976 m = re.compile(".*\((.*)\).*").match(t)
978 tags = m.group(1).split(', ')
983 if len(t) > 0 and t[0] == 'v':
985 if args.major is None or v.major == args.major:
991 elif globals.command == 'test':
992 if args.target is None:
993 raise Error('you must specify -t or --target')
997 target = target_factory(args.target, args.debug, args.work)
998 tree = globals.trees.get(args.project, args.checkout, target)
999 with TreeDirectory(tree):
1000 target.test(tree, args.test)
1002 if target is not None and not args.keep:
1006 if target is not None and not args.keep:
1009 elif globals.command == 'shell':
1010 if args.target is None:
1011 raise Error('you must specify -t or --target')
1013 target = target_factory(args.target, args.debug, args.work)
1014 target.command('bash')
1016 elif globals.command == 'revision':
1018 target = SourceTarget()
1019 tree = globals.trees.get(args.project, args.checkout, target)
1020 with TreeDirectory(tree):
1021 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1024 elif globals.command == 'checkout':
1026 if args.output is None:
1027 raise Error('you must specify -o or --output')
1029 target = SourceTarget()
1030 tree = globals.trees.get(args.project, args.checkout, target)
1031 with TreeDirectory(tree):
1032 shutil.copytree('.', args.output)
1036 raise Error('invalid command %s' % globals.command)
1041 print('cdist: %s' % str(e), file=sys.stderr)