def mail_send(self, mail):
     if True:  #not self.opts.dry_run():
         mail_subject = '%s on %s' % (self.bset,
                                      self.macros.expand('%{_host}'))
         if mail['failure'] is not None:
             mail_subject = 'FAILED %s (%s)' % (mail_subject,
                                                mail['failure'])
         else:
             mail_subject = 'PASSED %s' % (mail_subject)
         mail_subject = 'Build %s: %s' % (reports.platform(mode='system'),
                                          mail_subject)
         body = mail['log']
         body += (os.linesep * 2).join(mail['reports'])
         mail['mail'].send(mail['to'], mail_subject, body)
示例#2
0
def run():
    import sys
    ec = 0
    setbuilder_error = False
    mail = None
    try:
        optargs = {
            '--list-configs': 'List available configurations',
            '--list-bsets': 'List available build sets',
            '--list-configs': 'List available configuration files.',
            '--list-deps': 'List the dependent files.',
            '--bset-tar-file': 'Create a build set tar file',
            '--pkg-tar-files': 'Create package tar files',
            '--no-report': 'Do not create a package report.',
            '--report-format': 'The report format (text, html, asciidoc).'
        }
        mailer.append_options(optargs)
        opts = options.load(sys.argv, optargs)
        if opts.get_arg('--mail'):
            mail = {'mail': mailer.mail(opts), 'output': log_capture()}
            to_addr = opts.get_arg('--mail-to')
            if to_addr is not None:
                mail['to'] = to_addr[1]
            else:
                mail['to'] = opts.defaults.expand('%{_mail_tools_to}')
            mail['from'] = mail['mail'].from_address()
        log.notice('RTEMS Source Builder - Set Builder, %s' % (version.str()))
        opts.log_info()
        if not check.host_setup(opts):
            raise error.general(
                'host build environment is not set up correctly')
        if mail:
            mail['header'] = os.linesep.join(mail['output'].get()) + os.linesep
            mail['header'] += os.linesep
            mail['header'] += 'Host: ' + reports.platform(
                'compact') + os.linesep
            indent = '       '
            for l in textwrap.wrap(reports.platform('extended'),
                                   width=80 - len(indent)):
                mail['header'] += indent + l + os.linesep
        configs = build.get_configs(opts)
        if opts.get_arg('--list-deps'):
            deps = []
        else:
            deps = None
        if not list_bset_cfg_files(opts, configs):
            prefix = opts.defaults.expand('%{_prefix}')
            if opts.canadian_cross():
                opts.disable_install()

            if not opts.dry_run() and \
               not opts.canadian_cross() and \
               not opts.no_install() and \
               not path.ispathwritable(prefix):
                raise error.general('prefix is not writable: %s' %
                                    (path.host(prefix)))

            for bset in opts.params():
                setbuilder_error = True
                b = buildset(bset, configs, opts)
                b.build(deps, mail=mail)
                b = None
                setbuilder_error = False

        if deps is not None:
            c = 0
            for d in sorted(set(deps)):
                c += 1
                print('dep[%d]: %s' % (c, d))
    except error.general as gerr:
        if not setbuilder_error:
            log.stderr(str(gerr))
        log.stderr('Build FAILED')
        ec = 1
    except error.internal as ierr:
        if not setbuilder_error:
            log.stderr(str(ierr))
        log.stderr('Internal Build FAILED')
        ec = 1
    except error.exit as eerr:
        pass
    except KeyboardInterrupt:
        log.notice('abort: user terminated')
        ec = 1
    except:
        raise
        log.notice('abort: unknown error')
        ec = 1
    sys.exit(ec)
