diff --git a/source-builder/sb/build.py b/source-builder/sb/build.py index 4a67ab1..4497478 100644 --- a/source-builder/sb/build.py +++ b/source-builder/sb/build.py @@ -61,8 +61,9 @@ def _notice(opts, text): class script: """Create and manage a shell script.""" - def __init__(self, quiet = True): + def __init__(self, quiet = True, trace = False): self.quiet = quiet + self.trace = trace self.reset() def reset(self): @@ -76,7 +77,9 @@ class script: i = 0 for l in text: i += 1 - log.output('script:%3d: ' % (self.lc + i) + l) + log.output('script:%3d: %s' % (self.lc + i, l)) + if self.trace: + print '%3d: S %s' % (self.lc + i, l) self.lc += len(text) self.body.extend(text) @@ -101,11 +104,12 @@ class script: class build: """Build a package given a config file.""" - def __init__(self, name, _defaults, opts): + def __init__(self, name, create_tar_files, _defaults, opts): self.opts = opts + self.create_tar_files = create_tar_files _notice(opts, 'building: ' + name) self.config = config.file(name, _defaults = _defaults, opts = opts) - self.script = script(quiet = opts.quiet()) + self.script = script(quiet = opts.quiet(), trace = opts.trace()) def _output(self, text): if not self.opts.quiet(): @@ -400,20 +404,21 @@ class build: self.script.append(' '.join(args)) def files(self, package): - self.script.append('echo "==> %files:"') - prefixbase = self.opts.prefixbase() - if prefixbase is None: - prefixbase = '' - inpath = path.join('%{buildroot}', prefixbase) - tardir = path.abspath(self.config.expand('%{_tardir}')) - self.script.append(self.config.expand('if test -d %s; then' % (inpath))) - self.script.append(' mkdir -p %s' % tardir) - self.script.append(self.config.expand(' cd ' + inpath)) - tar = path.join(tardir, package.long_name() + '.tar.bz2') - cmd = self.config.expand(' %{__tar} -cf - . ' + '| %{__bzip2} > ' + tar) - self.script.append(cmd) - self.script.append(self.config.expand(' cd %{_builddir}')) - self.script.append('fi') + if self.create_tar_files: + self.script.append('echo "==> %files:"') + prefixbase = self.opts.prefixbase() + if prefixbase is None: + prefixbase = '' + inpath = path.join('%{buildroot}', prefixbase) + tardir = path.abspath(self.config.expand('%{_tardir}')) + self.script.append(self.config.expand('if test -d %s; then' % (inpath))) + self.script.append(' mkdir -p %s' % tardir) + self.script.append(self.config.expand(' cd ' + inpath)) + tar = path.join(tardir, package.long_name() + '.tar.bz2') + cmd = self.config.expand(' %{__tar} -cf - . ' + '| %{__bzip2} > ' + tar) + self.script.append(cmd) + self.script.append(self.config.expand(' cd %{_builddir}')) + self.script.append('fi') def clean(self, package): self.script.append('echo "==> %clean:"') @@ -495,10 +500,15 @@ def run(args): raise error.general('host build environment is not set up correctly (use --force to proceed)') _notice(opts, 'warning: forcing build with known host setup problems') if opts.get_arg('--list-configs'): - list_configs(opts, _defaults) + configs = get_configs(opts, _defaults) + for p in configs['paths']: + print 'Examining: %s' % (os.path.relpath(p)) + for c in configs['files']: + if c.endswith('.cfg'): + print ' %s' % (c) else: for config_file in opts.config_files(): - b = build(config_file, _defaults = _defaults, opts = opts) + b = build(config_file, True, _defaults = _defaults, opts = opts) b.make() del b except error.general, gerr: diff --git a/source-builder/sb/setbuilder.py b/source-builder/sb/setbuilder.py index b6eb0b5..8890589 100644 --- a/source-builder/sb/setbuilder.py +++ b/source-builder/sb/setbuilder.py @@ -79,22 +79,18 @@ class buildset: return None def copy(self, src, dst): - if os.path.isdir(path.host(src)): - topdir = self.opts.expand('%{_topdir}', self.defaults) - what = '%s -> %s' % \ - (path.host(src[len(topdir) + 1:]), path.host(dst[len(topdir) + 1:])) - if self.opts.trace(): - _notice(self.opts, 'installing: %s' % (what)) - if not self.opts.dry_run(): - try: - files = distutils.dir_util.copy_tree(path.host(src), - path.host(dst)) - for f in files: - self._output(f) - except IOError, err: - raise error.general('installing tree: %s: %s' % (what, str(err))) - except distutils.errors.DistutilsFileError, err: - raise error.general('installing tree: %s' % (str(err))) + if not os.path.isdir(path.host(src)): + raise error.general('copying tree: no source directory: %s' % (path.host(src))) + if not self.opts.dry_run(): + try: + files = distutils.dir_util.copy_tree(path.host(src), + path.host(dst)) + for f in files: + self._output(f) + except IOError, err: + raise error.general('copying tree: %s: %s' % (what, str(err))) + except distutils.errors.DistutilsFileError, err: + raise error.general('copying tree: %s' % (str(err))) def first_package(self, _build): tmproot = path.abspath(_build.config.expand('%{_tmproot}')) @@ -114,16 +110,31 @@ class buildset: return tmproot def every_package(self, _build, tmproot): - self.copy(_build.config.abspath('%{buildroot}'), tmproot) + src = _build.config.abspath('%{buildroot}') + dst = tmproot + if self.opts.get_arg('--bset-tar-file'): + what = '%s -> %s' % \ + (os.path.relpath(path.host(src)), os.path.relpath(path.host(dst))) + if self.opts.trace(): + _notice(self.opts, 'collecting: %s' % (what)) + self.copy(src, dst) + if not self.opts.get_arg('--no-install'): + dst = _build.config.expand('%{_prefix}') + src = path.join(src, dst) + _notice(self.opts, 'installing: %s -> %s' % \ + (self.bset_pkg, os.path.relpath(path.host(dst)))) + self.copy(src, dst) def last_package(self, _build, tmproot): - tar = path.join(_build.config.expand('%{_tardir}'), - _build.config.expand('%s.tar.bz2' % (self.bset_pkg))) - _notice(self.opts, 'tarball: %s' % os.path.relpath(path.host(tar))) - if not self.opts.dry_run(): - cmd = _build.config.expand("'cd " + tmproot + \ - " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'") - _build.run(cmd, shell_opts = '-c', cwd = tmproot) + if self.opts.get_arg('--bset-tar-file'): + tar = path.join(_build.config.expand('%{_tardir}'), + _build.config.expand('%s.tar.bz2' % (self.bset_pkg))) + _notice(self.opts, 'tarball: %s -> %s' % + (os.path.relpath(path.host(tmproot)), os.path.relpath(path.host(tar)))) + if not self.opts.dry_run(): + cmd = _build.config.expand("'cd " + tmproot + \ + " && %{__tar} -cf - . | %{__bzip2} > " + tar + "'") + _build.run(cmd, shell_opts = '-c', cwd = tmproot) def parse(self, bset): @@ -234,7 +245,10 @@ class buildset: bs.build() del bs elif configs[s].endswith('.cfg'): - b = build.build(configs[s], _defaults = self.defaults, opts = self.opts) + b = build.build(configs[s], + self.opts.get_arg('--pkg-tar-files'), + _defaults = self.defaults, + opts = self.opts) if s == 0: tmproot = self.first_package(b) b.make() @@ -268,9 +282,12 @@ class buildset: def run(): import sys try: - optargs = { '--keep-going': 'Do not stop on error.', - '--list-configs': 'List available configurations', - '--list-bsets': 'List available build sets'} + optargs = { '--list-configs': 'List available configurations', + '--list-bsets': 'List available build sets', + '--keep-going': 'Do not stop on error.', + '--no-install': 'Do not install the packages to the prefix.', + '--bset-tar-file': 'Create a build set tar file', + '--pkg-tar-files': 'Create package tar files' } opts, _defaults = defaults.load(sys.argv, optargs) log.default = log.log(opts.logfiles()) _notice(opts, 'Source Builder - Set Builder, v%s' % (version))