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
34 TEMPORARY_DIRECTORY = '/var/tmp'
36 class Error(Exception):
37 def __init__(self, value):
46 Store for Tree objects which re-uses already-created objects
47 and checks for requests for different versions of the same thing.
53 def get(self, name, specifier, target, required_by=None):
55 if t.name == name and t.specifier == specifier and t.target == target:
57 elif t.name == name and t.specifier != specifier:
59 if required_by is not None:
60 a += ' by %s' % required_by
62 if t.required_by is not None:
63 b += ' by %s' % t.required_by
64 raise Error('conflicting versions of %s required (%s versus %s)' % (name, a, b))
66 nt = Tree(name, specifier, target, required_by)
84 def __init__(self, key, default=None):
88 def offer(self, key, value):
92 class BoolOption(object):
93 def __init__(self, key):
97 def offer(self, key, value):
99 self.value = (value == 'yes' or value == '1' or value == 'true')
103 self.options = [ Option('mxe_prefix'),
104 Option('git_prefix'),
105 Option('osx_environment_prefix'),
106 Option('osx_sdk_prefix'),
108 BoolOption('docker_sudo'),
109 Option('parallel', 4) ]
112 f = open('%s/.config/cdist' % os.path.expanduser('~'), 'r')
118 if len(l) > 0 and l[0] == '#':
121 s = l.strip().split()
123 for k in self.options:
129 for o in self.options:
132 raise Error('Required setting %s not found' % k)
136 for o in self.options:
140 if self.get('docker_sudo'):
152 if not globals.quiet:
153 print('\x1b[33m* %s\x1b[0m' % m)
155 def escape_spaces(s):
156 return s.replace(' ', '\\ ')
159 """Escape a host:filename string for use with an scp command"""
161 assert(len(s) == 1 or len(s) == 2)
163 return '%s:"\'%s\'"' % (s[0], s[1])
165 return '\"%s\"' % s[0]
168 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
169 if b.startswith('s3://'):
170 command('s3cmd -P -r put "%s" "%s"' % (a, b))
172 command('scp -r %s %s' % (scp_escape(a), scp_escape(b)))
175 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
176 if b.startswith('s3://'):
177 command('s3cmd -P put "%s" "%s"' % (a, b))
183 temp_path = os.path.join(os.path.dirname(path), ".tmp." + os.path.basename(path))
184 command('scp %s %s' % (scp_escape(a), scp_escape(host + ":" + temp_path)))
185 command('ssh %s -- mv "%s" "%s"' % (host, escape_spaces(temp_path), escape_spaces(path)))
187 command('scp %s %s' % (scp_escape(a), scp_escape(b)))
191 Make directories either locally or on a remote host; remotely if
192 d includes a colon, otherwise locally.
194 if d.startswith('s3://'):
195 # No need to create folders on S3
198 if d.find(':') == -1:
206 command('ssh %s -- mkdir -p %s' % (s[0], s[1]))
214 shutil.rmtree(a, ignore_errors=True)
220 raise Error('command %s failed' % c)
222 def command_and_read(c):
224 p = subprocess.Popen(c.split(), stdout=subprocess.PIPE)
225 f = os.fdopen(os.dup(p.stdout.fileno()))
228 def read_wscript_variable(directory, variable):
229 f = open('%s/wscript' % directory, 'r')
236 if len(s) == 3 and s[0] == variable:
243 def set_version_in_wscript(version):
244 f = open('wscript', 'rw')
245 o = open('wscript.tmp', 'w')
252 if len(s) == 3 and s[0] == "VERSION":
253 print("Writing %s" % version)
254 print("VERSION = '%s'" % version, file=o)
256 print(l, file=o, end="")
260 os.rename('wscript.tmp', 'wscript')
262 def append_version_to_changelog(version):
264 f = open('ChangeLog', 'r')
266 log('Could not open ChangeLog')
272 f = open('ChangeLog', 'w')
273 now = datetime.datetime.now()
274 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))
277 def append_version_to_debian_changelog(version):
278 if not os.path.exists('debian'):
279 log('Could not find debian directory')
282 command('dch -b -v %s-1 "New upstream release."' % version)
284 def devel_to_git(git_commit, filename):
285 if git_commit is not None:
286 filename = filename.replace('devel', '-%s' % git_commit)
290 def __init__(self, tree):
293 self.cwd = os.getcwd()
294 os.chdir('%s/src/%s' % (self.tree.target.directory, self.tree.name))
295 def __exit__(self, type, value, traceback):
303 def __init__(self, s):
306 if s.startswith("'"):
311 if s.endswith('devel'):
315 if s.endswith('pre'):
319 self.major = int(p[0])
320 self.minor = int(p[1])
322 self.micro = int(p[2])
326 def bump_minor(self):
330 def bump_micro(self):
336 def to_release(self):
340 s = '%d.%d.%d' % (self.major, self.minor, self.micro)
350 class Target(object):
352 Class representing the target that we are building for. This is exposed to cscripts,
353 though not all of it is guaranteed 'API'. cscripts may expect:
355 platform: platform string (e.g. 'windows', 'linux', 'osx')
356 parallel: number of parallel jobs to run
357 directory: directory to work in
358 variables: dict of environment variables
359 debug: True to build a debug version, otherwise False
360 set(a, b): set the value of variable 'a' to 'b'
361 unset(a): unset the value of variable 'a'
362 command(c): run the command 'c' in the build environment
366 def __init__(self, platform, directory=None):
368 platform -- platform string (e.g. 'windows', 'linux', 'osx')
369 directory -- directory to work in; if None we will use a temporary directory
370 Temporary directories will be removed after use; specified directories will not.
372 self.platform = platform
373 self.parallel = int(config.get('parallel'))
375 if directory is None:
376 self.directory = tempfile.mkdtemp('', 'tmp', TEMPORARY_DIRECTORY)
379 self.directory = directory
382 # Environment variables that we will use when we call cscripts
389 def package(self, project, checkout, output_dir):
390 tree = globals.trees.get(project, checkout, self)
391 tree.build_dependencies()
393 packages = tree.call('package', tree.version)
394 if isinstance(packages, (str, unicode)):
395 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
398 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
400 def build(self, project, checkout):
401 tree = globals.trees.get(project, checkout, self)
402 tree.build_dependencies()
405 def test(self, tree, test):
406 """test is the test case to run, or None"""
407 tree.build_dependencies()
409 return tree.call('test', test)
412 self.variables[a] = b
415 del(self.variables[a])
418 return self.variables[a]
420 def append(self, k, v, s):
421 if (not k in self.variables) or len(self.variables[k]) == 0:
422 self.variables[k] = '"%s"' % v
424 e = self.variables[k]
425 if e[0] == '"' and e[-1] == '"':
426 self.variables[k] = '"%s%s%s"' % (e[1:-1], s, v)
428 self.variables[k] = '"%s%s%s"' % (e, s, v)
430 def append_with_space(self, k, v):
431 return self.append(k, v, ' ')
433 def append_with_colon(self, k, v):
434 return self.append(k, v, ':')
436 def variables_string(self, escaped_quotes=False):
438 for k, v in self.variables.items():
440 v = v.replace('"', '\\"')
441 e += '%s=%s ' % (k, v)
446 rmtree(self.directory)
452 class DockerTarget(Target):
453 def __init__(self, platform, directory, version):
454 super(DockerTarget, self).__init__(platform, directory)
455 self.version = version
459 mounts = '-v %s:%s ' % (self.directory, self.directory)
460 for m in self.mounts:
461 mounts += '-v %s:%s ' % (m, m)
462 self.container = command_and_read('%s run -u %s %s -itd %s /bin/bash' % (config.docker(), getpass.getuser(), mounts, self.image)).read().strip()
464 def command(self, cmd):
465 dir = os.path.join(self.directory, os.path.relpath(os.getcwd(), self.directory))
466 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))
469 super(DockerTarget, self).cleanup()
470 command('%s kill %s' % (config.docker(), self.container))
473 self.mounts.append(m)
476 class WindowsTarget(DockerTarget):
478 This target exposes the following additional API:
480 version: Windows version ('xp' or None)
481 bits: bitness of Windows (32 or 64)
482 name: name of our target e.g. x86_64-w64-mingw32.shared
483 library_prefix: path to Windows libraries
484 tool_path: path to toolchain binaries
486 def __init__(self, version, bits, directory=None):
487 super(WindowsTarget, self).__init__('windows', directory, version)
490 self.tool_path = '%s/usr/bin' % config.get('mxe_prefix')
492 self.name = 'i686-w64-mingw32.shared'
494 self.name = 'x86_64-w64-mingw32.shared'
495 self.library_prefix = '%s/usr/%s' % (config.get('mxe_prefix'), self.name)
497 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.library_prefix)
498 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
499 self.set('PATH', '%s/bin:%s:%s' % (self.library_prefix, self.tool_path, os.environ['PATH']))
500 self.set('CC', '%s-gcc' % self.name)
501 self.set('CXX', '%s-g++' % self.name)
502 self.set('LD', '%s-ld' % self.name)
503 self.set('RANLIB', '%s-ranlib' % self.name)
504 self.set('WINRC', '%s-windres' % self.name)
505 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
506 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
507 self.set('CXXFLAGS', '"%s"' % cxx)
508 self.set('CPPFLAGS', '')
509 self.set('LINKFLAGS', '"%s"' % link)
510 self.set('LDFLAGS', '"%s"' % link)
512 self.image = 'windows'
515 def windows_prefix(self):
516 log('Deprecated property windows_prefix')
517 return self.library_prefix
520 def mingw_prefixes(self):
521 log('Deprecated property mingw_prefixes')
522 return [self.library_prefix]
525 def mingw_path(self):
526 log('Deprecated property mingw_path')
527 return self.tool_path
530 def mingw_name(self):
531 log('Deprecated property mingw_name')
535 class LinuxTarget(DockerTarget):
537 Build for Linux in a docker container.
538 This target exposes the following additional API:
540 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
541 version: distribution version (e.g. '12.04', '8', '6.5')
542 bits: bitness of the distribution (32 or 64)
545 def __init__(self, distro, version, bits, directory=None):
546 super(LinuxTarget, self).__init__('linux', directory, version)
550 self.set('CXXFLAGS', '-I%s/include' % self.directory)
551 self.set('CPPFLAGS', '')
552 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
553 self.set('PKG_CONFIG_PATH',
554 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
555 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
557 if self.version is None:
558 self.image = '%s-%s' % (self.distro, self.bits)
560 self.image = '%s-%s-%s' % (self.distro, self.version, self.bits)
562 def test(self, tree, test):
563 self.append_with_colon('PATH', '%s/bin' % self.directory)
564 self.append_with_colon('LD_LIBRARY_PATH', '%s/lib' % self.directory)
565 super(LinuxTarget, self).test(tree, test)
568 class OSXTarget(Target):
569 def __init__(self, directory=None):
570 super(OSXTarget, self).__init__('osx', directory)
571 self.sdk = config.get('osx_sdk')
572 self.sdk_prefix = config.get('osx_sdk_prefix')
573 self.environment_prefix = config.get('osx_environment_prefix')
575 def command(self, c):
576 command('%s %s' % (self.variables_string(False), c))
579 class OSXSingleTarget(OSXTarget):
580 def __init__(self, bits, directory=None):
581 super(OSXSingleTarget, self).__init__(directory)
589 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
590 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
592 # Environment variables
593 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
594 self.set('CPPFLAGS', '')
595 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
596 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
597 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
598 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
599 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
600 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
602 def package(self, project, checkout, output_dir):
603 raise Error('cannot package non-universal OS X versions')
606 class OSXUniversalTarget(OSXTarget):
607 def __init__(self, directory=None):
608 super(OSXUniversalTarget, self).__init__(directory)
610 def package(self, project, checkout, output_dir):
613 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
614 tree = globals.trees.get(project, checkout, target)
615 tree.build_dependencies()
618 tree = globals.trees.get(project, checkout, self)
619 with TreeDirectory(tree):
620 for p in tree.call('package', tree.version):
621 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
623 class SourceTarget(Target):
624 """Build a source .tar.bz2"""
626 super(SourceTarget, self).__init__('source')
628 def command(self, c):
629 log('host -> %s' % c)
630 command('%s %s' % (self.variables_string(), c))
633 rmtree(self.directory)
635 def package(self, project, checkout, output_dir):
636 tree = globals.trees.get(project, checkout, self)
637 with TreeDirectory(tree):
638 name = read_wscript_variable(os.getcwd(), 'APPNAME')
639 command('./waf dist')
640 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
641 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
643 # @param s Target string:
645 # or ubuntu-version-{32,64}
646 # or debian-version-{32,64}
647 # or centos-version-{32,64}
648 # or fedora-version-{32,64}
649 # or mageia-version-{32,64}
652 # @param debug True to build with debugging symbols (where possible)
653 def target_factory(args):
656 if s.startswith('windows-'):
659 target = WindowsTarget(None, int(x[1]), args.work)
661 target = WindowsTarget(x[1], int(x[2]), args.work)
663 raise Error("Bad Windows target name `%s'")
664 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora-') or s.startswith('mageia-'):
667 raise Error("Bad Linux target name `%s'; must be something like ubuntu-16.04-32 (i.e. distro-version-bits)" % s)
668 target = LinuxTarget(p[0], p[1], int(p[2]), args.work)
669 elif s.startswith('arch-'):
672 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
673 target = LinuxTarget(p[0], None, int(p[1]), args.work)
674 elif s == 'raspbian':
675 target = LinuxTarget(s, None, None, args.work)
676 elif s.startswith('osx-'):
677 target = OSXSingleTarget(int(s.split('-')[1]), args.work)
679 if globals.command == 'build':
680 target = OSXSingleTarget(64, args.work)
682 target = OSXUniversalTarget(args.work)
684 target = SourceTarget()
687 raise Error("Bad target `%s'" % s)
689 target.debug = args.debug
691 if args.environment is not None:
692 for e in args.environment:
693 target.set(e, os.environ[e])
695 if args.mount is not None:
708 """Description of a tree, which is a checkout of a project,
709 possibly built. This class is never exposed to cscripts.
711 name -- name of git repository (without the .git)
712 specifier -- git tag or revision to use
713 target -- target object that we are using
714 version -- version from the wscript (if one is present)
715 git_commit -- git revision that is actually being used
716 built -- true if the tree has been built yet in this run
717 required_by -- name of the tree that requires this one
720 def __init__(self, name, specifier, target, required_by):
722 self.specifier = specifier
725 self.git_commit = None
727 self.required_by = required_by
735 redirect = '>/dev/null'
736 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
737 os.chdir('%s/src/%s' % (target.directory, self.name))
739 spec = self.specifier
743 command('git checkout %s %s %s' % (flags, spec, redirect))
744 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
745 command('git submodule init --quiet')
746 command('git submodule update --quiet')
748 proj = '%s/src/%s' % (target.directory, self.name)
751 exec(open('%s/cscript' % proj).read(), self.cscript)
753 if os.path.exists('%s/wscript' % proj):
754 v = read_wscript_variable(proj, "VERSION");
757 self.version = Version(v)
759 self.version = Version(subprocess.Popen(shlex.split('git -C %s describe --tags --abbrev=0' % proj), stdout=subprocess.PIPE).communicate()[0][1:])
763 def call(self, function, *args):
764 with TreeDirectory(self):
765 return self.cscript[function](self.target, *args)
767 def build_dependencies(self, options=None):
769 if not 'dependencies' in self.cscript:
772 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
773 deps = self.call('dependencies', options)
775 log("Deprecated cscipt dependencies() method with no options parameter")
776 deps = self.call('dependencies')
779 dep = globals.trees.get(d[0], d[1], self.target, self.name)
782 # Make the options to pass in from the option_defaults of the thing
783 # we are building and any options specified by the parent.
784 if 'option_defaults' in dep.cscript:
785 for k, v in dep.cscript['option_defaults']().items():
789 for k, v in d[2].items():
792 msg = 'Building dependency %s %s of %s' % (d[0], d[1], self.name)
794 msg += ' with options %s' % options
797 dep.build_dependencies(options)
800 def build(self, options=None):
804 variables = copy.copy(self.target.variables)
806 if not globals.dry_run:
807 if len(inspect.getargspec(self.cscript['build']).args) == 2:
808 self.call('build', options)
812 self.target.variables = variables
816 # Command-line parser
822 "build": "build project",
823 "package": "package and build project",
824 "release": "release a project using its next version number (changing wscript and tagging)",
825 "pot": "build the project's .pot files",
826 "changelog": "generate a simple HTML changelog",
827 "manual": "build the project's manual",
828 "doxygen": "build the project's Doxygen documentation",
829 "latest": "print out the latest version",
830 "test": "run the project's unit tests",
831 "shell": "build the project then start a shell",
832 "checkout": "check out the project",
833 "revision": "print the head git revision number"
836 one_of = "Command is one of:\n"
838 for k, v in commands.items():
839 one_of += "\t%s\t%s\n" % (k, v)
842 parser = argparse.ArgumentParser()
843 parser.add_argument('command', help=summary)
844 parser.add_argument('-p', '--project', help='project name')
845 parser.add_argument('--minor', help='minor version number bump', action='store_true')
846 parser.add_argument('--micro', help='micro version number bump', action='store_true')
847 parser.add_argument('--latest-major', help='major version to return with latest', type=int)
848 parser.add_argument('--latest-minor', help='minor version to return with latest', type=int)
849 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
850 parser.add_argument('-o', '--output', help='output directory', default='.')
851 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
852 parser.add_argument('-t', '--target', help='target')
853 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
854 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
855 parser.add_argument('-w', '--work', help='override default work directory')
856 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
857 parser.add_argument('--test', help="name of test to run (with `test'), defaults to all")
858 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
859 parser.add_argument('-e', '--environment', help='pass the value of the named environment variable into the build', action='append')
860 parser.add_argument('-m', '--mount', help='mount a given directory in the build environment', action='append')
861 parser.add_argument('--no-version-commit', help="use just tags for versioning, don't modify wscript, ChangeLog etc.", action='store_true')
862 args = parser.parse_args()
864 # Override configured stuff
865 if args.git_prefix is not None:
866 config.set('git_prefix', args.git_prefix)
868 if args.output.find(':') == -1:
869 # This isn't of the form host:path so make it absolute
870 args.output = os.path.abspath(args.output) + '/'
872 if args.output[-1] != ':' and args.output[-1] != '/':
875 # Now, args.output is 'host:', 'host:path/' or 'path/'
877 if args.work is not None:
878 args.work = os.path.abspath(args.work)
880 if args.project is None and args.command != 'shell':
881 raise Error('you must specify -p or --project')
883 globals.quiet = args.quiet
884 globals.command = args.command
885 globals.dry_run = args.dry_run
887 if not globals.command in commands:
888 e = 'command must be one of:\n' + one_of
889 raise Error('command must be one of:\n%s' % one_of)
891 if globals.command == 'build':
892 if args.target is None:
893 raise Error('you must specify -t or --target')
895 target = target_factory(args)
896 target.build(args.project, args.checkout)
900 elif globals.command == 'package':
901 if args.target is None:
902 raise Error('you must specify -t or --target')
904 target = target_factory(args)
906 if target.platform == 'linux':
907 if target.distro != 'arch':
908 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
910 output_dir = os.path.join(args.output, '%s-%d' % (target.distro, target.bits))
912 output_dir = args.output
915 target.package(args.project, args.checkout, output_dir)
920 elif globals.command == 'release':
921 if args.minor is False and args.micro is False:
922 raise Error('you must specify --minor or --micro')
924 target = SourceTarget()
925 tree = globals.trees.get(args.project, args.checkout, target)
927 version = tree.version
934 with TreeDirectory(tree):
935 if not args.no_version_commit:
936 set_version_in_wscript(version)
937 append_version_to_changelog(version)
938 append_version_to_debian_changelog(version)
939 command('git commit -a -m "Bump version"')
941 command('git tag -m "v%s" v%s' % (version, version))
943 if not args.no_version_commit:
945 set_version_in_wscript(version)
946 command('git commit -a -m "Bump version"')
949 command('git push --tags')
953 elif globals.command == 'pot':
954 target = SourceTarget()
955 tree = globals.trees.get(args.project, args.checkout, target)
957 pots = tree.call('make_pot')
959 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
963 elif globals.command == 'changelog':
964 target = SourceTarget()
965 tree = globals.trees.get(args.project, args.checkout, target)
967 with TreeDirectory(tree):
968 text = open('ChangeLog', 'r')
970 html = tempfile.NamedTemporaryFile()
981 if len(l) > 0 and l[0] == "\t":
983 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
986 if last is not None and len(changes) > 0:
987 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
988 print("<ul>", file=html)
990 print("<li>%s" % c, file=html)
991 print("</ul>", file=html)
1001 changes.append(c[2:])
1003 changes[-1] += " " + c
1005 copyfile(html.file, '%schangelog.html' % args.output)
1009 elif globals.command == 'manual':
1010 target = SourceTarget()
1011 tree = globals.trees.get(args.project, args.checkout, target)
1013 outs = tree.call('make_manual')
1015 if os.path.isfile(o):
1016 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
1018 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
1022 elif globals.command == 'doxygen':
1023 target = SourceTarget()
1024 tree = globals.trees.get(args.project, args.checkout, target)
1026 dirs = tree.call('make_doxygen')
1027 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
1031 copytree(d, args.output)
1035 elif globals.command == 'latest':
1036 target = SourceTarget()
1037 tree = globals.trees.get(args.project, args.checkout, target)
1039 with TreeDirectory(tree):
1040 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
1042 while latest is None:
1044 m = re.compile(".*\((.*)\).*").match(t)
1046 tags = m.group(1).split(', ')
1051 if len(t) > 0 and t[0] == 'v':
1053 if (args.latest_major is None or v.major == args.latest_major) and (args.latest_minor is None or v.minor == args.latest_minor):
1059 elif globals.command == 'test':
1060 if args.target is None:
1061 raise Error('you must specify -t or --target')
1065 target = target_factory(args)
1066 tree = globals.trees.get(args.project, args.checkout, target)
1067 with TreeDirectory(tree):
1068 target.test(tree, args.test)
1070 if target is not None and not args.keep:
1074 if target is not None and not args.keep:
1077 elif globals.command == 'shell':
1078 if args.target is None:
1079 raise Error('you must specify -t or --target')
1081 target = target_factory(args)
1082 target.command('bash')
1084 elif globals.command == 'revision':
1086 target = SourceTarget()
1087 tree = globals.trees.get(args.project, args.checkout, target)
1088 with TreeDirectory(tree):
1089 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1092 elif globals.command == 'checkout':
1094 if args.output is None:
1095 raise Error('you must specify -o or --output')
1097 target = SourceTarget()
1098 tree = globals.trees.get(args.project, args.checkout, target)
1099 with TreeDirectory(tree):
1100 shutil.copytree('.', args.output)
1104 raise Error('invalid command %s' % globals.command)
1109 print('cdist: %s' % str(e), file=sys.stderr)