示例#3
0
    def build(self, deps=None, nesting_count=0, mail=None):

        build_error = False

        nesting_count += 1

        if mail:
            mail['output'].clear()

        log.trace('_bset: %s: make' % (self.bset))
        log.notice('Build Set: %s' % (self.bset))

        mail_subject = '%s on %s' % (self.bset, self.macros.expand('%{_host}'))

        current_path = os.environ['PATH']

        start = datetime.datetime.now()

        mail_report = False
        have_errors = False

        if mail:
            mail['output'].clear()

        try:
            configs = self.load()

            log.trace('_bset: %s: configs: %s' %
                      (self.bset, ','.join(configs)))

            sizes_valid = False
            builds = []
            for s in range(0, len(configs)):
                b = None
                try:
                    #
                    # Each section of the build set gets a separate set of
                    # macros so we do not contaminate one configuration with
                    # another.
                    #
                    opts = copy.copy(self.opts)
                    macros = copy.copy(self.macros)
                    if configs[s].endswith('.bset'):
                        log.trace('_bset: == %2d %s' %
                                  (nesting_count + 1, '=' * 75))
                        bs = buildset(configs[s], self.configs, opts, macros)
                        bs.build(deps, nesting_count, mail)
                        del bs
                    elif configs[s].endswith('.cfg'):
                        if mail:
                            mail_report = True
                        log.trace('_bset: -- %2d %s' %
                                  (nesting_count + 1, '-' * 75))
                        try:
                            b = build.build(
                                configs[s],
                                self.opts.get_arg('--pkg-tar-files'), opts,
                                macros)
                        except:
                            build_error = True
                            raise
                        if b.macros.get('%{_disable_reporting}'):
                            mail_report = False
                        if deps is None:
                            self.build_package(configs[s], b)
                            self.report(configs[s],
                                        b,
                                        copy.copy(self.opts),
                                        copy.copy(self.macros),
                                        mail=mail)
                            # Always produce an XML report.
                            self.report(configs[s],
                                        b,
                                        copy.copy(self.opts),
                                        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]
                        #
                        # Dump post build macros.
                        #
                        log.trace('_bset: macros post-build')
                        log.trace(str(macros))
                    else:
                        raise error.general('invalid config type: %s' %
                                            (configs[s]))
                except error.general as gerr:
                    have_errors = True
                    if b is not None:
                        if self.build_failure is None:
                            self.build_failure = b.name()
                        self.write_mail_header('')
                        self.write_mail_header('= ' * 40)
                        self.write_mail_header('Build FAILED: %s' % (b.name()))
                        self.write_mail_header('- ' * 40)
                        self.write_mail_header(str(log.default))
                        self.write_mail_header('- ' * 40)
                        if self.opts.keep_going():
                            log.notice(str(gerr))
                            if self.opts.always_clean():
                                builds += [b]
                        else:
                            raise
                    else:
                        raise
            #
            # Installing ...
            #
            log.trace('_bset: installing: deps:%r no-install:%r' % \
                      (deps is None, self.opts.no_install()))
            if deps is None \
               and not self.opts.no_install() \
               and not have_errors:
                for b in builds:
                    log.trace('_bset: installing: %r' % b.installable())
                    if b.installable():
                        self.install(b.name(), b.config.expand('%{buildroot}'),
                                     b.config.expand('%{_prefix}'))
            #
            # Sizes ...
            #
            if len(builds) > 1:
                size_build = 0
                size_installed = 0
                size_build_max = 0
                for b in builds:
                    s = b.get_build_size()
                    size_build += s
                    if s > size_build_max:
                        size_build_max = s
                    size_installed += b.get_installed_size()
                size_sources = 0
                for p in builds[0].config.expand('%{_sourcedir}').split(':'):
                    size_sources += path.get_size(p)
                size_patches = 0
                for p in builds[0].config.expand('%{_patchdir}').split(':'):
                    size_patches += path.get_size(p)
                size_total = size_sources + size_patches + size_installed
                build_max_size_human = build.humanize_number(
                    size_build_max + size_installed, 'B')
                build_total_size_human = build.humanize_number(size_total, 'B')
                build_sources_size_human = build.humanize_number(
                    size_sources, 'B')
                build_patches_size_human = build.humanize_number(
                    size_patches, 'B')
                build_installed_size_human = build.humanize_number(
                    size_installed, 'B')
                build_size = 'usage: %s' % (build_max_size_human)
                build_size += ' total: %s' % (build_total_size_human)
                build_size += ' (sources: %s' % (build_sources_size_human)
                build_size += ', patches: %s' % (build_patches_size_human)
                build_size += ', installed %s)' % (build_installed_size_human)
                sizes_valid = True
            #
            # Cleaning ...
            #
            if deps is None and \
                    (not self.opts.no_clean() or self.opts.always_clean()):
                for b in builds:
                    if not b.disabled():
                        log.notice('cleaning: %s' % (b.name()))
                        b.cleanup()
            #
            # Log the build size message
            #
            if len(builds) > 1:
                log.notice('Build Sizes: %s' % (build_size))
            #
            # Clear out the builds ...
            #
            for b in builds:
                del b
        except error.general as gerr:
            if not build_error:
                log.stderr(str(gerr))
            raise
        except KeyboardInterrupt:
            mail_report = False
            raise
        except:
            self.build_failure = 'RSB general failure'
            raise
        finally:
            end = datetime.datetime.now()
            os.environ['PATH'] = current_path
            build_time = str(end - start)
            if mail_report and not self.macros.defined('mail_disable'):
                self.write_mail_header('Build Time: %s' % (build_time), True)
                self.write_mail_header('', True)
                if self.build_failure is not None:
                    mail_subject = 'FAILED %s (%s)' % \
                        (mail_subject, self.build_failure)
                else:
                    mail_subject = 'PASSED %s' % (mail_subject)
                mail_subject = 'Build %s: %s' % (reports.platform(
                    mode='system'), mail_subject)
                self.write_mail_header(mail['header'], True)
                self.write_mail_header('')
                log.notice('Mailing report: %s' % (mail['to']))
                body = self.get_mail_header()
                body += 'Sizes' + os.linesep
                body += '=====' + os.linesep + os.linesep
                if sizes_valid:
                    body += 'Maximum build usage: ' + build_max_size_human + os.linesep
                    body += 'Total size: ' + build_total_size_human + os.linesep
                    body += 'Installed : ' + build_installed_size_human + os.linesep
                    body += 'Sources: ' + build_sources_size_human + os.linesep
                    body += 'Patches: ' + build_patches_size_human + os.linesep
                else:
                    body += 'No packages built'
                body += os.linesep
                body += 'Output' + os.linesep
                body += '======' + os.linesep + os.linesep
                body += os.linesep.join(mail['output'].get())
                body += os.linesep + os.linesep
                body += 'Report' + os.linesep
                body += '======' + os.linesep + os.linesep
                body += self.get_mail_report()
                if not opts.dry_run():
                    mail['mail'].send(mail['to'], mail_subject, body)
            log.notice('Build Set: Time %s' % (build_time))
