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_build_host'),
98 Option('osx_environment_prefix'),
99 Option('osx_sdk_prefix'),
101 BoolOption('docker_sudo'),
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:
133 if self.get('docker_sudo'):
145 if not globals.quiet:
146 print('\x1b[33m* %s\x1b[0m' % m)
149 """Escape a host:filename string for use with an scp command"""
151 assert(len(s) == 1 or len(s) == 2)
153 return '%s:"\'%s\'"' % (s[0], s[1])
155 return '\"%s\"' % s[0]
158 log('copy %s -> %s' % (scp_escape(b), scp_escape(b)))
159 command('scp -r %s %s' % (scp_escape(a), scp_escape(b)))
162 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
163 command('scp %s %s' % (scp_escape(a), scp_escape(b)))
167 Make directories either locally or on a remote host; remotely if
168 d includes a colon, otherwise locally.
170 if d.find(':') == -1:
178 command('ssh %s -- mkdir -p %s' % (s[0], s[1]))
186 shutil.rmtree(a, ignore_errors=True)
192 raise Error('command %s failed' % c)
194 def command_and_read(c):
196 p = subprocess.Popen(c.split(), stdout=subprocess.PIPE)
197 f = os.fdopen(os.dup(p.stdout.fileno()))
200 def read_wscript_variable(directory, variable):
201 f = open('%s/wscript' % directory, 'r')
208 if len(s) == 3 and s[0] == variable:
215 def set_version_in_wscript(version):
216 f = open('wscript', 'rw')
217 o = open('wscript.tmp', 'w')
224 if len(s) == 3 and s[0] == "VERSION":
225 print("Writing %s" % version)
226 print("VERSION = '%s'" % version, file=o)
228 print(l, file=o, end="")
232 os.rename('wscript.tmp', 'wscript')
234 def append_version_to_changelog(version):
236 f = open('ChangeLog', 'r')
238 log('Could not open ChangeLog')
244 f = open('ChangeLog', 'w')
245 now = datetime.datetime.now()
246 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))
249 def append_version_to_debian_changelog(version):
250 if not os.path.exists('debian'):
251 log('Could not find debian directory')
254 command('dch -b -v %s-1 "New upstream release."' % version)
256 def devel_to_git(git_commit, filename):
257 if git_commit is not None:
258 filename = filename.replace('devel', '-%s' % git_commit)
262 def __init__(self, tree):
265 self.cwd = os.getcwd()
266 os.chdir('%s/src/%s' % (self.tree.target.directory, self.tree.name))
267 def __exit__(self, type, value, traceback):
275 def __init__(self, s):
278 if s.startswith("'"):
283 if s.endswith('devel'):
287 if s.endswith('pre'):
291 self.major = int(p[0])
292 self.minor = int(p[1])
294 self.micro = int(p[2])
298 def bump_minor(self):
302 def bump_micro(self):
308 def to_release(self):
312 s = '%d.%d.%d' % (self.major, self.minor, self.micro)
322 class Target(object):
324 Class representing the target that we are building for. This is exposed to cscripts,
325 though not all of it is guaranteed 'API'. cscripts may expect:
327 platform: platform string (e.g. 'windows', 'linux', 'osx')
328 parallel: number of parallel jobs to run
329 directory: directory to work in
330 variables: dict of environment variables
331 debug: True to build a debug version, otherwise False
332 set(a, b): set the value of variable 'a' to 'b'
333 unset(a): unset the value of variable 'a'
334 command(c): run the command 'c' in the build environment
338 def __init__(self, platform, directory=None):
340 platform -- platform string (e.g. 'windows', 'linux', 'osx')
341 directory -- directory to work in; if None we will use a temporary directory
342 Temporary directories will be removed after use; specified directories will not.
344 self.platform = platform
345 self.parallel = int(config.get('parallel'))
347 # self.directory is the working directory
348 if directory is None:
349 self.directory = tempfile.mkdtemp('', 'tmp', TEMPORARY_DIRECTORY)
352 self.directory = directory
355 # Environment variables that we will use when we call cscripts
359 def package(self, project, checkout, output_dir):
360 tree = globals.trees.get(project, checkout, self)
361 tree.build_dependencies()
363 packages = tree.call('package', tree.version)
364 if isinstance(packages, (str, unicode)):
365 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
368 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
370 def build(self, project, checkout):
371 tree = globals.trees.get(project, checkout, self)
372 tree.build_dependencies()
375 def test(self, tree, test):
376 """test is the test case to run, or None"""
377 tree.build_dependencies()
379 return tree.call('test', test)
382 self.variables[a] = b
385 del(self.variables[a])
388 return self.variables[a]
390 def append_with_space(self, k, v):
391 if (not k in self.variables) or len(self.variables[k]) == 0:
392 self.variables[k] = '"%s"' % v
394 e = self.variables[k]
395 if e[0] == '"' and e[-1] == '"':
396 self.variables[k] = '"%s %s"' % (e[1:-1], v)
398 self.variables[k] = '"%s %s"' % (e, v)
400 def variables_string(self, escaped_quotes=False):
402 for k, v in self.variables.items():
404 v = v.replace('"', '\\"')
405 e += '%s=%s ' % (k, v)
410 rmtree(self.directory)
413 class WindowsTarget(Target):
415 This target exposes the following additional API:
417 version: Windows version ('xp' or None)
418 bits: bitness of Windows (32 or 64)
419 name: name of our target e.g. x86_64-w64-mingw32.shared
420 library_prefix: path to Windows libraries
421 tool_path: path to toolchain binaries
423 def __init__(self, version, bits, directory=None):
424 super(WindowsTarget, self).__init__('windows', directory)
425 self.version = version
428 self.tool_path = '%s/usr/bin' % config.get('mxe_prefix')
430 self.name = 'i686-w64-mingw32.shared'
432 self.name = 'x86_64-w64-mingw32.shared'
433 self.library_prefix = '%s/usr/%s' % (config.get('mxe_prefix'), self.name)
435 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.library_prefix)
436 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
437 self.set('PATH', '%s/bin:%s:%s' % (self.library_prefix, self.tool_path, os.environ['PATH']))
438 print(self.get('PATH'))
439 self.set('CC', '%s-gcc' % self.name)
440 self.set('CXX', '%s-g++' % self.name)
441 self.set('LD', '%s-ld' % self.name)
442 self.set('RANLIB', '%s-ranlib' % self.name)
443 self.set('WINRC', '%s-windres' % self.name)
444 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
445 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
446 self.set('CXXFLAGS', '"%s"' % cxx)
447 self.set('CPPFLAGS', '')
448 self.set('LINKFLAGS', '"%s"' % link)
449 self.set('LDFLAGS', '"%s"' % link)
451 # These are for backwards-compatibility
452 self.windows_prefix = self.library_prefix
453 self.mingw_prefixes = [self.library_prefix]
454 self.mingw_path = self.tool_path
455 self.mingw_name = self.name
457 def command(self, c):
458 log('host -> %s' % c)
459 command('%s %s' % (self.variables_string(), c))
461 class LinuxTarget(Target):
463 Build for Linux in a docker container.
464 This target exposes the following additional API:
466 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
467 version: distribution version (e.g. '12.04', '8', '6.5')
468 bits: bitness of the distribution (32 or 64)
471 def __init__(self, distro, version, bits, directory=None):
472 super(LinuxTarget, self).__init__('linux', directory)
474 self.version = version
477 self.set('CXXFLAGS', '-I%s/include' % self.directory)
478 self.set('CPPFLAGS', '')
479 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
480 self.set('PKG_CONFIG_PATH',
481 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
482 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
484 class DockerTarget(LinuxTarget):
485 """Build in a docker container"""
486 def __init__(self, distro, version, bits, directory=None):
487 super(DockerTarget, self).__init__(distro, version, bits, directory)
489 def build(self, project, checkout):
491 if checkout is not None:
492 ch = '-c %s' % checkout
493 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
494 container = command_and_read('%s run -itd %s /bin/bash' % (config.docker(), target)).read().strip()
495 command('%s exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s build -w /cdist"' % (config.docker(), container, project, target, ch))
496 command('%s kill %s' % (config.docker(), container))
498 def package(self, project, checkout, output_dir):
500 if checkout is not None:
501 ch = '-c %s' % checkout
502 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
503 container = command_and_read('%s run -itd %s /bin/bash' % (config.docker(), target)).read().strip()
504 command('%s exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s package -w /cdist"' % (config.docker(), container, project, target, ch))
505 # I can't get wildcards to work with docker cp
506 debs = command_and_read('%s exec -t %s ls -1 /%s' % (config.docker(), container, target)).read().split('\n')
510 command('%s cp %s:/%s/%s %s' % (config.docker(), container, target, d, output_dir))
511 command('%s kill %s' % (config.docker(), container))
513 class DirectTarget(LinuxTarget):
514 """Build directly in the current environment"""
515 def __init__(self, distro, version, bits, directory=None):
516 super(DirectTarget, self).__init__(distro, version, bits, directory)
518 def command(self, c):
519 command('%s %s' % (self.variables_string(), c))
522 class OSXTarget(Target):
523 def __init__(self, directory=None):
524 super(OSXTarget, self).__init__('osx', directory)
525 self.sdk = config.get('osx_sdk')
526 self.sdk_prefix = config.get('osx_sdk_prefix')
527 self.environment_prefix = config.get('osx_environment_prefix')
529 def command(self, c):
530 command('%s %s' % (self.variables_string(False), c))
533 class OSXSingleTarget(OSXTarget):
534 def __init__(self, bits, directory=None):
535 super(OSXSingleTarget, self).__init__(directory)
543 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
544 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
546 # Environment variables
547 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
548 self.set('CPPFLAGS', '')
549 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
550 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
551 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
552 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
553 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
554 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
556 def package(self, project, checkout, output_dir):
557 raise Error('cannot package non-universal OS X versions')
560 class OSXUniversalTarget(OSXTarget):
561 def __init__(self, directory=None):
562 super(OSXUniversalTarget, self).__init__(directory)
564 def package(self, project, checkout, output_dir):
567 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
568 tree = globals.trees.get(project, checkout, target)
569 tree.build_dependencies()
572 tree = globals.trees.get(project, checkout, self)
573 with TreeDirectory(tree):
574 for p in tree.call('package', tree.version):
575 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
577 class SourceTarget(Target):
578 """Build a source .tar.bz2"""
580 super(SourceTarget, self).__init__('source')
582 def command(self, c):
583 log('host -> %s' % c)
584 command('%s %s' % (self.variables_string(), c))
587 rmtree(self.directory)
589 def package(self, project, checkout, output_dir):
590 tree = globals.trees.get(project, checkout, self)
591 with TreeDirectory(tree):
592 name = read_wscript_variable(os.getcwd(), 'APPNAME')
593 command('./waf dist')
594 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
595 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
597 # @param s Target string:
599 # or ubuntu-version-{32,64}
600 # or debian-version-{32,64}
601 # or centos-version-{32,64}
602 # or fedora-version-{32,64}
605 # @param debug True to build with debugging symbols (where possible)
606 def target_factory(s, direct, debug, work):
608 if s.startswith('windows-'):
611 target = WindowsTarget(None, int(x[1]), work)
613 target = WindowsTarget(x[1], int(x[2]), work)
615 raise Error("Bad Windows target name `%s'")
616 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora'):
619 raise Error("Bad Linux target name `%s'; must be something like ubuntu-12.04-32 (i.e. distro-version-bits)" % s)
621 target = DirectTarget(p[0], p[1], int(p[2]), work)
623 target = DockerTarget(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 = DockerTarget(p[0], None, p[1], work)
629 elif s == 'raspbian':
630 target = DockerTarget(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()
641 target = DockerTarget()
644 raise Error("Bad target `%s'" % s)
655 """Description of a tree, which is a checkout of a project,
656 possibly built. This class is never exposed to cscripts.
658 name -- name of git repository (without the .git)
659 specifier -- git tag or revision to use
660 target --- target object that we are using
661 version --- version from the wscript (if one is present)
662 git_commit -- git revision that is actually being used
663 built --- true if the tree has been built yet in this run
666 def __init__(self, name, specifier, target):
668 self.specifier = specifier
671 self.git_commit = None
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 parameter")
718 deps = self.call('dependencies')
721 dep = globals.trees.get(d[0], d[1], self.target)
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('-d', '--direct', help='build in the current environment', action='store_true')
795 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
796 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
797 parser.add_argument('-w', '--work', help='override default work directory')
798 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
799 parser.add_argument('--test', help='name of test to run (with `test''), defaults to all')
800 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
801 args = parser.parse_args()
803 # Override configured stuff
804 if args.git_prefix is not None:
805 config.set('git_prefix', args.git_prefix)
807 if args.output.find(':') == -1:
808 # This isn't of the form host:path so make it absolute
809 args.output = os.path.abspath(args.output) + '/'
811 if args.output[-1] != ':' and args.output[-1] != '/':
814 # Now, args.output is 'host:', 'host:path/' or 'path/'
816 if args.work is not None:
817 args.work = os.path.abspath(args.work)
819 if args.project is None and args.command != 'shell':
820 raise Error('you must specify -p or --project')
822 globals.quiet = args.quiet
823 globals.command = args.command
824 globals.dry_run = args.dry_run
826 if not globals.command in commands:
827 e = 'command must be one of:\n' + one_of
828 raise Error('command must be one of:\n%s' % one_of)
830 if globals.command == 'build':
831 if args.target is None:
832 raise Error('you must specify -t or --target')
834 target = target_factory(args.target, args.direct, args.debug, args.work)
835 target.build(args.project, args.checkout)
839 elif globals.command == 'package':
840 if args.target is None:
841 raise Error('you must specify -t or --target')
843 target = target_factory(args.target, args.direct, args.debug, args.work)
845 if target.platform == 'linux':
846 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
848 output_dir = args.output
851 target.package(args.project, args.checkout, output_dir)
856 elif globals.command == 'release':
857 if args.minor is False and args.micro is False:
858 raise Error('you must specify --minor or --micro')
860 target = SourceTarget()
861 tree = globals.trees.get(args.project, args.checkout, target)
863 version = tree.version
870 with TreeDirectory(tree):
871 set_version_in_wscript(version)
872 append_version_to_changelog(version)
873 append_version_to_debian_changelog(version)
875 command('git commit -a -m "Bump version"')
876 command('git tag -m "v%s" v%s' % (version, version))
879 set_version_in_wscript(version)
880 command('git commit -a -m "Bump version"')
882 command('git push --tags')
886 elif globals.command == 'pot':
887 target = SourceTarget()
888 tree = globals.trees.get(args.project, args.checkout, target)
890 pots = tree.call('make_pot')
892 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
896 elif globals.command == 'changelog':
897 target = SourceTarget()
898 tree = globals.trees.get(args.project, args.checkout, target)
900 with TreeDirectory(tree):
901 text = open('ChangeLog', 'r')
903 html = tempfile.NamedTemporaryFile()
914 if len(l) > 0 and l[0] == "\t":
916 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
919 if last is not None and len(changes) > 0:
920 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
921 print("<ul>", file=html)
923 print("<li>%s" % c, file=html)
924 print("</ul>", file=html)
934 changes.append(c[2:])
936 changes[-1] += " " + c
938 copyfile(html.file, '%schangelog.html' % args.output)
942 elif globals.command == 'manual':
943 target = SourceTarget()
944 tree = globals.trees.get(args.project, args.checkout, target)
946 outs = tree.call('make_manual')
948 if os.path.isfile(o):
949 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
951 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
955 elif globals.command == 'doxygen':
956 target = SourceTarget()
957 tree = globals.trees.get(args.project, args.checkout, target)
959 dirs = tree.call('make_doxygen')
960 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
964 copytree(d, args.output)
968 elif globals.command == 'latest':
969 target = SourceTarget()
970 tree = globals.trees.get(args.project, args.checkout, target)
972 with TreeDirectory(tree):
973 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
975 while latest is None:
977 m = re.compile(".*\((.*)\).*").match(t)
979 tags = m.group(1).split(', ')
984 if len(t) > 0 and t[0] == 'v':
986 if args.major is None or v.major == args.major:
992 elif globals.command == 'test':
993 if args.target is None:
994 raise Error('you must specify -t or --target')
998 target = target_factory(args.target, args.direct, args.debug, args.work)
999 tree = globals.trees.get(args.project, args.checkout, target)
1000 with TreeDirectory(tree):
1001 target.test(tree, args.test)
1003 if target is not None:
1007 if target is not None:
1010 elif globals.command == 'shell':
1011 if args.target is None:
1012 raise Error('you must specify -t or --target')
1014 target = target_factory(args.target, args.direct, args.debug, args.work)
1015 target.command('bash')
1017 elif globals.command == 'revision':
1019 target = SourceTarget()
1020 tree = globals.trees.get(args.project, args.checkout, target)
1021 with TreeDirectory(tree):
1022 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1025 elif globals.command == 'checkout':
1027 if args.output is None:
1028 raise Error('you must specify -o or --output')
1030 target = SourceTarget()
1031 tree = globals.trees.get(args.project, args.checkout, target)
1032 with TreeDirectory(tree):
1033 shutil.copytree('.', args.output)
1037 raise Error('invalid command %s' % globals.command)
1042 print('cdist: %s' % str(e), file=sys.stderr)