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
367 def package(self, project, checkout, output_dir):
368 tree = globals.trees.get(project, checkout, self)
369 tree.build_dependencies()
371 packages = tree.call('package', tree.version)
372 if isinstance(packages, (str, unicode)):
373 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
376 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
378 def build(self, project, checkout):
379 tree = globals.trees.get(project, checkout, self)
380 tree.build_dependencies()
383 def test(self, tree, test):
384 """test is the test case to run, or None"""
385 tree.build_dependencies()
387 return tree.call('test', test)
390 self.variables[a] = b
393 del(self.variables[a])
396 return self.variables[a]
398 def append(self, k, v, s):
399 if (not k in self.variables) or len(self.variables[k]) == 0:
400 self.variables[k] = '"%s"' % v
402 e = self.variables[k]
403 if e[0] == '"' and e[-1] == '"':
404 self.variables[k] = '"%s%s%s"' % (e[1:-1], s, v)
406 self.variables[k] = '"%s%s%s"' % (e, s, v)
408 def append_with_space(self, k, v):
409 return self.append(k, v, ' ')
411 def append_with_colon(self, k, v):
412 return self.append(k, v, ':')
414 def variables_string(self, escaped_quotes=False):
416 for k, v in self.variables.items():
418 v = v.replace('"', '\\"')
419 e += '%s=%s ' % (k, v)
424 rmtree(self.directory)
430 class WindowsTarget(Target):
432 This target exposes the following additional API:
434 version: Windows version ('xp' or None)
435 bits: bitness of Windows (32 or 64)
436 name: name of our target e.g. x86_64-w64-mingw32.shared
437 library_prefix: path to Windows libraries
438 tool_path: path to toolchain binaries
440 def __init__(self, version, bits, directory=None):
441 super(WindowsTarget, self).__init__('windows', directory)
442 self.version = version
445 self.tool_path = '%s/usr/bin' % config.get('mxe_prefix')
447 self.name = 'i686-w64-mingw32.shared'
449 self.name = 'x86_64-w64-mingw32.shared'
450 self.library_prefix = '%s/usr/%s' % (config.get('mxe_prefix'), self.name)
452 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.library_prefix)
453 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
454 self.set('PATH', '%s/bin:%s:%s' % (self.library_prefix, self.tool_path, os.environ['PATH']))
455 self.set('CC', '%s-gcc' % self.name)
456 self.set('CXX', '%s-g++' % self.name)
457 self.set('LD', '%s-ld' % self.name)
458 self.set('RANLIB', '%s-ranlib' % self.name)
459 self.set('WINRC', '%s-windres' % self.name)
460 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
461 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
462 self.set('CXXFLAGS', '"%s"' % cxx)
463 self.set('CPPFLAGS', '')
464 self.set('LINKFLAGS', '"%s"' % link)
465 self.set('LDFLAGS', '"%s"' % link)
468 def windows_prefix(self):
469 log('Deprecated property windows_prefix')
470 return self.library_prefix
473 def mingw_prefixes(self):
474 log('Deprecated property mingw_prefixes')
475 return [self.library_prefix]
478 def mingw_path(self):
479 log('Deprecated property mingw_path')
480 return self.tool_path
483 def mingw_name(self):
484 log('Deprecated property mingw_name')
487 def command(self, c):
488 log('host -> %s' % c)
489 command('%s %s' % (self.variables_string(), c))
491 class LinuxTarget(Target):
493 Build for Linux in a docker container.
494 This target exposes the following additional API:
496 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
497 version: distribution version (e.g. '12.04', '8', '6.5')
498 bits: bitness of the distribution (32 or 64)
501 def __init__(self, distro, version, bits, directory=None):
502 super(LinuxTarget, self).__init__('linux', directory)
504 self.version = version
508 self.set('CXXFLAGS', '-I%s/include' % self.directory)
509 self.set('CPPFLAGS', '')
510 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
511 self.set('PKG_CONFIG_PATH',
512 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
513 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
516 image = '%s-%s-%s' % (self.distro, self.version, self.bits)
517 mounts = '-v %s:%s ' % (self.directory, self.directory)
518 for m in self.mounts:
519 mounts += '-v %s:%s ' % (m, m)
520 self.container = command_and_read('%s run -u %s %s -itd %s /bin/bash' % (config.docker(), getpass.getuser(), mounts, image)).read().strip()
522 def command(self, cmd):
523 dir = os.path.join(self.directory, os.path.relpath(os.getcwd(), self.directory))
524 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))
527 super(LinuxTarget, self).cleanup()
528 command('%s kill %s' % (config.docker(), self.container))
530 def test(self, tree, test):
531 self.append_with_colon('PATH', '%s/bin' % self.directory)
532 self.append_with_colon('LD_LIBRARY_PATH', '%s/lib' % self.directory)
533 super(LinuxTarget, self).test(tree, test)
536 self.mounts.append(m)
538 class OSXTarget(Target):
539 def __init__(self, directory=None):
540 super(OSXTarget, self).__init__('osx', directory)
541 self.sdk = config.get('osx_sdk')
542 self.sdk_prefix = config.get('osx_sdk_prefix')
543 self.environment_prefix = config.get('osx_environment_prefix')
545 def command(self, c):
546 command('%s %s' % (self.variables_string(False), c))
549 class OSXSingleTarget(OSXTarget):
550 def __init__(self, bits, directory=None):
551 super(OSXSingleTarget, self).__init__(directory)
559 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
560 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
562 # Environment variables
563 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
564 self.set('CPPFLAGS', '')
565 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
566 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
567 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
568 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
569 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
570 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
572 def package(self, project, checkout, output_dir):
573 raise Error('cannot package non-universal OS X versions')
576 class OSXUniversalTarget(OSXTarget):
577 def __init__(self, directory=None):
578 super(OSXUniversalTarget, self).__init__(directory)
580 def package(self, project, checkout, output_dir):
583 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
584 tree = globals.trees.get(project, checkout, target)
585 tree.build_dependencies()
588 tree = globals.trees.get(project, checkout, self)
589 with TreeDirectory(tree):
590 for p in tree.call('package', tree.version):
591 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
593 class SourceTarget(Target):
594 """Build a source .tar.bz2"""
596 super(SourceTarget, self).__init__('source')
598 def command(self, c):
599 log('host -> %s' % c)
600 command('%s %s' % (self.variables_string(), c))
603 rmtree(self.directory)
605 def package(self, project, checkout, output_dir):
606 tree = globals.trees.get(project, checkout, self)
607 with TreeDirectory(tree):
608 name = read_wscript_variable(os.getcwd(), 'APPNAME')
609 command('./waf dist')
610 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
611 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
613 # @param s Target string:
615 # or ubuntu-version-{32,64}
616 # or debian-version-{32,64}
617 # or centos-version-{32,64}
618 # or fedora-version-{32,64}
619 # or mageia-version-{32,64}
622 # @param debug True to build with debugging symbols (where possible)
623 def target_factory(args):
626 if s.startswith('windows-'):
629 target = WindowsTarget(None, int(x[1]), args.work)
631 target = WindowsTarget(x[1], int(x[2]), args.work)
633 raise Error("Bad Windows target name `%s'")
634 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora-') or s.startswith('mageia-'):
637 raise Error("Bad Linux target name `%s'; must be something like ubuntu-16.04-32 (i.e. distro-version-bits)" % s)
638 target = LinuxTarget(p[0], p[1], int(p[2]), args.work)
639 elif s.startswith('arch-'):
642 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
643 target = LinuxTarget(p[0], None, p[1], args.work)
644 elif s == 'raspbian':
645 target = LinuxTarget(s, None, None, args.work)
646 elif s.startswith('osx-'):
647 target = OSXSingleTarget(int(s.split('-')[1]), args.work)
649 if globals.command == 'build':
650 target = OSXSingleTarget(64, args.work)
652 target = OSXUniversalTarget(args.work)
654 target = SourceTarget()
657 raise Error("Bad target `%s'" % s)
659 target.debug = args.debug
661 if args.environment is not None:
662 for e in args.environment:
663 target.set(e, os.environ[e])
665 if args.mount is not None:
678 """Description of a tree, which is a checkout of a project,
679 possibly built. This class is never exposed to cscripts.
681 name -- name of git repository (without the .git)
682 specifier -- git tag or revision to use
683 target -- target object that we are using
684 version -- version from the wscript (if one is present)
685 git_commit -- git revision that is actually being used
686 built -- true if the tree has been built yet in this run
687 required_by -- name of the tree that requires this one
690 def __init__(self, name, specifier, target, required_by):
692 self.specifier = specifier
695 self.git_commit = None
697 self.required_by = required_by
705 redirect = '>/dev/null'
706 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
707 os.chdir('%s/src/%s' % (target.directory, self.name))
709 spec = self.specifier
713 command('git checkout %s %s %s' % (flags, spec, redirect))
714 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
715 command('git submodule init --quiet')
716 command('git submodule update --quiet')
718 proj = '%s/src/%s' % (target.directory, self.name)
721 exec(open('%s/cscript' % proj).read(), self.cscript)
723 if os.path.exists('%s/wscript' % proj):
724 v = read_wscript_variable(proj, "VERSION");
726 self.version = Version(v)
730 def call(self, function, *args):
731 with TreeDirectory(self):
732 return self.cscript[function](self.target, *args)
734 def build_dependencies(self, options=None):
736 if not 'dependencies' in self.cscript:
739 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
740 deps = self.call('dependencies', options)
742 log("Deprecated cscipt dependencies() method with no options parameter")
743 deps = self.call('dependencies')
746 dep = globals.trees.get(d[0], d[1], self.target, self.name)
749 # Make the options to pass in from the option_defaults of the thing
750 # we are building and any options specified by the parent.
751 if 'option_defaults' in dep.cscript:
752 for k, v in dep.cscript['option_defaults']().items():
756 for k, v in d[2].items():
759 msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
761 msg += ' with options %s' % options
764 dep.build_dependencies(options)
767 def build(self, options=None):
771 variables = copy.copy(self.target.variables)
773 if not globals.dry_run:
774 if len(inspect.getargspec(self.cscript['build']).args) == 2:
775 self.call('build', options)
779 self.target.variables = variables
783 # Command-line parser
789 "build": "build project",
790 "package": "package and build project",
791 "release": "release a project using its next version number (changing wscript and tagging)",
792 "pot": "build the project's .pot files",
793 "changelog": "generate a simple HTML changelog",
794 "manual": "build the project's manual",
795 "doxygen": "build the project's Doxygen documentation",
796 "latest": "print out the latest version",
797 "test": "run the project's unit tests",
798 "shell": "build the project then start a shell",
799 "checkout": "check out the project",
800 "revision": "print the head git revision number"
803 one_of = "Command is one of:\n"
805 for k, v in commands.items():
806 one_of += "\t%s\t%s\n" % (k, v)
809 parser = argparse.ArgumentParser()
810 parser.add_argument('command', help=summary)
811 parser.add_argument('-p', '--project', help='project name')
812 parser.add_argument('--minor', help='minor version number bump', action='store_true')
813 parser.add_argument('--micro', help='micro version number bump', action='store_true')
814 parser.add_argument('--major', help='major version to return with latest', type=int)
815 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
816 parser.add_argument('-o', '--output', help='output directory', default='.')
817 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
818 parser.add_argument('-t', '--target', help='target')
819 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
820 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
821 parser.add_argument('-w', '--work', help='override default work directory')
822 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
823 parser.add_argument('--test', help="name of test to run (with `test'), defaults to all")
824 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
825 parser.add_argument('-e', '--environment', help='pass the value of the named environment variable into the build', action='append')
826 parser.add_argument('-m', '--mount', help='mount a given directory in the build environment', action='append')
827 args = parser.parse_args()
829 # Override configured stuff
830 if args.git_prefix is not None:
831 config.set('git_prefix', args.git_prefix)
833 if args.output.find(':') == -1:
834 # This isn't of the form host:path so make it absolute
835 args.output = os.path.abspath(args.output) + '/'
837 if args.output[-1] != ':' and args.output[-1] != '/':
840 # Now, args.output is 'host:', 'host:path/' or 'path/'
842 if args.work is not None:
843 args.work = os.path.abspath(args.work)
845 if args.project is None and args.command != 'shell':
846 raise Error('you must specify -p or --project')
848 globals.quiet = args.quiet
849 globals.command = args.command
850 globals.dry_run = args.dry_run
852 if not globals.command in commands:
853 e = 'command must be one of:\n' + one_of
854 raise Error('command must be one of:\n%s' % one_of)
856 if globals.command == 'build':
857 if args.target is None:
858 raise Error('you must specify -t or --target')
860 target = target_factory(args)
861 target.build(args.project, args.checkout)
865 elif globals.command == 'package':
866 if args.target is None:
867 raise Error('you must specify -t or --target')
869 target = target_factory(args)
871 if target.platform == 'linux':
872 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
874 output_dir = args.output
877 target.package(args.project, args.checkout, output_dir)
882 elif globals.command == 'release':
883 if args.minor is False and args.micro is False:
884 raise Error('you must specify --minor or --micro')
886 target = SourceTarget()
887 tree = globals.trees.get(args.project, args.checkout, target)
889 version = tree.version
896 with TreeDirectory(tree):
897 set_version_in_wscript(version)
898 append_version_to_changelog(version)
899 append_version_to_debian_changelog(version)
901 command('git commit -a -m "Bump version"')
902 command('git tag -m "v%s" v%s' % (version, version))
905 set_version_in_wscript(version)
906 command('git commit -a -m "Bump version"')
908 command('git push --tags')
912 elif globals.command == 'pot':
913 target = SourceTarget()
914 tree = globals.trees.get(args.project, args.checkout, target)
916 pots = tree.call('make_pot')
918 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
922 elif globals.command == 'changelog':
923 target = SourceTarget()
924 tree = globals.trees.get(args.project, args.checkout, target)
926 with TreeDirectory(tree):
927 text = open('ChangeLog', 'r')
929 html = tempfile.NamedTemporaryFile()
940 if len(l) > 0 and l[0] == "\t":
942 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
945 if last is not None and len(changes) > 0:
946 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
947 print("<ul>", file=html)
949 print("<li>%s" % c, file=html)
950 print("</ul>", file=html)
960 changes.append(c[2:])
962 changes[-1] += " " + c
964 copyfile(html.file, '%schangelog.html' % args.output)
968 elif globals.command == 'manual':
969 target = SourceTarget()
970 tree = globals.trees.get(args.project, args.checkout, target)
972 outs = tree.call('make_manual')
974 if os.path.isfile(o):
975 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
977 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
981 elif globals.command == 'doxygen':
982 target = SourceTarget()
983 tree = globals.trees.get(args.project, args.checkout, target)
985 dirs = tree.call('make_doxygen')
986 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
990 copytree(d, args.output)
994 elif globals.command == 'latest':
995 target = SourceTarget()
996 tree = globals.trees.get(args.project, args.checkout, target)
998 with TreeDirectory(tree):
999 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
1001 while latest is None:
1003 m = re.compile(".*\((.*)\).*").match(t)
1005 tags = m.group(1).split(', ')
1010 if len(t) > 0 and t[0] == 'v':
1012 if args.major is None or v.major == args.major:
1018 elif globals.command == 'test':
1019 if args.target is None:
1020 raise Error('you must specify -t or --target')
1024 target = target_factory(args)
1025 tree = globals.trees.get(args.project, args.checkout, target)
1026 with TreeDirectory(tree):
1027 target.test(tree, args.test)
1029 if target is not None and not args.keep:
1033 if target is not None and not args.keep:
1036 elif globals.command == 'shell':
1037 if args.target is None:
1038 raise Error('you must specify -t or --target')
1040 target = target_factory(args)
1041 target.command('bash')
1043 elif globals.command == 'revision':
1045 target = SourceTarget()
1046 tree = globals.trees.get(args.project, args.checkout, target)
1047 with TreeDirectory(tree):
1048 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1051 elif globals.command == 'checkout':
1053 if args.output is None:
1054 raise Error('you must specify -o or --output')
1056 target = SourceTarget()
1057 tree = globals.trees.get(args.project, args.checkout, target)
1058 with TreeDirectory(tree):
1059 shutil.copytree('.', args.output)
1063 raise Error('invalid command %s' % globals.command)
1068 print('cdist: %s' % str(e), file=sys.stderr)