示例#4
0
def run():
    import sys
    ec = 0
    setbuilder_error = False
    mail = None
    try:
        optargs = { '--list-configs':  'List available configurations',
                    '--list-bsets':    'List available build sets',
                    '--list-configs':  'List available configuration files.',
                    '--list-deps':     'List the dependent files.',
                    '--bset-tar-file': 'Create a build set tar file',
                    '--pkg-tar-files': 'Create package tar files',
                    '--no-report':     'Do not create a package report.',
                    '--report-format': 'The report format (text, html, asciidoc).' }
        mailer.append_options(optargs)
        opts = options.load(sys.argv, optargs)
        if opts.get_arg('--mail'):
            mail = { 'mail'  : mailer.mail(opts),
                     'output': log_capture() }
            to_addr = opts.get_arg('--mail-to')
            if to_addr is not None:
                mail['to'] = to_addr[1]
            else:
                mail['to'] = opts.defaults.expand('%{_mail_tools_to}')
            mail['from'] = mail['mail'].from_address()
        log.notice('RTEMS Source Builder - Set Builder, %s' % (version.str()))
        opts.log_info()
        if not check.host_setup(opts):
            raise error.general('host build environment is not set up correctly')
        if mail:
            mail['header'] = os.linesep.join(mail['output'].get()) + os.linesep
            mail['header'] += os.linesep
            mail['header'] += 'Host: '  + reports.platform('compact') + os.linesep
            indent = '       '
            for l in textwrap.wrap(reports.platform('extended'),
                                   width = 80 - len(indent)):
                mail['header'] += indent + l + os.linesep
        configs = build.get_configs(opts)
        if opts.get_arg('--list-deps'):
            deps = []
        else:
            deps = None
        if not list_bset_cfg_files(opts, configs):
            prefix = opts.defaults.expand('%{_prefix}')
            if opts.canadian_cross():
                opts.disable_install()

            if not opts.dry_run() and \
               not opts.canadian_cross() and \
               not opts.no_install() and \
               not path.ispathwritable(prefix):
                raise error.general('prefix is not writable: %s' % (path.host(prefix)))

            for bset in opts.params():
                setbuilder_error = True
                b = buildset(bset, configs, opts)
                b.build(deps, mail = mail)
                b = None
                setbuilder_error = False

        if deps is not None:
            c = 0
            for d in sorted(set(deps)):
                c += 1
                print('dep[%d]: %s' % (c, d))
    except error.general as gerr:
        if not setbuilder_error:
            log.stderr(str(gerr))
        log.stderr('Build FAILED')
        ec = 1
    except error.internal as ierr:
        if not setbuilder_error:
            log.stderr(str(ierr))
        log.stderr('Internal Build FAILED')
        ec = 1
    except error.exit as eerr:
        pass
    except KeyboardInterrupt:
        log.notice('abort: user terminated')
        ec = 1
    except:
        raise
        log.notice('abort: unknown error')
        ec = 1
    sys.exit(ec)
