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 self.set('CC', '%s-gcc' % self.name)
439 self.set('CXX', '%s-g++' % self.name)
440 self.set('LD', '%s-ld' % self.name)
441 self.set('RANLIB', '%s-ranlib' % self.name)
442 self.set('WINRC', '%s-windres' % self.name)
443 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
444 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
445 self.set('CXXFLAGS', '"%s"' % cxx)
446 self.set('CPPFLAGS', '')
447 self.set('LINKFLAGS', '"%s"' % link)
448 self.set('LDFLAGS', '"%s"' % link)
451 def windows_prefix(self):
452 log('Deprecated property windows_prefix')
453 return self.library_prefix
456 def mingw_prefixes(self):
457 log('Deprecated property mingw_prefixes')
458 return [self.library_prefix]
461 def mingw_path(self):
462 log('Deprecated property mingw_path')
463 return self.tool_path
466 def mingw_name(self):
467 log('Deprecated property mingw_name')
470 def command(self, c):
471 log('host -> %s' % c)
472 command('%s %s' % (self.variables_string(), c))
474 class LinuxTarget(Target):
476 Build for Linux in a docker container.
477 This target exposes the following additional API:
479 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
480 version: distribution version (e.g. '12.04', '8', '6.5')
481 bits: bitness of the distribution (32 or 64)
484 def __init__(self, distro, version, bits, directory=None):
485 super(LinuxTarget, self).__init__('linux', directory)
487 self.version = version
490 self.set('CXXFLAGS', '-I%s/include' % self.directory)
491 self.set('CPPFLAGS', '')
492 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
493 self.set('PKG_CONFIG_PATH',
494 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
495 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
497 class DockerTarget(LinuxTarget):
498 """Build in a docker container"""
499 def __init__(self, distro, version, bits, directory=None):
500 super(DockerTarget, self).__init__(distro, version, bits, directory)
502 def build(self, project, checkout):
504 if checkout is not None:
505 ch = '-c %s' % checkout
506 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
507 container = command_and_read('%s run -itd %s /bin/bash' % (config.docker(), target)).read().strip()
508 command('%s exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s build -w /cdist"' % (config.docker(), container, project, target, ch))
509 command('%s kill %s' % (config.docker(), container))
511 def package(self, project, checkout, output_dir):
513 if checkout is not None:
514 ch = '-c %s' % checkout
515 target = '%s-%s-%s' % (self.distro, self.version, self.bits)
516 container = command_and_read('%s run -itd %s /bin/bash' % (config.docker(), target)).read().strip()
517 command('%s exec -t %s /bin/bash -c "cdist -p %s -t %s -d %s package -w /cdist"' % (config.docker(), container, project, target, ch))
518 # I can't get wildcards to work with docker cp
519 debs = command_and_read('%s exec -t %s ls -1 /%s' % (config.docker(), container, target)).read().split('\n')
523 command('%s cp %s:/%s/%s %s' % (config.docker(), container, target, d, self.directory))
524 copyfile('%s/%s' % (self.directory, d), output_dir)
525 command('%s kill %s' % (config.docker(), container))
527 def command(self, cmd):
528 command('%s exec -t %s /bin/bash -c "%s"' % (config.docker(), container, cmd))
530 class DirectTarget(LinuxTarget):
531 """Build directly in the current environment"""
532 def __init__(self, distro, version, bits, directory=None):
533 super(DirectTarget, self).__init__(distro, version, bits, directory)
535 def command(self, c):
536 command('%s %s' % (self.variables_string(), c))
539 class OSXTarget(Target):
540 def __init__(self, directory=None):
541 super(OSXTarget, self).__init__('osx', directory)
542 self.sdk = config.get('osx_sdk')
543 self.sdk_prefix = config.get('osx_sdk_prefix')
544 self.environment_prefix = config.get('osx_environment_prefix')
546 def command(self, c):
547 command('%s %s' % (self.variables_string(False), c))
550 class OSXSingleTarget(OSXTarget):
551 def __init__(self, bits, directory=None):
552 super(OSXSingleTarget, self).__init__(directory)
560 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
561 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
563 # Environment variables
564 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
565 self.set('CPPFLAGS', '')
566 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
567 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
568 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
569 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
570 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
571 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
573 def package(self, project, checkout, output_dir):
574 raise Error('cannot package non-universal OS X versions')
577 class OSXUniversalTarget(OSXTarget):
578 def __init__(self, directory=None):
579 super(OSXUniversalTarget, self).__init__(directory)
581 def package(self, project, checkout, output_dir):
584 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
585 tree = globals.trees.get(project, checkout, target)
586 tree.build_dependencies()
589 tree = globals.trees.get(project, checkout, self)
590 with TreeDirectory(tree):
591 for p in tree.call('package', tree.version):
592 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
594 class SourceTarget(Target):
595 """Build a source .tar.bz2"""
597 super(SourceTarget, self).__init__('source')
599 def command(self, c):
600 log('host -> %s' % c)
601 command('%s %s' % (self.variables_string(), c))
604 rmtree(self.directory)
606 def package(self, project, checkout, output_dir):
607 tree = globals.trees.get(project, checkout, self)
608 with TreeDirectory(tree):
609 name = read_wscript_variable(os.getcwd(), 'APPNAME')
610 command('./waf dist')
611 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
612 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
614 # @param s Target string:
616 # or ubuntu-version-{32,64}
617 # or debian-version-{32,64}
618 # or centos-version-{32,64}
619 # or fedora-version-{32,64}
622 # @param debug True to build with debugging symbols (where possible)
623 def target_factory(s, direct, debug, work):
625 if s.startswith('windows-'):
628 target = WindowsTarget(None, int(x[1]), work)
630 target = WindowsTarget(x[1], int(x[2]), work)
632 raise Error("Bad Windows target name `%s'")
633 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora'):
636 raise Error("Bad Linux target name `%s'; must be something like ubuntu-12.04-32 (i.e. distro-version-bits)" % s)
638 target = DirectTarget(p[0], p[1], int(p[2]), work)
640 target = DockerTarget(p[0], p[1], int(p[2]), work)
641 elif s.startswith('arch-'):
644 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
645 target = DockerTarget(p[0], None, p[1], work)
646 elif s == 'raspbian':
647 target = DockerTarget(s, None, None, work)
648 elif s.startswith('osx-'):
649 target = OSXSingleTarget(int(s.split('-')[1]), work)
651 if globals.command == 'build':
652 target = OSXSingleTarget(64, work)
654 target = OSXUniversalTarget(work)
656 target = SourceTarget()
658 target = DockerTarget()
661 raise Error("Bad target `%s'" % s)
672 """Description of a tree, which is a checkout of a project,
673 possibly built. This class is never exposed to cscripts.
675 name -- name of git repository (without the .git)
676 specifier -- git tag or revision to use
677 target --- target object that we are using
678 version --- version from the wscript (if one is present)
679 git_commit -- git revision that is actually being used
680 built --- true if the tree has been built yet in this run
683 def __init__(self, name, specifier, target):
685 self.specifier = specifier
688 self.git_commit = None
697 redirect = '>/dev/null'
698 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
699 os.chdir('%s/src/%s' % (target.directory, self.name))
701 spec = self.specifier
705 command('git checkout %s %s %s' % (flags, spec, redirect))
706 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
707 command('git submodule init --quiet')
708 command('git submodule update --quiet')
710 proj = '%s/src/%s' % (target.directory, self.name)
713 exec(open('%s/cscript' % proj).read(), self.cscript)
715 if os.path.exists('%s/wscript' % proj):
716 v = read_wscript_variable(proj, "VERSION");
718 self.version = Version(v)
722 def call(self, function, *args):
723 with TreeDirectory(self):
724 return self.cscript[function](self.target, *args)
726 def build_dependencies(self, options=None):
728 if not 'dependencies' in self.cscript:
731 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
732 deps = self.call('dependencies', options)
734 log("Deprecated cscipt dependencies() method with no parameter")
735 deps = self.call('dependencies')
738 dep = globals.trees.get(d[0], d[1], self.target)
741 # Make the options to pass in from the option_defaults of the thing
742 # we are building and any options specified by the parent.
743 if 'option_defaults' in dep.cscript:
744 for k, v in dep.cscript['option_defaults']().items():
748 for k, v in d[2].items():
751 msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
753 msg += ' with options %s' % options
756 dep.build_dependencies(options)
759 def build(self, options=None):
763 variables = copy.copy(self.target.variables)
765 if not globals.dry_run:
766 if len(inspect.getargspec(self.cscript['build']).args) == 2:
767 self.call('build', options)
771 self.target.variables = variables
775 # Command-line parser
781 "build": "build project",
782 "package": "package and build project",
783 "release": "release a project using its next version number (changing wscript and tagging)",
784 "pot": "build the project's .pot files",
785 "changelog": "generate a simple HTML changelog",
786 "manual": "build the project's manual",
787 "doxygen": "build the project's Doxygen documentation",
788 "latest": "print out the latest version",
789 "test": "run the project's unit tests",
790 "shell": "build the project then start a shell",
791 "checkout": "check out the project",
792 "revision": "print the head git revision number"
795 one_of = "Command is one of:\n"
797 for k, v in commands.items():
798 one_of += "\t%s\t%s\n" % (k, v)
801 parser = argparse.ArgumentParser()
802 parser.add_argument('command', help=summary)
803 parser.add_argument('-p', '--project', help='project name')
804 parser.add_argument('--minor', help='minor version number bump', action='store_true')
805 parser.add_argument('--micro', help='micro version number bump', action='store_true')
806 parser.add_argument('--major', help='major version to return with latest', type=int)
807 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
808 parser.add_argument('-o', '--output', help='output directory', default='.')
809 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
810 parser.add_argument('-t', '--target', help='target')
811 parser.add_argument('-d', '--direct', help='build in the current environment', action='store_true')
812 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
813 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
814 parser.add_argument('-w', '--work', help='override default work directory')
815 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
816 parser.add_argument('--test', help='name of test to run (with `test''), defaults to all')
817 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
818 args = parser.parse_args()
820 # Override configured stuff
821 if args.git_prefix is not None:
822 config.set('git_prefix', args.git_prefix)
824 if args.output.find(':') == -1:
825 # This isn't of the form host:path so make it absolute
826 args.output = os.path.abspath(args.output) + '/'
828 if args.output[-1] != ':' and args.output[-1] != '/':
831 # Now, args.output is 'host:', 'host:path/' or 'path/'
833 if args.work is not None:
834 args.work = os.path.abspath(args.work)
836 if args.project is None and args.command != 'shell':
837 raise Error('you must specify -p or --project')
839 globals.quiet = args.quiet
840 globals.command = args.command
841 globals.dry_run = args.dry_run
843 if not globals.command in commands:
844 e = 'command must be one of:\n' + one_of
845 raise Error('command must be one of:\n%s' % one_of)
847 if globals.command == 'build':
848 if args.target is None:
849 raise Error('you must specify -t or --target')
851 target = target_factory(args.target, args.direct, args.debug, args.work)
852 target.build(args.project, args.checkout)
856 elif globals.command == 'package':
857 if args.target is None:
858 raise Error('you must specify -t or --target')
860 target = target_factory(args.target, args.direct, args.debug, args.work)
862 if target.platform == 'linux':
863 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
865 output_dir = args.output
868 target.package(args.project, args.checkout, output_dir)
873 elif globals.command == 'release':
874 if args.minor is False and args.micro is False:
875 raise Error('you must specify --minor or --micro')
877 target = SourceTarget()
878 tree = globals.trees.get(args.project, args.checkout, target)
880 version = tree.version
887 with TreeDirectory(tree):
888 set_version_in_wscript(version)
889 append_version_to_changelog(version)
890 append_version_to_debian_changelog(version)
892 command('git commit -a -m "Bump version"')
893 command('git tag -m "v%s" v%s' % (version, version))
896 set_version_in_wscript(version)
897 command('git commit -a -m "Bump version"')
899 command('git push --tags')
903 elif globals.command == 'pot':
904 target = SourceTarget()
905 tree = globals.trees.get(args.project, args.checkout, target)
907 pots = tree.call('make_pot')
909 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
913 elif globals.command == 'changelog':
914 target = SourceTarget()
915 tree = globals.trees.get(args.project, args.checkout, target)
917 with TreeDirectory(tree):
918 text = open('ChangeLog', 'r')
920 html = tempfile.NamedTemporaryFile()
931 if len(l) > 0 and l[0] == "\t":
933 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
936 if last is not None and len(changes) > 0:
937 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
938 print("<ul>", file=html)
940 print("<li>%s" % c, file=html)
941 print("</ul>", file=html)
951 changes.append(c[2:])
953 changes[-1] += " " + c
955 copyfile(html.file, '%schangelog.html' % args.output)
959 elif globals.command == 'manual':
960 target = SourceTarget()
961 tree = globals.trees.get(args.project, args.checkout, target)
963 outs = tree.call('make_manual')
965 if os.path.isfile(o):
966 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
968 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
972 elif globals.command == 'doxygen':
973 target = SourceTarget()
974 tree = globals.trees.get(args.project, args.checkout, target)
976 dirs = tree.call('make_doxygen')
977 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
981 copytree(d, args.output)
985 elif globals.command == 'latest':
986 target = SourceTarget()
987 tree = globals.trees.get(args.project, args.checkout, target)
989 with TreeDirectory(tree):
990 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
992 while latest is None:
994 m = re.compile(".*\((.*)\).*").match(t)
996 tags = m.group(1).split(', ')
1001 if len(t) > 0 and t[0] == 'v':
1003 if args.major is None or v.major == args.major:
1009 elif globals.command == 'test':
1010 if args.target is None:
1011 raise Error('you must specify -t or --target')
1015 target = target_factory(args.target, args.direct, args.debug, args.work)
1016 tree = globals.trees.get(args.project, args.checkout, target)
1017 with TreeDirectory(tree):
1018 target.test(tree, args.test)
1020 if target is not None:
1024 if target is not None:
1027 elif globals.command == 'shell':
1028 if args.target is None:
1029 raise Error('you must specify -t or --target')
1031 target = target_factory(args.target, args.direct, args.debug, args.work)
1032 target.command('bash')
1034 elif globals.command == 'revision':
1036 target = SourceTarget()
1037 tree = globals.trees.get(args.project, args.checkout, target)
1038 with TreeDirectory(tree):
1039 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1042 elif globals.command == 'checkout':
1044 if args.output is None:
1045 raise Error('you must specify -o or --output')
1047 target = SourceTarget()
1048 tree = globals.trees.get(args.project, args.checkout, target)
1049 with TreeDirectory(tree):
1050 shutil.copytree('.', args.output)
1054 raise Error('invalid command %s' % globals.command)
1059 print('cdist: %s' % str(e), file=sys.stderr)