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('windows_environment_prefix'),
96 Option('mingw_prefix'),
98 Option('osx_build_host'),
99 Option('osx_environment_prefix'),
100 Option('osx_sdk_prefix'),
102 Option('parallel', 4) ]
105 f = open('%s/.config/cdist' % os.path.expanduser('~'), 'r')
111 if len(l) > 0 and l[0] == '#':
114 s = l.strip().split()
116 for k in self.options:
122 for o in self.options:
125 raise Error('Required setting %s not found' % k)
129 for o in self.options:
139 if not globals.quiet:
140 print('\x1b[33m* %s\x1b[0m' % m)
143 """Escape a host:filename string for use with an scp command"""
145 assert(len(s) == 1 or len(s) == 2)
147 return '%s:"\'%s\'"' % (s[0], s[1])
149 return '\"%s\"' % s[0]
152 log('copy %s -> %s' % (scp_escape(b), scp_escape(b)))
153 command('scp -r %s %s' % (scp_escape(a), scp_escape(b)))
156 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
157 command('scp %s %s' % (scp_escape(a), scp_escape(b)))
161 Make directories either locally or on a remote host; remotely if
162 d includes a colon, otherwise locally.
164 if d.find(':') == -1:
172 command('ssh %s -- mkdir -p %s' % (s[0], s[1]))
180 shutil.rmtree(a, ignore_errors=True)
186 raise Error('command %s failed' % c)
188 def command_and_read(c):
190 p = subprocess.Popen(c.split(), stdout=subprocess.PIPE)
191 f = os.fdopen(os.dup(p.stdout.fileno()))
194 def read_wscript_variable(directory, variable):
195 f = open('%s/wscript' % directory, 'r')
202 if len(s) == 3 and s[0] == variable:
209 def set_version_in_wscript(version):
210 f = open('wscript', 'rw')
211 o = open('wscript.tmp', 'w')
218 if len(s) == 3 and s[0] == "VERSION":
219 print("Writing %s" % version)
220 print("VERSION = '%s'" % version, file=o)
222 print(l, file=o, end="")
226 os.rename('wscript.tmp', 'wscript')
228 def append_version_to_changelog(version):
230 f = open('ChangeLog', 'r')
232 log('Could not open ChangeLog')
238 f = open('ChangeLog', 'w')
239 now = datetime.datetime.now()
240 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))
243 def append_version_to_debian_changelog(version):
244 if not os.path.exists('debian'):
245 log('Could not find debian directory')
248 command('dch -b -v %s-1 "New upstream release."' % version)
250 def devel_to_git(git_commit, filename):
251 if git_commit is not None:
252 filename = filename.replace('devel', '-%s' % git_commit)
256 def __init__(self, tree):
259 self.cwd = os.getcwd()
260 os.chdir('%s/src/%s' % (self.tree.target.directory, self.tree.name))
261 def __exit__(self, type, value, traceback):
269 def __init__(self, s):
272 if s.startswith("'"):
277 if s.endswith('devel'):
281 if s.endswith('pre'):
285 self.major = int(p[0])
286 self.minor = int(p[1])
288 self.micro = int(p[2])
292 def bump_minor(self):
296 def bump_micro(self):
302 def to_release(self):
306 s = '%d.%d.%d' % (self.major, self.minor, self.micro)
316 class Target(object):
318 Class representing the target that we are building for. This is exposed to cscripts,
319 though not all of it is guaranteed 'API'. cscripts may expect:
321 platform: platform string (e.g. 'windows', 'linux', 'osx')
322 parallel: number of parallel jobs to run
323 directory: directory to work in
324 variables: dict of environment variables
325 debug: True to build a debug version, otherwise False
326 set(a, b): set the value of variable 'a' to 'b'
327 unset(a): unset the value of variable 'a'
328 command(c): run the command 'c' in the build environment
332 def __init__(self, platform, directory=None):
334 platform -- platform string (e.g. 'windows', 'linux', 'osx')
335 directory -- directory to work in; if None we will use a temporary directory
336 Temporary directories will be removed after use; specified directories will not.
338 self.platform = platform
339 self.parallel = int(config.get('parallel'))
341 # self.directory is the working directory
342 if directory is None:
343 self.directory = tempfile.mkdtemp('', 'tmp', TEMPORARY_DIRECTORY)
346 self.directory = directory
349 # Environment variables that we will use when we call cscripts
353 def package(self, project, checkout, output_dir):
354 tree = globals.trees.get(project, checkout, self)
355 tree.build_dependencies()
357 packages = tree.call('package', tree.version)
358 if isinstance(packages, (str, unicode)):
359 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
362 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
364 def test(self, tree, test):
365 """test is the test case to run, or None"""
366 tree.build_dependencies()
368 return tree.call('test', test)
371 self.variables[a] = b
374 del(self.variables[a])
377 return self.variables[a]
379 def append_with_space(self, k, v):
380 if (not k in self.variables) or len(self.variables[k]) == 0:
381 self.variables[k] = '"%s"' % v
383 e = self.variables[k]
384 if e[0] == '"' and e[-1] == '"':
385 self.variables[k] = '"%s %s"' % (e[1:-1], v)
387 self.variables[k] = '"%s %s"' % (e, v)
389 def variables_string(self, escaped_quotes=False):
391 for k, v in self.variables.items():
393 v = v.replace('"', '\\"')
394 e += '%s=%s ' % (k, v)
399 rmtree(self.directory)
402 class WindowsTarget(Target):
404 This target exposes the following additional API:
406 version: Windows version ('xp' or None)
407 bits: bitness of Windows (32 or 64)
408 environment_prefix: path to Windows environment
409 mingw_path: path to mingw binaries
411 def __init__(self, version, bits, directory=None):
412 super(WindowsTarget, self).__init__('windows', directory)
413 self.version = version
416 self.environment_prefix = '%s/%d' % (config.get('windows_environment_prefix'), self.bits)
417 if not os.path.exists(self.environment_prefix):
418 raise Error('environment prefix %s does not exist' % self.environment_prefix)
421 self.mingw_name = 'i686'
423 self.mingw_name = 'x86_64'
425 self.mingw_path = '%s/%d/bin' % (config.get('mingw_prefix'), self.bits)
426 self.mingw_prefixes = ['/%s/%d' % (config.get('mingw_prefix'), self.bits), '%s/%d/%s-w64-mingw32' % (config.get('mingw_prefix'), bits, self.mingw_name)]
428 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.environment_prefix)
429 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
430 self.set('PATH', '%s/bin:%s:%s' % (self.environment_prefix, self.mingw_path, os.environ['PATH']))
431 self.set('CC', '%s-w64-mingw32-gcc' % self.mingw_name)
432 self.set('CXX', '%s-w64-mingw32-g++' % self.mingw_name)
433 self.set('LD', '%s-w64-mingw32-ld' % self.mingw_name)
434 self.set('RANLIB', '%s-w64-mingw32-ranlib' % self.mingw_name)
435 self.set('WINRC', '%s-w64-mingw32-windres' % self.mingw_name)
436 cxx = '-I%s/include -I%s/include' % (self.environment_prefix, self.directory)
437 link = '-L%s/lib -L%s/lib' % (self.environment_prefix, self.directory)
438 for p in self.mingw_prefixes:
439 cxx += ' -I%s/include' % p
440 link += ' -L%s/lib' % p
441 self.set('CXXFLAGS', '"%s"' % cxx)
442 self.set('CPPFLAGS', '')
443 self.set('LINKFLAGS', '"%s"' % link)
444 self.set('LDFLAGS', '"%s"' % link)
446 # This is for backwards-compatibility
447 self.windows_prefix = self.environment_prefix
449 def command(self, c):
450 log('host -> %s' % c)
451 command('%s %s' % (self.variables_string(), c))
453 class LinuxTarget(Target):
455 Build for Linux in a docker container.
456 This target exposes the following additional API:
458 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
459 version: distribution version (e.g. '12.04', '8', '6.5')
460 bits: bitness of the distribution (32 or 64)
463 def __init__(self, distro, version, bits, directory=None):
464 super(LinuxTarget, self).__init__('linux', directory)
466 self.version = version
469 self.set('CXXFLAGS', '-I%s/include' % self.directory)
470 self.set('CPPFLAGS', '')
471 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
472 self.set('PKG_CONFIG_PATH',
473 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
474 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
476 class DockerTarget(LinuxTarget):
477 """Build in a docker container"""
478 def __init__(self, distro, version, bits, directory=None):
479 super(DockerTarget, self).__init__(distro, version, bits, directory)
481 def package(self, project, checkout, output_dir):
483 if checkout is not None:
484 ch = '-c %s' % checkout
485 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
486 container = command_and_read('docker run -itd %s /bin/bash' % target).read().strip()
487 command('docker exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s package -w /cdist"' % (container, project, target, ch))
488 # I can't get wildcards to work with docker cp
489 debs = command_and_read('docker exec -t %s ls -1 /%s' % (container, target)).read().split('\n')
493 command('docker cp %s:/%s/%s %s' % (container, target, d, output_dir))
494 command('docker kill %s' % container)
496 class DirectTarget(LinuxTarget):
497 """Build directly in the current environment"""
498 def __init__(self, distro, version, bits, directory=None):
499 super(DirectTarget, self).__init__(distro, version, bits, directory)
501 def command(self, c):
502 command('%s %s' % (self.variables_string(), c))
505 class OSXTarget(Target):
506 def __init__(self, directory=None):
507 super(OSXTarget, self).__init__('osx', directory)
508 self.sdk = config.get('osx_sdk')
509 self.sdk_prefix = config.get('osx_sdk_prefix')
510 self.environment_prefix = config.get('osx_environment_prefix')
512 def command(self, c):
513 command('%s %s' % (self.variables_string(False), c))
516 class OSXSingleTarget(OSXTarget):
517 def __init__(self, bits, directory=None):
518 super(OSXSingleTarget, self).__init__(directory)
526 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
527 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
529 # Environment variables
530 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
531 self.set('CPPFLAGS', '')
532 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
533 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
534 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
535 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
536 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
537 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
539 def package(self, project, checkout, output_dir):
540 raise Error('cannot package non-universal OS X versions')
543 class OSXUniversalTarget(OSXTarget):
544 def __init__(self, directory=None):
545 super(OSXUniversalTarget, self).__init__(directory)
547 def package(self, project, checkout, output_dir):
550 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
551 tree = globals.trees.get(project, checkout, target)
552 tree.build_dependencies()
555 tree = globals.trees.get(project, checkout, self)
556 with TreeDirectory(tree):
557 for p in tree.call('package', tree.version):
558 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
560 class SourceTarget(Target):
561 """Build a source .tar.bz2"""
563 super(SourceTarget, self).__init__('source')
565 def command(self, c):
566 log('host -> %s' % c)
567 command('%s %s' % (self.variables_string(), c))
570 rmtree(self.directory)
572 def package(self, project, checkout, output_dir):
573 tree = globals.trees.get(project, checkout, self)
574 with TreeDirectory(tree):
575 name = read_wscript_variable(os.getcwd(), 'APPNAME')
576 command('./waf dist')
577 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
578 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
580 # @param s Target string:
582 # or ubuntu-version-{32,64}
583 # or debian-version-{32,64}
584 # or centos-version-{32,64}
585 # or fedora-version-{32,64}
588 # @param debug True to build with debugging symbols (where possible)
589 def target_factory(s, direct, debug, work):
591 if s.startswith('windows-'):
594 target = WindowsTarget(None, int(x[1]), work)
596 target = WindowsTarget(x[1], int(x[2]), work)
598 raise Error("Bad Windows target name `%s'")
599 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora'):
602 raise Error("Bad Linux target name `%s'; must be something like ubuntu-12.04-32 (i.e. distro-version-bits)" % s)
604 target = DirectTarget(p[0], p[1], int(p[2]), work)
606 target = DockerTarget(p[0], p[1], int(p[2]), work)
607 elif s.startswith('arch-'):
610 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
611 target = DockerTarget(p[0], None, p[1], work)
612 elif s == 'raspbian':
613 target = DockerTarget(s, None, None, work)
614 elif s.startswith('osx-'):
615 target = OSXSingleTarget(int(s.split('-')[1]), work)
617 if globals.command == 'build':
618 target = OSXSingleTarget(64, work)
620 target = OSXUniversalTarget(work)
622 target = SourceTarget()
624 target = DockerTarget()
627 raise Error("Bad target `%s'" % s)
638 """Description of a tree, which is a checkout of a project,
639 possibly built. This class is never exposed to cscripts.
641 name -- name of git repository (without the .git)
642 specifier -- git tag or revision to use
643 target --- target object that we are using
644 version --- version from the wscript (if one is present)
645 git_commit -- git revision that is actually being used
646 built --- true if the tree has been built yet in this run
649 def __init__(self, name, specifier, target):
651 self.specifier = specifier
654 self.git_commit = None
663 redirect = '>/dev/null'
664 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
665 os.chdir('%s/src/%s' % (target.directory, self.name))
667 spec = self.specifier
671 command('git checkout %s %s %s' % (flags, spec, redirect))
672 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
673 command('git submodule init --quiet')
674 command('git submodule update --quiet')
676 proj = '%s/src/%s' % (target.directory, self.name)
679 exec(open('%s/cscript' % proj).read(), self.cscript)
681 if os.path.exists('%s/wscript' % proj):
682 v = read_wscript_variable(proj, "VERSION");
684 self.version = Version(v)
688 def call(self, function, *args):
689 with TreeDirectory(self):
690 return self.cscript[function](self.target, *args)
692 def build_dependencies(self, options=None):
694 if not 'dependencies' in self.cscript:
697 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
698 deps = self.call('dependencies', options)
700 log("Deprecated cscipt dependencies() method with no parameter")
701 deps = self.call('dependencies')
704 dep = globals.trees.get(d[0], d[1], self.target)
707 # Make the options to pass in from the option_defaults of the thing
708 # we are building and any options specified by the parent.
709 if 'option_defaults' in dep.cscript:
710 for k, v in dep.cscript['option_defaults']().items():
714 for k, v in d[2].items():
717 msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
719 msg += ' with options %s' % options
722 dep.build_dependencies(options)
725 def build(self, options=None):
729 variables = copy.copy(self.target.variables)
731 if not globals.dry_run:
732 if len(inspect.getargspec(self.cscript['build']).args) == 2:
733 self.call('build', options)
737 self.target.variables = variables
741 # Command-line parser
747 "build": "build project",
748 "package": "package and build project",
749 "release": "release a project using its next version number (changing wscript and tagging)",
750 "pot": "build the project's .pot files",
751 "changelog": "generate a simple HTML changelog",
752 "manual": "build the project's manual",
753 "doxygen": "build the project's Doxygen documentation",
754 "latest": "print out the latest version",
755 "test": "run the project's unit tests",
756 "shell": "build the project then start a shell",
757 "checkout": "check out the project",
758 "revision": "print the head git revision number"
761 one_of = "Command is one of:\n"
763 for k, v in commands.items():
764 one_of += "\t%s\t%s\n" % (k, v)
767 parser = argparse.ArgumentParser()
768 parser.add_argument('command', help=summary)
769 parser.add_argument('-p', '--project', help='project name')
770 parser.add_argument('--minor', help='minor version number bump', action='store_true')
771 parser.add_argument('--micro', help='micro version number bump', action='store_true')
772 parser.add_argument('--major', help='major version to return with latest', type=int)
773 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
774 parser.add_argument('-o', '--output', help='output directory', default='.')
775 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
776 parser.add_argument('-t', '--target', help='target')
777 parser.add_argument('-d', '--direct', help='build in the current environment', action='store_true')
778 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
779 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
780 parser.add_argument('-w', '--work', help='override default work directory')
781 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
782 parser.add_argument('--test', help='name of test to run (with `test''), defaults to all')
783 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
784 args = parser.parse_args()
786 # Override configured stuff
787 if args.git_prefix is not None:
788 config.set('git_prefix', args.git_prefix)
790 if args.output.find(':') == -1:
791 # This isn't of the form host:path so make it absolute
792 args.output = os.path.abspath(args.output) + '/'
794 if args.output[-1] != ':' and args.output[-1] != '/':
797 # Now, args.output is 'host:', 'host:path/' or 'path/'
799 if args.work is not None:
800 args.work = os.path.abspath(args.work)
802 if args.project is None and args.command != 'shell':
803 raise Error('you must specify -p or --project')
805 globals.quiet = args.quiet
806 globals.command = args.command
807 globals.dry_run = args.dry_run
809 if not globals.command in commands:
810 e = 'command must be one of:\n' + one_of
811 raise Error('command must be one of:\n%s' % one_of)
813 if globals.command == 'build':
814 if args.target is None:
815 raise Error('you must specify -t or --target')
817 target = target_factory(args.target, args.direct, args.debug, args.work)
818 tree = globals.trees.get(args.project, args.checkout, target)
819 tree.build_dependencies()
824 elif globals.command == 'package':
825 if args.target is None:
826 raise Error('you must specify -t or --target')
828 target = target_factory(args.target, args.direct, args.debug, args.work)
830 if target.platform == 'linux':
831 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
833 output_dir = args.output
836 target.package(args.project, args.checkout, output_dir)
841 elif globals.command == 'release':
842 if args.minor is False and args.micro is False:
843 raise Error('you must specify --minor or --micro')
845 target = SourceTarget()
846 tree = globals.trees.get(args.project, args.checkout, target)
848 version = tree.version
855 set_version_in_wscript(version)
856 append_version_to_changelog(version)
857 append_version_to_debian_changelog(version)
859 command('git commit -a -m "Bump version"')
860 command('git tag -m "v%s" v%s' % (version, version))
863 set_version_in_wscript(version)
864 command('git commit -a -m "Bump version"')
866 command('git push --tags')
870 elif globals.command == 'pot':
871 target = SourceTarget()
872 tree = globals.trees.get(args.project, args.checkout, target)
874 pots = tree.call('make_pot')
876 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
880 elif globals.command == 'changelog':
881 target = SourceTarget()
882 tree = globals.trees.get(args.project, args.checkout, target)
884 with TreeDirectory(tree):
885 text = open('ChangeLog', 'r')
887 html = tempfile.NamedTemporaryFile()
898 if len(l) > 0 and l[0] == "\t":
900 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
903 if last is not None and len(changes) > 0:
904 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
905 print("<ul>", file=html)
907 print("<li>%s" % c, file=html)
908 print("</ul>", file=html)
918 changes.append(c[2:])
920 changes[-1] += " " + c
922 copyfile(html.file, '%schangelog.html' % args.output)
926 elif globals.command == 'manual':
927 target = SourceTarget()
928 tree = globals.trees.get(args.project, args.checkout, target)
930 outs = tree.call('make_manual')
932 if os.path.isfile(o):
933 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
935 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
939 elif globals.command == 'doxygen':
940 target = SourceTarget()
941 tree = globals.trees.get(args.project, args.checkout, target)
943 dirs = tree.call('make_doxygen')
944 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
948 copytree(d, args.output)
952 elif globals.command == 'latest':
953 target = SourceTarget()
954 tree = globals.trees.get(args.project, args.checkout, target)
956 with TreeDirectory(tree):
957 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
959 while latest is None:
961 m = re.compile(".*\((.*)\).*").match(t)
963 tags = m.group(1).split(', ')
968 if len(t) > 0 and t[0] == 'v':
970 if args.major is None or v.major == args.major:
976 elif globals.command == 'test':
977 if args.target is None:
978 raise Error('you must specify -t or --target')
982 target = target_factory(args.target, args.direct, args.debug, args.work)
983 tree = globals.trees.get(args.project, args.checkout, target)
984 with TreeDirectory(tree):
985 target.test(tree, args.test)
987 if target is not None:
991 if target is not None:
994 elif globals.command == 'shell':
995 if args.target is None:
996 raise Error('you must specify -t or --target')
998 target = target_factory(args.target, args.direct, args.debug, args.work)
999 target.command('bash')
1001 elif globals.command == 'revision':
1003 target = SourceTarget()
1004 tree = globals.trees.get(args.project, args.checkout, target)
1005 with TreeDirectory(tree):
1006 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1009 elif globals.command == 'checkout':
1011 if args.output is None:
1012 raise Error('you must specify -o or --output')
1014 target = SourceTarget()
1015 tree = globals.trees.get(args.project, args.checkout, target)
1016 with TreeDirectory(tree):
1017 shutil.copytree('.', args.output)
1021 raise Error('invalid command %s' % globals.command)
1026 print('cdist: %s' % str(e), file=sys.stderr)