3 # Copyright (C) 2012-2018 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('flatpak_state_dir'),
110 Option('parallel', 4) ]
113 f = open('%s/.config/cdist' % os.path.expanduser('~'), 'r')
119 if len(l) > 0 and l[0] == '#':
122 s = l.strip().split()
124 for k in self.options:
130 for o in self.options:
131 if o.key == k and o.value is not None:
136 for o in self.options:
139 raise Error('Required setting %s not found' % k)
143 for o in self.options:
147 if self.get('docker_sudo'):
159 if not globals.quiet:
160 print('\x1b[33m* %s\x1b[0m' % m)
162 def escape_spaces(s):
163 return s.replace(' ', '\\ ')
166 """Escape a host:filename string for use with an scp command"""
168 assert(len(s) == 1 or len(s) == 2)
170 return '%s:"\'%s\'"' % (s[0], s[1])
172 return '\"%s\"' % s[0]
175 return '\"%s\"' % n.substr(' ', '\\ ')
178 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
179 if b.startswith('s3://'):
180 command('s3cmd -P -r put "%s" "%s"' % (a, b))
182 command('scp -r %s %s' % (scp_escape(a), scp_escape(b)))
185 log('copy %s -> %s' % (scp_escape(a), scp_escape(b)))
186 if b.startswith('s3://'):
187 command('s3cmd -P put "%s" "%s"' % (a, b))
193 temp_path = os.path.join(os.path.dirname(path), ".tmp." + os.path.basename(path))
194 command('scp %s %s' % (scp_escape(a), scp_escape(host + ":" + temp_path)))
195 command('ssh %s -- mv "%s" "%s"' % (host, escape_spaces(temp_path), escape_spaces(path)))
197 command('scp %s %s' % (scp_escape(a), scp_escape(b)))
201 Make directories either locally or on a remote host; remotely if
202 d includes a colon, otherwise locally.
204 if d.startswith('s3://'):
205 # No need to create folders on S3
208 if d.find(':') == -1:
216 command('ssh %s -- mkdir -p %s' % (s[0], s[1]))
224 shutil.rmtree(a, ignore_errors=True)
230 raise Error('command %s failed' % c)
232 def command_and_read(c):
234 p = subprocess.Popen(c.split(), stdout=subprocess.PIPE)
235 f = os.fdopen(os.dup(p.stdout.fileno()))
238 def read_wscript_variable(directory, variable):
239 f = open('%s/wscript' % directory, 'r')
246 if len(s) == 3 and s[0] == variable:
253 def set_version_in_wscript(version):
254 f = open('wscript', 'rw')
255 o = open('wscript.tmp', 'w')
262 if len(s) == 3 and s[0] == "VERSION":
263 print("Writing %s" % version)
264 print("VERSION = '%s'" % version, file=o)
266 print(l, file=o, end="")
270 os.rename('wscript.tmp', 'wscript')
272 def append_version_to_changelog(version):
274 f = open('ChangeLog', 'r')
276 log('Could not open ChangeLog')
282 f = open('ChangeLog', 'w')
283 now = datetime.datetime.now()
284 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))
287 def append_version_to_debian_changelog(version):
288 if not os.path.exists('debian'):
289 log('Could not find debian directory')
292 command('dch -b -v %s-1 "New upstream release."' % version)
294 def devel_to_git(git_commit, filename):
295 if git_commit is not None:
296 filename = filename.replace('devel', '-%s' % git_commit)
299 def argument_options(args):
301 if args.option is not None:
302 for o in args.option:
305 raise Error("Bad option `%s'" % o)
316 def __init__(self, tree):
319 self.cwd = os.getcwd()
320 os.chdir('%s/src/%s' % (self.tree.target.directory, self.tree.name))
321 def __exit__(self, type, value, traceback):
329 def __init__(self, s):
332 if s.startswith("'"):
337 if s.endswith('devel'):
341 if s.endswith('pre'):
345 self.major = int(p[0])
346 self.minor = int(p[1])
348 self.micro = int(p[2])
352 def bump_minor(self):
356 def bump_micro(self):
362 def to_release(self):
366 s = '%d.%d.%d' % (self.major, self.minor, self.micro)
376 class Target(object):
378 Class representing the target that we are building for. This is exposed to cscripts,
379 though not all of it is guaranteed 'API'. cscripts may expect:
381 platform: platform string (e.g. 'windows', 'linux', 'osx')
382 parallel: number of parallel jobs to run
383 directory: directory to work in
384 variables: dict of environment variables
385 debug: True to build a debug version, otherwise False
386 set(a, b): set the value of variable 'a' to 'b'
387 unset(a): unset the value of variable 'a'
388 command(c): run the command 'c' in the build environment
392 def __init__(self, platform, directory=None):
394 platform -- platform string (e.g. 'windows', 'linux', 'osx')
395 directory -- directory to work in; if None we will use a temporary directory
396 Temporary directories will be removed after use; specified directories will not.
398 self.platform = platform
399 self.parallel = int(config.get('parallel'))
401 if directory is None:
402 self.directory = tempfile.mkdtemp('', 'tmp', TEMPORARY_DIRECTORY)
405 self.directory = directory
408 # Environment variables that we will use when we call cscripts
411 # True to build our dependencies ourselves; False if this is taken care
412 # of in some other way
413 self.build_dependencies = True
418 def package(self, project, checkout, output_dir, options):
419 tree = globals.trees.get(project, checkout, self)
420 if self.build_dependencies:
421 tree.build_dependencies(options)
423 if len(inspect.getargspec(tree.cscript['package']).args) == 3:
424 packages = tree.call('package', tree.version, options)
426 log("Deprecated cscript package() method with no options parameter")
427 packages = tree.call('package', tree.version)
429 if isinstance(packages, (str, unicode)):
430 copyfile(packages, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, packages))))
433 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
435 def build(self, project, checkout, options):
436 tree = globals.trees.get(project, checkout, self)
437 if self.build_dependencies:
438 tree.build_dependencies(options)
441 def test(self, tree, test, options):
442 """test is the test case to run, or None"""
443 if self.build_dependencies:
444 tree.build_dependencies(options)
446 return tree.call('test', test)
449 self.variables[a] = b
452 del(self.variables[a])
455 return self.variables[a]
457 def append(self, k, v, s):
458 if (not k in self.variables) or len(self.variables[k]) == 0:
459 self.variables[k] = '"%s"' % v
461 e = self.variables[k]
462 if e[0] == '"' and e[-1] == '"':
463 self.variables[k] = '"%s%s%s"' % (e[1:-1], s, v)
465 self.variables[k] = '"%s%s%s"' % (e, s, v)
467 def append_with_space(self, k, v):
468 return self.append(k, v, ' ')
470 def append_with_colon(self, k, v):
471 return self.append(k, v, ':')
473 def variables_string(self, escaped_quotes=False):
475 for k, v in self.variables.items():
477 v = v.replace('"', '\\"')
478 e += '%s=%s ' % (k, v)
483 rmtree(self.directory)
490 class DockerTarget(Target):
491 def __init__(self, platform, directory, version):
492 super(DockerTarget, self).__init__(platform, directory)
493 self.version = version
497 mounts = '-v %s:%s ' % (self.directory, self.directory)
498 for m in self.mounts:
499 mounts += '-v %s:%s ' % (m, m)
500 self.container = command_and_read('%s run -u %s %s -itd %s /bin/bash' % (config.docker(), getpass.getuser(), mounts, self.image)).read().strip()
502 def command(self, cmd):
503 dir = os.path.join(self.directory, os.path.relpath(os.getcwd(), self.directory))
504 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))
507 super(DockerTarget, self).cleanup()
508 command('%s kill %s' % (config.docker(), self.container))
511 self.mounts.append(m)
514 class FlatpakTarget(Target):
515 def __init__(self, project, checkout):
516 super(FlatpakTarget, self).__init__('flatpak')
517 self.build_dependencies = False
518 self.project = project
519 self.checkout = checkout
524 def command(self, cmd):
527 def checkout_dependencies(self):
528 tree = globals.trees.get(self.project, self.checkout, self)
529 return tree.checkout_dependencies()
534 def flatpak_builder(self):
535 b = 'flatpak-builder'
536 if config.has('flatpak_state_dir'):
537 b += ' --state-dir=%s' % config.get('flatpak_state_dir')
541 class WindowsTarget(DockerTarget):
543 This target exposes the following additional API:
545 version: Windows version ('xp' or None)
546 bits: bitness of Windows (32 or 64)
547 name: name of our target e.g. x86_64-w64-mingw32.shared
548 library_prefix: path to Windows libraries
549 tool_path: path to toolchain binaries
551 def __init__(self, version, bits, directory=None):
552 super(WindowsTarget, self).__init__('windows', directory, version)
555 self.tool_path = '%s/usr/bin' % config.get('mxe_prefix')
557 self.name = 'i686-w64-mingw32.shared'
559 self.name = 'x86_64-w64-mingw32.shared'
560 self.library_prefix = '%s/usr/%s' % (config.get('mxe_prefix'), self.name)
562 self.set('PKG_CONFIG_LIBDIR', '%s/lib/pkgconfig' % self.library_prefix)
563 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/bin/pkgconfig' % (self.directory, self.directory))
564 self.set('PATH', '%s/bin:%s:%s' % (self.library_prefix, self.tool_path, os.environ['PATH']))
565 self.set('CC', '%s-gcc' % self.name)
566 self.set('CXX', '%s-g++' % self.name)
567 self.set('LD', '%s-ld' % self.name)
568 self.set('RANLIB', '%s-ranlib' % self.name)
569 self.set('WINRC', '%s-windres' % self.name)
570 cxx = '-I%s/include -I%s/include' % (self.library_prefix, self.directory)
571 link = '-L%s/lib -L%s/lib' % (self.library_prefix, self.directory)
572 self.set('CXXFLAGS', '"%s"' % cxx)
573 self.set('CPPFLAGS', '')
574 self.set('LINKFLAGS', '"%s"' % link)
575 self.set('LDFLAGS', '"%s"' % link)
577 self.image = 'windows'
580 def windows_prefix(self):
581 log('Deprecated property windows_prefix')
582 return self.library_prefix
585 def mingw_prefixes(self):
586 log('Deprecated property mingw_prefixes')
587 return [self.library_prefix]
590 def mingw_path(self):
591 log('Deprecated property mingw_path')
592 return self.tool_path
595 def mingw_name(self):
596 log('Deprecated property mingw_name')
600 class LinuxTarget(DockerTarget):
602 Build for Linux in a docker container.
603 This target exposes the following additional API:
605 distro: distribution ('debian', 'ubuntu', 'centos' or 'fedora')
606 version: distribution version (e.g. '12.04', '8', '6.5')
607 bits: bitness of the distribution (32 or 64)
608 detail: None or 'appimage' if we are building for appimage
611 def __init__(self, distro, version, bits, directory=None):
612 super(LinuxTarget, self).__init__('linux', directory, version)
617 self.set('CXXFLAGS', '-I%s/include' % self.directory)
618 self.set('CPPFLAGS', '')
619 self.set('LINKFLAGS', '-L%s/lib' % self.directory)
620 self.set('PKG_CONFIG_PATH',
621 '%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (self.directory, self.directory))
622 self.set('PATH', '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin')
624 if self.version is None:
625 self.image = '%s-%s' % (self.distro, self.bits)
627 self.image = '%s-%s-%s' % (self.distro, self.version, self.bits)
629 def test(self, tree, test, options):
630 self.append_with_colon('PATH', '%s/bin' % self.directory)
631 self.append_with_colon('LD_LIBRARY_PATH', '%s/lib' % self.directory)
632 super(LinuxTarget, self).test(tree, test, options)
635 class AppImageTarget(LinuxTarget):
636 def __init__(self, work):
637 super(AppImageTarget, self).__init__('ubuntu', '18.04', 64, work)
638 self.detail = 'appimage'
641 class OSXTarget(Target):
642 def __init__(self, directory=None):
643 super(OSXTarget, self).__init__('osx', directory)
644 self.sdk = config.get('osx_sdk')
645 self.sdk_prefix = config.get('osx_sdk_prefix')
646 self.environment_prefix = config.get('osx_environment_prefix')
648 def command(self, c):
649 command('%s %s' % (self.variables_string(False), c))
652 class OSXSingleTarget(OSXTarget):
653 def __init__(self, bits, directory=None):
654 super(OSXSingleTarget, self).__init__(directory)
662 flags = '-isysroot %s/MacOSX%s.sdk -arch %s' % (self.sdk_prefix, self.sdk, arch)
663 enviro = '%s/%d' % (config.get('osx_environment_prefix'), bits)
665 # Environment variables
666 self.set('CFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
667 self.set('CPPFLAGS', '')
668 self.set('CXXFLAGS', '"-I%s/include -I%s/include %s"' % (self.directory, enviro, flags))
669 self.set('LDFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
670 self.set('LINKFLAGS', '"-L%s/lib -L%s/lib %s"' % (self.directory, enviro, flags))
671 self.set('PKG_CONFIG_PATH', '%s/lib/pkgconfig:%s/lib/pkgconfig:/usr/lib/pkgconfig' % (self.directory, enviro))
672 self.set('PATH', '$PATH:/usr/bin:/sbin:/usr/local/bin:%s/bin' % enviro)
673 self.set('MACOSX_DEPLOYMENT_TARGET', config.get('osx_sdk'))
675 def package(self, project, checkout, output_dir, options):
676 raise Error('cannot package non-universal OS X versions')
679 class OSXUniversalTarget(OSXTarget):
680 def __init__(self, directory=None):
681 super(OSXUniversalTarget, self).__init__(directory)
683 def package(self, project, checkout, output_dir, options):
686 target = OSXSingleTarget(b, os.path.join(self.directory, '%d' % b))
687 tree = globals.trees.get(project, checkout, target)
688 tree.build_dependencies(options)
691 tree = globals.trees.get(project, checkout, self)
692 with TreeDirectory(tree):
693 if len(inspect.getargspec(tree.cscript['package']).args) == 3:
694 packages = tree.call('package', tree.version, options)
696 log("Deprecated cscript package() method with no options parameter")
697 packages = tree.call('package', tree.version)
699 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
701 class SourceTarget(Target):
702 """Build a source .tar.bz2"""
704 super(SourceTarget, self).__init__('source')
706 def command(self, c):
707 log('host -> %s' % c)
708 command('%s %s' % (self.variables_string(), c))
711 rmtree(self.directory)
713 def package(self, project, checkout, output_dir, options):
714 tree = globals.trees.get(project, checkout, self)
715 with TreeDirectory(tree):
716 name = read_wscript_variable(os.getcwd(), 'APPNAME')
717 command('./waf dist')
718 p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
719 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
721 # @param s Target string:
723 # or ubuntu-version-{32,64}
724 # or debian-version-{32,64}
725 # or centos-version-{32,64}
726 # or fedora-version-{32,64}
727 # or mageia-version-{32,64}
732 # @param debug True to build with debugging symbols (where possible)
733 def target_factory(args):
736 if s.startswith('windows-'):
739 target = WindowsTarget(None, int(x[1]), args.work)
741 target = WindowsTarget(x[1], int(x[2]), args.work)
743 raise Error("Bad Windows target name `%s'")
744 elif s.startswith('ubuntu-') or s.startswith('debian-') or s.startswith('centos-') or s.startswith('fedora-') or s.startswith('mageia-'):
747 raise Error("Bad Linux target name `%s'; must be something like ubuntu-16.04-32 (i.e. distro-version-bits)" % s)
748 target = LinuxTarget(p[0], p[1], int(p[2]), args.work)
749 elif s.startswith('arch-'):
752 raise Error("Bad Arch target name `%s'; must be arch-32 or arch-64")
753 target = LinuxTarget(p[0], None, int(p[1]), args.work)
754 elif s == 'raspbian':
755 target = LinuxTarget(s, None, None, args.work)
756 elif s.startswith('osx-'):
757 target = OSXSingleTarget(int(s.split('-')[1]), args.work)
759 if globals.command == 'build':
760 target = OSXSingleTarget(64, args.work)
762 target = OSXUniversalTarget(args.work)
764 target = SourceTarget()
766 target = FlatpakTarget(args.project, args.checkout)
767 elif s == 'appimage':
768 target = AppImageTarget(args.work)
771 raise Error("Bad target `%s'" % s)
773 target.debug = args.debug
775 if args.environment is not None:
776 for e in args.environment:
777 target.set(e, os.environ[e])
779 if args.mount is not None:
792 """Description of a tree, which is a checkout of a project,
793 possibly built. This class is never exposed to cscripts.
795 name -- name of git repository (without the .git)
796 specifier -- git tag or revision to use
797 target -- target object that we are using
798 version -- version from the wscript (if one is present)
799 git_commit -- git revision that is actually being used
800 built -- true if the tree has been built yet in this run
801 required_by -- name of the tree that requires this one
804 def __init__(self, name, specifier, target, required_by):
806 self.specifier = specifier
809 self.git_commit = None
811 self.required_by = required_by
819 redirect = '>/dev/null'
820 command('git clone %s %s/%s.git %s/src/%s' % (flags, config.get('git_prefix'), self.name, target.directory, self.name))
821 os.chdir('%s/src/%s' % (target.directory, self.name))
823 spec = self.specifier
827 command('git checkout %s %s %s' % (flags, spec, redirect))
828 self.git_commit = command_and_read('git rev-parse --short=7 HEAD').readline().strip()
829 command('git submodule init --quiet')
830 command('git submodule update --quiet')
832 proj = '%s/src/%s' % (target.directory, self.name)
835 exec(open('%s/cscript' % proj).read(), self.cscript)
837 if os.path.exists('%s/wscript' % proj):
838 v = read_wscript_variable(proj, "VERSION");
841 self.version = Version(v)
843 self.version = Version(subprocess.Popen(shlex.split('git -C %s describe --tags --abbrev=0' % proj), stdout=subprocess.PIPE).communicate()[0][1:])
847 def call(self, function, *args):
848 with TreeDirectory(self):
849 return self.cscript[function](self.target, *args)
851 def add_defaults(self, options):
852 """Add the defaults from this into a dict options"""
853 if 'option_defaults' in self.cscript:
854 for k, v in self.cscript['option_defaults']().items():
858 def dependencies(self, options):
859 if not 'dependencies' in self.cscript:
862 if len(inspect.getargspec(self.cscript['dependencies']).args) == 2:
863 deps = self.call('dependencies', options)
865 log("Deprecated cscript dependencies() method with no options parameter")
866 deps = self.call('dependencies')
869 dep = globals.trees.get(d[0], d[1], self.target, self.name)
871 # Start with the options passed in
872 dep_options = copy.copy(options)
873 # Add things specified by the parent
875 for k, v in d[2].items():
876 if not k in dep_options:
878 # Then fill in the dependency's defaults
879 dep.add_defaults(dep_options)
881 for i in dep.dependencies(dep_options):
883 yield (dep, dep_options)
885 def checkout_dependencies(self, options={}):
886 for i in self.dependencies(options):
889 def build_dependencies(self, options):
890 for i in self.dependencies(options):
893 def build(self, options):
897 variables = copy.copy(self.target.variables)
899 # Start with the options passed in
900 options = copy.copy(options)
901 # Fill in the defaults
902 self.add_defaults(options)
904 if not globals.dry_run:
905 if len(inspect.getargspec(self.cscript['build']).args) == 2:
906 self.call('build', options)
910 self.target.variables = variables
914 # Command-line parser
920 "build": "build project",
921 "package": "package and build project",
922 "release": "release a project using its next version number (changing wscript and tagging)",
923 "pot": "build the project's .pot files",
924 "changelog": "generate a simple HTML changelog",
925 "manual": "build the project's manual",
926 "doxygen": "build the project's Doxygen documentation",
927 "latest": "print out the latest version",
928 "test": "run the project's unit tests",
929 "shell": "build the project then start a shell",
930 "checkout": "check out the project",
931 "revision": "print the head git revision number"
934 one_of = "Command is one of:\n"
936 for k, v in commands.items():
937 one_of += "\t%s\t%s\n" % (k, v)
940 parser = argparse.ArgumentParser()
941 parser.add_argument('command', help=summary)
942 parser.add_argument('-p', '--project', help='project name')
943 parser.add_argument('--minor', help='minor version number bump', action='store_true')
944 parser.add_argument('--micro', help='micro version number bump', action='store_true')
945 parser.add_argument('--latest-major', help='major version to return with latest', type=int)
946 parser.add_argument('--latest-minor', help='minor version to return with latest', type=int)
947 parser.add_argument('-c', '--checkout', help='string to pass to git for checkout')
948 parser.add_argument('-o', '--output', help='output directory', default='.')
949 parser.add_argument('-q', '--quiet', help='be quiet', action='store_true')
950 parser.add_argument('-t', '--target', help='target')
951 parser.add_argument('-k', '--keep', help='keep working tree', action='store_true')
952 parser.add_argument('--debug', help='build with debugging symbols where possible', action='store_true')
953 parser.add_argument('-w', '--work', help='override default work directory')
954 parser.add_argument('-g', '--git-prefix', help='override configured git prefix')
955 parser.add_argument('--test', help="name of test to run (with `test'), defaults to all")
956 parser.add_argument('-n', '--dry-run', help='run the process without building anything', action='store_true')
957 parser.add_argument('-e', '--environment', help='pass the value of the named environment variable into the build', action='append')
958 parser.add_argument('-m', '--mount', help='mount a given directory in the build environment', action='append')
959 parser.add_argument('--no-version-commit', help="use just tags for versioning, don't modify wscript, ChangeLog etc.", action='store_true')
960 parser.add_argument('--option', help='set an option for the build (use --option key:value)', action='append')
961 args = parser.parse_args()
963 # Override configured stuff
964 if args.git_prefix is not None:
965 config.set('git_prefix', args.git_prefix)
967 if args.output.find(':') == -1:
968 # This isn't of the form host:path so make it absolute
969 args.output = os.path.abspath(args.output) + '/'
971 if args.output[-1] != ':' and args.output[-1] != '/':
974 # Now, args.output is 'host:', 'host:path/' or 'path/'
976 if args.work is not None:
977 args.work = os.path.abspath(args.work)
979 if args.project is None and args.command != 'shell':
980 raise Error('you must specify -p or --project')
982 globals.quiet = args.quiet
983 globals.command = args.command
984 globals.dry_run = args.dry_run
986 if not globals.command in commands:
987 e = 'command must be one of:\n' + one_of
988 raise Error('command must be one of:\n%s' % one_of)
990 if globals.command == 'build':
991 if args.target is None:
992 raise Error('you must specify -t or --target')
994 target = target_factory(args)
995 target.build(args.project, args.checkout, argument_options(args))
999 elif globals.command == 'package':
1000 if args.target is None:
1001 raise Error('you must specify -t or --target')
1003 target = target_factory(args)
1005 if target.platform == 'linux':
1006 if target.distro != 'arch':
1007 output_dir = os.path.join(args.output, '%s-%s-%d' % (target.distro, target.version, target.bits))
1009 output_dir = os.path.join(args.output, '%s-%d' % (target.distro, target.bits))
1011 output_dir = args.output
1013 makedirs(output_dir)
1015 # Start with the options passed on the command line
1016 options = copy.copy(argument_options(args))
1017 # Fill in the defaults
1018 tree = globals.trees.get(args.project, args.checkout, target)
1019 tree.add_defaults(options)
1021 target.package(args.project, args.checkout, output_dir, options)
1026 elif globals.command == 'release':
1027 if args.minor is False and args.micro is False:
1028 raise Error('you must specify --minor or --micro')
1030 target = SourceTarget()
1031 tree = globals.trees.get(args.project, args.checkout, target)
1033 version = tree.version
1034 version.to_release()
1036 version.bump_minor()
1038 version.bump_micro()
1040 with TreeDirectory(tree):
1041 if not args.no_version_commit:
1042 set_version_in_wscript(version)
1043 append_version_to_changelog(version)
1044 append_version_to_debian_changelog(version)
1045 command('git commit -a -m "Bump version"')
1047 command('git tag -m "v%s" v%s' % (version, version))
1049 if not args.no_version_commit:
1051 set_version_in_wscript(version)
1052 command('git commit -a -m "Bump version"')
1055 command('git push --tags')
1059 elif globals.command == 'pot':
1060 target = SourceTarget()
1061 tree = globals.trees.get(args.project, args.checkout, target)
1063 pots = tree.call('make_pot')
1065 copyfile(p, '%s%s' % (args.output, os.path.basename(p)))
1069 elif globals.command == 'changelog':
1070 target = SourceTarget()
1071 tree = globals.trees.get(args.project, args.checkout, target)
1073 with TreeDirectory(tree):
1074 text = open('ChangeLog', 'r')
1076 html = tempfile.NamedTemporaryFile()
1087 if len(l) > 0 and l[0] == "\t":
1089 if len(s) == 4 and s[1] == "Version" and s[3] == "released.":
1092 if last is not None and len(changes) > 0:
1093 print("<h2>Changes between version %s and %s</h2>" % (s[2], last), file=html)
1094 print("<ul>", file=html)
1096 print("<li>%s" % c, file=html)
1097 print("</ul>", file=html)
1107 changes.append(c[2:])
1109 changes[-1] += " " + c
1111 copyfile(html.file, '%schangelog.html' % args.output)
1115 elif globals.command == 'manual':
1116 target = SourceTarget()
1117 tree = globals.trees.get(args.project, args.checkout, target)
1119 outs = tree.call('make_manual')
1121 if os.path.isfile(o):
1122 copyfile(o, '%s%s' % (args.output, os.path.basename(o)))
1124 copytree(o, '%s%s' % (args.output, os.path.basename(o)))
1128 elif globals.command == 'doxygen':
1129 target = SourceTarget()
1130 tree = globals.trees.get(args.project, args.checkout, target)
1132 dirs = tree.call('make_doxygen')
1133 if hasattr(dirs, 'strip') or (not hasattr(dirs, '__getitem__') and not hasattr(dirs, '__iter__')):
1137 copytree(d, args.output)
1141 elif globals.command == 'latest':
1142 target = SourceTarget()
1143 tree = globals.trees.get(args.project, args.checkout, target)
1145 with TreeDirectory(tree):
1146 f = command_and_read('git log --tags --simplify-by-decoration --pretty="%d"')
1148 while latest is None:
1150 m = re.compile(".*\((.*)\).*").match(t)
1152 tags = m.group(1).split(', ')
1157 if len(t) > 0 and t[0] == 'v':
1159 if (args.latest_major is None or v.major == args.latest_major) and (args.latest_minor is None or v.minor == args.latest_minor):
1165 elif globals.command == 'test':
1166 if args.target is None:
1167 raise Error('you must specify -t or --target')
1171 target = target_factory(args)
1172 tree = globals.trees.get(args.project, args.checkout, target)
1173 with TreeDirectory(tree):
1174 target.test(tree, args.test, argument_options(args))
1176 if target is not None and not args.keep:
1180 if target is not None and not args.keep:
1183 elif globals.command == 'shell':
1184 if args.target is None:
1185 raise Error('you must specify -t or --target')
1187 target = target_factory(args)
1188 target.command('bash')
1190 elif globals.command == 'revision':
1192 target = SourceTarget()
1193 tree = globals.trees.get(args.project, args.checkout, target)
1194 with TreeDirectory(tree):
1195 print(command_and_read('git rev-parse HEAD').readline().strip()[:7])
1198 elif globals.command == 'checkout':
1200 if args.output is None:
1201 raise Error('you must specify -o or --output')
1203 target = SourceTarget()
1204 tree = globals.trees.get(args.project, args.checkout, target)
1205 with TreeDirectory(tree):
1206 shutil.copytree('.', args.output)
1210 raise Error('invalid command %s' % globals.command)
1215 print('cdist: %s' % str(e), file=sys.stderr)