diff options
Diffstat (limited to 'source-builder/sb/setbuilder.py')
-rw-r--r-- | source-builder/sb/setbuilder.py | 147 |
1 files changed, 94 insertions, 53 deletions
diff --git a/source-builder/sb/setbuilder.py b/source-builder/sb/setbuilder.py index b0e2b23..46d7fe7 100644 --- a/source-builder/sb/setbuilder.py +++ b/source-builder/sb/setbuilder.py @@ -30,11 +30,14 @@ import glob import operator import os import sys +import tarfile + import textwrap try: from . import build from . import check + from . import config from . import error from . import log from . import mailer @@ -223,6 +226,9 @@ class buildset: def installing(self): return self.install_mode() == 'installing' + def installable(self): + return not self.opts.no_install() and self.installing() + def staging(self): return not self.installing() @@ -259,21 +265,31 @@ class buildset: self.root_copy(_build.config.expand('%{buildroot}'), _build.config.expand('%{_tmproot}')) - def bset_tar(self, _build): - tardir = _build.config.expand('%{_tardir}') - if (self.opts.get_arg('--bset-tar-file') or self.opts.canadian_cross()) \ - and not _build.macros.get('%{_disable_packaging}'): + def bset_tar(self, stagingroot): + if self.opts.get_arg('--bset-tar-file') or self.opts.canadian_cross(): + # Use a config to expand the macros because it supports all + # expansions, ie %{_cwd} + cfg = config.file(self.bset, self.opts, self.macros, load=False) + prefix = cfg.expand('%{_prefix}') + tardir = cfg.expand('%{_tardir}') path.mkdir(tardir) - tar = path.join(tardir, - _build.config.expand('%s.tar.bz2' % \ - (_build.main_package().name()))) - log.notice('tarball: %s' % (os.path.relpath(path.host(tar)))) + tarname = path.join(tardir, + path.basename('%s.tar.bz2' % (self.bset))) + log.notice('tarfile: %s' % (os.path.relpath(path.host(tarname)))) if not self.opts.dry_run(): - tmproot = _build.config.expand('%{_tmproot}') - cmd = _build.config.expand('"cd ' + tmproot + \ - ' && %{__tar} -cf - . | %{__bzip2} > ' + \ - tar + '"') - _build.run(cmd, shell_opts = '-c', cwd = tmproot) + tar = None + try: + tar = tarfile.open(tarname, 'w:bz2') + for filedir in sorted(path.listdir(stagingroot)): + src = path.join(stagingroot, filedir) + dst = path.join(prefix, filedir) + log.trace('tar: %s -> %s' % (src, dst)) + tar.add(src, dst) + except OSError as oe: + raise error.general('tarfile: %s: %s' % (self.bset, oe)) + finally: + if tar is not None: + tar.close() def parse(self, bset): @@ -284,6 +300,14 @@ class buildset: line = line[1:b] return line.strip() + def _clean_and_pack(line, last_line): + leading_ws = ' ' if len(line) > 0 and line[0].isspace() else '' + line = _clean(line) + if len(last_line) > 0: + line = last_line + leading_ws + line + return line + + bset = macro_expand(self.macros, bset) bsetname = bset if not path.exists(bsetname): @@ -305,25 +329,37 @@ class buildset: try: lc = 0 + ll = '' for l in bset: lc += 1 - l = _clean(l) + l = _clean_and_pack(l, ll) if len(l) == 0: continue + if l[-1] == '\\': + ll = l[0:-1] + continue + ll = '' log.trace('_bset: : %s: %03d: %s' % (self.bset, lc, l)) ls = l.split() if ls[0][-1] == ':' and ls[0][:-1] == 'package': self.bset_pkg = ls[1].strip() self.macros['package'] = self.bset_pkg - elif ls[0][0] == '%': + elif ls[0][0] == '%' and (len(ls[0]) > 1 and ls[0][1] != '{'): def err(msg): raise error.general('%s:%d: %s' % (self.bset, lc, msg)) - if ls[0] == '%define': + if ls[0] == '%define' or ls[0] == '%defineifnot' : + name = ls[1].strip() + value = None if len(ls) > 2: - self.macros.define(ls[1].strip(), - ' '.join([f.strip() for f in ls[2:]])) - else: - self.macros.define(ls[1].strip()) + value = ' '.join([f.strip() for f in ls[2:]]) + if ls[0] == '%defineifnot': + if self.macros.defined(name): + name = None + if name is not None: + if value is not None: + self.macros.define(name, value) + else: + self.macros.define(name) elif ls[0] == '%undefine': if len(ls) > 2: raise error.general('%s:%d: %undefine requires ' \ @@ -336,7 +372,7 @@ class buildset: elif ls[0] == '%hash': sources.hash(ls[1:], self.macros, err) else: - l = l.strip() + l = macro_expand(self.macros, l.strip()) c = build.find_config(l, self.configs) if c is None: raise error.general('%s:%d: cannot find file: %s' % (self.bset, @@ -397,19 +433,11 @@ class buildset: interrupted = False # - # If this is the outter most buildset it's files are installed. Nested - # build sets staged their installed file. The staged files are install - # when the outtter most build finishes. - # - if nesting_count != 1: - if self.installing(): - self.macros['install_mode'] = 'staging' - - # - # Only the outter build set can have staging to install. Get the staging - # root via the config because it could require a valid config. + # If installing switch to staging. Not sure if this is still + # needed. # - have_staging = False + if nesting_count > 1 and self.installing(): + self.macros['install_mode'] = 'staging' try: configs = self.load() @@ -417,7 +445,7 @@ class buildset: log.trace('_bset: %2d: %s: configs: %s' % (nesting_count, self.bset, ', '.join(configs))) - if nesting_count == 1 and len(configs) > 1: + if nesting_count == 1: # # Prepend staging areas, bin directory to the # path. Lets the later package depend on the earlier @@ -449,8 +477,6 @@ class buildset: '=' * (74 - len(configs[s])))) bs = buildset(configs[s], self.configs, opts, macros) bs.build(deps, nesting_count, mail) - if self.installing(): - have_staging = True del bs elif configs[s].endswith('.cfg'): if mail: @@ -480,8 +506,6 @@ class buildset: copy.copy(self.macros), format = 'xml', mail = mail) - if s == len(configs) - 1 and not have_errors: - self.bset_tar(b) else: deps += b.config.includes() builds += [b] @@ -514,23 +538,22 @@ class buildset: # # Installing or staging ... # - log.trace('_bset: %2d: %s: deps:%r no-install:%r' % \ + log.trace('_bset: %2d: mode: %s: deps:%r no-install:%r' % \ (nesting_count, self.install_mode(), deps is None, self.opts.no_install())) - log.trace('_bset: %2d: %s: builds: %s' % \ + log.trace('_bset: %2d: mode: %s: builds: %s' % \ (nesting_count, self.install_mode(), ', '.join([b.name() for b in builds]))) - if deps is None and not self.opts.no_install() and not have_errors: + if deps is None and not have_errors: for b in builds: - log.trace('_bset: : %s: %r' % (self.install_mode(), - b.installable())) + log.trace('_bset: : %s: installable=%r build-installable=%r' % \ + (self.install_mode(), self.installable(), b.installable())) if b.installable(): prefix = b.config.expand('%{_prefix}') buildroot = path.join(b.config.expand('%{buildroot}'), prefix) - if self.staging(): - prefix = b.config.expand('%{stagingroot}') - self.install(self.install_mode(), b.name(), buildroot, prefix) - + self.install('staging', b.name(), buildroot, b.config.expand('%{stagingroot}')) + if self.installable(): + self.install('installing', b.name(), buildroot, prefix) # # Sizes ... # @@ -584,16 +607,20 @@ class buildset: del b # - # If builds have been staged install into the finaly prefix. + # If builds have been staged install into the final prefix. # - if have_staging and not self.opts.no_install() and not have_errors: + if self.installing() and not have_errors: stagingroot = macro_expand(self.macros, '%{stagingroot}') have_stagingroot = path.exists(stagingroot) - log.trace('_bset: %2d: install staging, present: %s' % \ - (nesting_count, have_stagingroot)) + do_install = not self.opts.no_install() + if do_install: + log.trace('_bset: %2d: install staging, present: %s' % \ + (nesting_count, have_stagingroot)) if have_stagingroot: prefix = macro_expand(self.macros, '%{_prefix}') - self.install(self.install_mode(), self.bset, stagingroot, prefix) + if do_install: + self.install(self.install_mode(), self.bset, stagingroot, prefix) + self.bset_tar(stagingroot) staging_size = path.get_size(stagingroot) if not self.opts.no_clean() or self.opts.always_clean(): log.notice('clean staging: %s' % (self.bset)) @@ -673,6 +700,16 @@ def list_bset_cfg_files(opts, configs): return True return False +def list_host(opts): + if opts.get_arg('--list-host'): + print('Host operating system information:') + print('Operating system: %s' % macro_expand(opts.defaults, '%{_os}')) + print('Number of processors: %s' % macro_expand(opts.defaults, '%{_ncpus}')) + print('Build architecture: %s' % macro_expand(opts.defaults, '%{_host_arch}')) + print('Host triplet: %s' % macro_expand(opts.defaults, '%{_host}')) + return True + return False + def run(): import sys ec = 0 @@ -683,6 +720,7 @@ def run(): '--list-bsets': 'List available build sets', '--list-configs': 'List available configuration files.', '--list-deps': 'List the dependent files.', + '--list-host': 'List host information and the host triplet.', '--bset-tar-file': 'Create a build set tar file', '--pkg-tar-files': 'Create package tar files', '--no-report': 'Do not create a package report.', @@ -695,6 +733,8 @@ def run(): 'log' : '', 'reports': [], 'failure': None } + # Request this now to generate any errors. + smtp_host = mail['mail'].smtp_host() to_addr = opts.get_arg('--mail-to') if to_addr is not None: mail['to'] = to_addr[1] @@ -718,7 +758,8 @@ def run(): deps = [] else: deps = None - if not list_bset_cfg_files(opts, configs): + + if not list_bset_cfg_files(opts, configs) and not list_host(opts): prefix = macro_expand(opts.defaults, '%{_prefix}') if opts.canadian_cross(): opts.disable_install() |