示例#5
0
    def build(self, deps = None, nesting_count = 0, mail = None):

        build_error = False

        nesting_count += 1

        if mail:
            mail['output'].clear()

        log.trace('_bset: %s: make' % (self.bset))
        log.notice('Build Set: %s' % (self.bset))

        mail_subject = '%s on %s' % (self.bset,
                                     self.macros.expand('%{_host}'))

        current_path = os.environ['PATH']

        start = datetime.datetime.now()

        mail_report = False
        have_errors = False

        if mail:
            mail['output'].clear()

        try:
            configs = self.load()

            log.trace('_bset: %s: configs: %s'  % (self.bset, ','.join(configs)))

            sizes_valid = False
            builds = []
            for s in range(0, len(configs)):
                b = None
                try:
                    #
                    # Each section of the build set gets a separate set of
                    # macros so we do not contaminate one configuration with
                    # another.
                    #
                    opts = copy.copy(self.opts)
                    macros = copy.copy(self.macros)
                    if configs[s].endswith('.bset'):
                        log.trace('_bset: == %2d %s' % (nesting_count + 1, '=' * 75))
                        bs = buildset(configs[s], self.configs, opts, macros)
                        bs.build(deps, nesting_count, mail)
                        del bs
                    elif configs[s].endswith('.cfg'):
                        if mail:
                            mail_report = True
                        log.trace('_bset: -- %2d %s' % (nesting_count + 1, '-' * 75))
                        try:
                            b = build.build(configs[s],
                                            self.opts.get_arg('--pkg-tar-files'),
                                            opts,
                                            macros)
                        except:
                            build_error = True
                            raise
                        if b.macros.get('%{_disable_reporting}'):
                            mail_report = False
                        if deps is None:
                            self.build_package(configs[s], b)
                            self.report(configs[s], b,
                                        copy.copy(self.opts),
                                        copy.copy(self.macros),
                                        mail = mail)
                            # Always produce an XML report.
                            self.report(configs[s], b,
                                        copy.copy(self.opts),
                                        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]
                        #
                        # Dump post build macros.
                        #
                        log.trace('_bset: macros post-build')
                        log.trace(str(macros))
                    else:
                        raise error.general('invalid config type: %s' % (configs[s]))
                except error.general as gerr:
                    have_errors = True
                    if b is not None:
                        if self.build_failure is None:
                            self.build_failure = b.name()
                        self.write_mail_header('')
                        self.write_mail_header('= ' * 40)
                        self.write_mail_header('Build FAILED: %s' % (b.name()))
                        self.write_mail_header('- ' * 40)
                        self.write_mail_header(str(log.default))
                        self.write_mail_header('- ' * 40)
                        if self.opts.keep_going():
                            log.notice(str(gerr))
                            if self.opts.always_clean():
                                builds += [b]
                        else:
                            raise
                    else:
                        raise
            #
            # Installing ...
            #
            log.trace('_bset: installing: deps:%r no-install:%r' % \
                      (deps is None, self.opts.no_install()))
            if deps is None \
               and not self.opts.no_install() \
               and not have_errors:
                for b in builds:
                    log.trace('_bset: installing: %r' % b.installable())
                    if b.installable():
                        self.install(b.name(),
                                     b.config.expand('%{buildroot}'),
                                     b.config.expand('%{_prefix}'))
            #
            # Sizes ...
            #
            if len(builds) > 1:
                size_build = 0
                size_installed = 0
                size_build_max = 0
                for b in builds:
                    s = b.get_build_size()
                    size_build += s
                    if s > size_build_max:
                        size_build_max = s
                    size_installed += b.get_installed_size()
                size_sources = 0
                for p in builds[0].config.expand('%{_sourcedir}').split(':'):
                    size_sources += path.get_size(p)
                size_patches = 0
                for p in builds[0].config.expand('%{_patchdir}').split(':'):
                    size_patches += path.get_size(p)
                size_total = size_sources + size_patches + size_installed
                build_max_size_human = build.humanize_number(size_build_max + size_installed, 'B')
                build_total_size_human = build.humanize_number(size_total, 'B')
                build_sources_size_human = build.humanize_number(size_sources, 'B')
                build_patches_size_human = build.humanize_number(size_patches, 'B')
                build_installed_size_human = build.humanize_number(size_installed, 'B')
                build_size = 'usage: %s' % (build_max_size_human)
                build_size += ' total: %s' % (build_total_size_human)
                build_size += ' (sources: %s' % (build_sources_size_human)
                build_size += ', patches: %s' % (build_patches_size_human)
                build_size += ', installed %s)' % (build_installed_size_human)
                sizes_valid = True
            #
            # Cleaning ...
            #
            if deps is None and \
                    (not self.opts.no_clean() or self.opts.always_clean()):
                for b in builds:
                    if not b.disabled():
                        log.notice('cleaning: %s' % (b.name()))
                        b.cleanup()
            #
            # Log the build size message
            #
            if len(builds) > 1:
                log.notice('Build Sizes: %s' % (build_size))
            #
            # Clear out the builds ...
            #
            for b in builds:
                del b
        except error.general as gerr:
            if not build_error:
                log.stderr(str(gerr))
            raise
        except KeyboardInterrupt:
            mail_report = False
            raise
        except:
            self.build_failure = 'RSB general failure'
            raise
        finally:
            end = datetime.datetime.now()
            os.environ['PATH'] = current_path
            build_time = str(end - start)
            if mail_report and not self.macros.defined('mail_disable'):
                self.write_mail_header('Build Time: %s' % (build_time), True)
                self.write_mail_header('', True)
                if self.build_failure is not None:
                    mail_subject = 'FAILED %s (%s)' % \
                        (mail_subject, self.build_failure)
                else:
                    mail_subject = 'PASSED %s' % (mail_subject)
                mail_subject = 'Build %s: %s' % (reports.platform(mode = 'system'),
                                                 mail_subject)
                self.write_mail_header(mail['header'], True)
                self.write_mail_header('')
                log.notice('Mailing report: %s' % (mail['to']))
                body = self.get_mail_header()
                body += 'Sizes' + os.linesep
                body += '=====' + os.linesep + os.linesep
                if sizes_valid:
                    body += 'Maximum build usage: ' + build_max_size_human + os.linesep
                    body += 'Total size: ' + build_total_size_human + os.linesep
                    body += 'Installed : ' + build_installed_size_human + os.linesep
                    body += 'Sources: ' + build_sources_size_human + os.linesep
                    body += 'Patches: ' + build_patches_size_human + os.linesep
                else:
                    body += 'No packages built'
                body += os.linesep
                body += 'Output' + os.linesep
                body += '======' + os.linesep + os.linesep
                body += os.linesep.join(mail['output'].get())
                body += os.linesep + os.linesep
                body += 'Report' + os.linesep
                body += '======' + os.linesep + os.linesep
                body += self.get_mail_report()
                if not opts.dry_run():
                    mail['mail'].send(mail['to'], mail_subject, body)
            log.notice('Build Set: Time %s' % (build_time))