def run(args): try: optargs = { '--list-bsets': 'List available build sets', '--list-configs': 'List available configurations', '--format': 'Output format (text, html, asciidoc, ini, xml)', '--output': 'File name to output the report' } opts = options.load(args, optargs) if opts.get_arg('--output') and len(opts.params()) > 1: raise error.general( '--output can only be used with a single config') print 'RTEMS Source Builder, Reporter v%s' % (version.str()) opts.log_info() if not check.host_setup(opts): log.warning('forcing build with known host setup problems') configs = build.get_configs(opts) if not setbuilder.list_bset_cfg_files(opts, configs): output = opts.get_arg('--output') if output is not None: output = output[1] formatter = text_formatter() format_opt = opts.get_arg('--format') if format_opt: if len(format_opt) != 2: raise error.general('invalid format option: %s' % ('='.join(format_opt))) if format_opt[1] == 'text': pass elif format_opt[1] == 'asciidoc': formatter = asciidoc_formatter() elif format_opt[1] == 'html': formatter = html_formatter() elif format_opt[1] == 'ini': formatter = ini_formatter() elif format_opt[1] == 'xml': formatter = xml_formatter() else: raise error.general('invalid format: %s' % (format_opt[1])) r = report(formatter, configs, opts) for _config in opts.params(): if output is None: outname = path.splitext(_config)[0] + formatter.ext() outname = outname.replace('/', '-') else: outname = output config = build.find_config(_config, configs) if config is None: raise error.general('config file not found: %s' % (inname)) r.create(config, outname) del r else: raise error.general('invalid config type: %s' % (config)) except error.general, gerr: print gerr sys.exit(1)
def run(args): try: optargs = { '--list-bsets': 'List available build sets', '--list-configs': 'List available configurations', '--format': 'Output format (text, html, asciidoc, ini)', '--output': 'File name to output the report' } opts = options.load(args, optargs) if opts.get_arg('--output') and len(opts.params()) > 1: raise error.general('--output can only be used with a single config') print 'RTEMS Source Builder, Reporter v%s' % (version.str()) opts.log_info() if not check.host_setup(opts): log.warning('forcing build with known host setup problems') configs = build.get_configs(opts) if not setbuilder.list_bset_cfg_files(opts, configs): output = opts.get_arg('--output') if output is not None: output = output[1] format = 'text' ext = '.txt' format_opt = opts.get_arg('--format') if format_opt: if len(format_opt) != 2: raise error.general('invalid format option: %s' % ('='.join(format_opt))) if format_opt[1] == 'text': pass elif format_opt[1] == 'asciidoc': format = 'asciidoc' ext = '.txt' elif format_opt[1] == 'html': format = 'html' ext = '.html' elif format_opt[1] == 'ini': format = 'ini' ext = '.ini' else: raise error.general('invalid format: %s' % (format_opt[1])) r = report(format, configs, opts) for _config in opts.params(): if output is None: outname = path.splitext(_config)[0] + ext outname = outname.replace('/', '-') else: outname = output config = build.find_config(_config, configs) if config is None: raise error.general('config file not found: %s' % (inname)) r.create(config, outname) del r else: raise error.general('invalid config type: %s' % (config)) except error.general, gerr: print gerr sys.exit(1)
def run(args): try: optargs = { "--list-bsets": "List available build sets", "--list-configs": "List available configurations", "--format": "Output format (text, html, asciidoc)", "--output": "File name to output the report", } opts = options.load(args, optargs) if opts.get_arg("--output") and len(opts.params()) > 1: raise error.general("--output can only be used with a single config") print "RTEMS Source Builder, Reporter v%s" % (version.str()) opts.log_info() if not check.host_setup(opts): log.warning("forcing build with known host setup problems") configs = build.get_configs(opts) if not setbuilder.list_bset_cfg_files(opts, configs): output = opts.get_arg("--output") if output is not None: output = output[1] format = "text" ext = ".txt" format_opt = opts.get_arg("--format") if format_opt: if len(format_opt) != 2: raise error.general("invalid format option: %s" % ("=".join(format_opt))) if format_opt[1] == "text": pass elif format_opt[1] == "asciidoc": format = "asciidoc" ext = ".txt" elif format_opt[1] == "html": format = "html" ext = ".html" else: raise error.general("invalid format: %s" % (format_opt[1])) r = report(format, configs, opts) for _config in opts.params(): if output is None: outname = path.splitext(_config)[0] + ext outname = outname.replace("/", "-") else: outname = output config = build.find_config(_config, configs) if config is None: raise error.general("config file not found: %s" % (inname)) r.create(config, outname) del r else: raise error.general("invalid config type: %s" % (config)) except error.general, gerr: print gerr sys.exit(1)
class buildset: """Build a set builds a set of packages.""" def __init__(self, bset, _configs, opts, macros=None): log.trace('_bset: %s: init' % (bset)) self.configs = _configs self.opts = opts if macros is None: self.macros = copy.copy(opts.defaults) else: self.macros = copy.copy(macros) self.bset = bset _target = self.macros.expand('%{_target}') if len(_target): pkg_prefix = _target else: pkg_prefix = self.macros.expand('%{_host}') self.bset_pkg = '%s-%s-set' % (pkg_prefix, self.bset) self.mail_header = '' self.mail_report = '' self.build_failure = None def write_mail_header(self, text, prepend=False): if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r': text += os.linesep if prepend: self.mail_header = text + self.mail_header else: self.mail_header += text def write_mail_report(self, text, prepend=False): if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r': text += os.linesep if prepend: self.mail_report = text + self.mail_report else: self.mail_report += text def copy(self, src, dst): log.output('copy: %s => %s' % (path.host(src), path.host(dst))) if not self.opts.dry_run(): path.copy_tree(src, dst) def report(self, _config, _build): if not _build.opts.get_arg('--no-report') \ and not _build.macros.get('%{_disable_reporting}') \ and _build.opts.get_arg('--mail'): format = _build.opts.get_arg('--report-format') if format is None: format = 'html' ext = '.html' else: if len(format) != 2: raise error.general('invalid report format option: %s' % ('='.join(format))) if format[1] == 'text': format = 'text' ext = '.txt' elif format[1] == 'asciidoc': format = 'asciidoc' ext = '.txt' elif format[1] == 'html': format = 'html' ext = '.html' else: raise error.general('invalid report format: %s' % (format[1])) buildroot = _build.config.abspath('%{buildroot}') prefix = _build.macros.expand('%{_prefix}') name = _build.main_package().name() + ext log.notice('reporting: %s -> %s' % (_config, name)) if not _build.opts.get_arg('--no-report'): outpath = path.host( path.join(buildroot, prefix, 'share', 'rtems-source-builder')) outname = path.host(path.join(outpath, name)) r = reports.report(format, self.configs, _build.opts, _build.macros) r.setup() r.introduction(_build.config.file_name()) r.config(_build.config, _build.opts, _build.macros) if not _build.opts.dry_run(): _build.mkdir(outpath) r.write(outname) del r if not _build.macros.get('%{_disable_reporting}') \ and _build.opts.get_arg('--mail'): r = reports.report('text', self.configs, _build.opts, _build.macros) r.setup() r.introduction(_build.config.file_name()) r.config(_build.config, _build.opts, _build.macros) self.write_mail_report(r.out) del r def root_copy(self, src, dst): what = '%s -> %s' % \ (os.path.relpath(path.host(src)), os.path.relpath(path.host(dst))) log.trace('_bset: %s: collecting: %s' % (self.bset, what)) self.copy(src, dst) def install(self, name, buildroot, prefix): dst = prefix src = path.join(buildroot, prefix) log.notice('installing: %s -> %s' % (name, path.host(dst))) self.copy(src, dst) def canadian_cross(self, _build): # @fixme Switch to using a private macros map. macros_to_save = [ '%{_prefix}', '%{_tmproot}', '%{buildroot}', '%{_builddir}', '%{_host}' ] macros_to_copy = [('%{_host}', '%{_build}'), ('%{_tmproot}', '%{_tmpcxcroot}'), ('%{buildroot}', '%{buildcxcroot}'), ('%{_builddir}', '%{_buildcxcdir}')] orig_macros = {} for m in macros_to_save: orig_macros[m] = _build.config.macro(m) for m in macros_to_copy: _build.config.set_define(m[0], _build.config.macro(m[1])) _build.make() for m in macros_to_save: _build.config.set_define(m, orig_macros[m]) if not _build.macros.get('%{_disable_collecting}'): self.root_copy(_build.config.expand('%{buildcxcroot}'), _build.config.expand('%{_tmpcxcroot}')) def build_package(self, _config, _build): if not _build.disabled(): if _build.canadian_cross(): self.canadian_cross(_build) _build.make() self.report(_config, _build) if not _build.macros.get('%{_disable_collecting}'): 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') \ and not _build.macros.get('%{_disable_packaging}'): path.mkdir(tardir) tar = path.join( tardir, _build.config.expand('%s.tar.bz2' % (self.bset_pkg))) log.notice('tarball: %s' % (os.path.relpath(path.host(tar)))) 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) def parse(self, bset): def _clean(line): line = line[0:-1] b = line.find('#') if b >= 0: line = line[1:b] return line.strip() bsetname = bset if not path.exists(bsetname): for cp in self.macros.expand('%{_configdir}').split(':'): configdir = path.abspath(cp) bsetname = path.join(configdir, bset) if path.exists(bsetname): break bsetname = None if bsetname is None: raise error.general('no build set file found: %s' % (bset)) try: log.trace('_bset: %s: open: %s' % (self.bset, bsetname)) bset = open(path.host(bsetname), 'r') except IOError, err: raise error.general('error opening bset file: %s' % (bsetname)) configs = [] try: lc = 0 for l in bset: lc += 1 l = _clean(l) if len(l) == 0: continue 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 = self.macros.expand(ls[1].strip()) self.macros['package'] = self.bset_pkg elif ls[0][0] == '%': if ls[0] == '%define': 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()) elif ls[0] == '%undefine': if len(ls) > 2: raise error.general('%s:%d: %undefine requires just the name' % \ (self.bset, lc)) self.macros.undefine(ls[1].strip()) elif ls[0] == '%include': configs += self.parse(ls[1].strip()) elif ls[0] == '%patch' or ls[0] == '%source': def err(msg): raise error.general('%s:%d: %s' % (self.bset, lc, msg)) sources.process(ls[0][1:], ls[1:], self.macros, err) else: l = l.strip() c = build.find_config(l, self.configs) if c is None: raise error.general('%s:%d: cannot find file: %s' % (self.bset, lc, l)) configs += [c] except: bset.close() raise bset.close() return configs
def parse(self, bset): # # Ouch, this is a copy of the setbuilder.py code. # def _clean(line): line = line[0:-1] b = line.find('#') if b >= 0: line = line[1:b] return line.strip() bsetname = bset if not path.exists(bsetname): for cp in self.macros.expand('%{_configdir}').split(':'): configdir = path.abspath(cp) bsetname = path.join(configdir, bset) if path.exists(bsetname): break bsetname = None if bsetname is None: raise error.general('no build set file found: %s' % (bset)) try: log.trace('_bset: %s: open: %s' % (self.bset, bsetname)) bset = open(path.host(bsetname), 'r') except IOError as err: raise error.general('error opening bset file: %s' % (bsetname)) configs = [] try: lc = 0 for l in bset: lc += 1 l = _clean(l) if len(l) == 0: continue 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] == '%': def err(msg): raise error.general('%s:%d: %s' % (self.bset, lc, msg)) if ls[0] == '%define': 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()) elif ls[0] == '%undefine': if len(ls) > 2: raise error.general('%s:%d: %undefine requires just the name' % \ (self.bset, lc)) self.macros.undefine(ls[1].strip()) elif ls[0] == '%include': configs += self.parse(ls[1].strip()) elif ls[0] in ['%patch', '%source']: sources.process(ls[0][1:], ls[1:], self.macros, err) elif ls[0] == '%hash': sources.hash(ls[1:], self.macros, err) else: l = l.strip() c = build.find_config(l, self.configs) if c is None: raise error.general('%s:%d: cannot find file: %s' % (self.bset, lc, l)) configs += [c] except: bset.close() raise bset.close() return configs
def parse(self, bset): def _clean(line): line = line[0:-1] b = line.find('#') if b >= 0: line = line[1:b] return line.strip() bsetname = bset if not path.exists(bsetname): for cp in self.macros.expand('%{_configdir}').split(':'): configdir = path.abspath(cp) bsetname = path.join(configdir, bset) if path.exists(bsetname): break bsetname = None if bsetname is None: raise error.general('no build set file found: %s' % (bset)) try: log.trace('_bset: %s: open: %s' % (self.bset, bsetname)) bset = open(path.host(bsetname), 'r') except IOError as err: raise error.general('error opening bset file: %s' % (bsetname)) configs = [] try: lc = 0 for l in bset: lc += 1 l = _clean(l) if len(l) == 0: continue 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] == '%': def err(msg): raise error.general('%s:%d: %s' % (self.bset, lc, msg)) if ls[0] == '%define': 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()) elif ls[0] == '%undefine': if len(ls) > 2: raise error.general('%s:%d: %undefine requires just the name' % \ (self.bset, lc)) self.macros.undefine(ls[1].strip()) elif ls[0] == '%include': configs += self.parse(ls[1].strip()) elif ls[0] in ['%patch', '%source']: sources.process(ls[0][1:], ls[1:], self.macros, err) elif ls[0] == '%hash': sources.hash(ls[1:], self.macros, err) else: l = l.strip() c = build.find_config(l, self.configs) if c is None: raise error.general('%s:%d: cannot find file: %s' % (self.bset, lc, l)) configs += [c] except: bset.close() raise bset.close() return configs
def run(args): try: optargs = { '--list-bsets': 'List available build sets', '--list-configs': 'List available configurations', '--format': 'Output format (text, html, markdown, ini, xml)', '--output': 'File name to output the report' } opts = options.load(args, optargs, logfile = False) if opts.get_arg('--output') and len(opts.params()) > 1: raise error.general('--output can only be used with a single config') print('RTEMS Source Builder, Reporter, %s' % (version.str())) opts.log_info() if not check.host_setup(opts): log.warning('forcing build with known host setup problems') configs = build.get_configs(opts) if not setbuilder.list_bset_cfg_files(opts, configs): output = opts.get_arg('--output') if output is not None: output = output[1] formatter = text_formatter() format_opt = opts.get_arg('--format') if format_opt: if len(format_opt) != 2: raise error.general('invalid format option: %s' % ('='.join(format_opt))) if format_opt[1] == 'text': pass elif format_opt[1] == 'markdown': formatter = markdown_formatter() elif format_opt[1] == 'html': formatter = html_formatter() elif format_opt[1] == 'ini': formatter = ini_formatter() elif format_opt[1] == 'xml': formatter = xml_formatter() else: raise error.general('invalid format: %s' % (format_opt[1])) r = report(formatter, configs, opts) for _config in opts.params(): if output is None: outname = path.splitext(_config)[0] + formatter.ext() outname = outname.replace('/', '-') else: outname = output config = build.find_config(_config, configs) if config is None: raise error.general('config file not found: %s' % (_config)) r.create(config, outname) del r else: raise error.general('invalid config type: %s' % (config)) except error.general as gerr: print(gerr) sys.exit(1) except error.internal as ierr: print(ierr) sys.exit(1) except error.exit as eerr: pass except KeyboardInterrupt: log.notice('abort: user terminated') sys.exit(1) sys.exit(0)
def run(args): try: optargs = { '--list-bsets': 'List available build sets', '--list-configs': 'List available configurations', '--format': 'Output format (text, html, markdown, ini, xml)', '--output': 'File name to output the report', '--sanitize': 'Remove Remotes information from report' } opts = options.load(args, optargs, logfile=False) if opts.get_arg('--output') and len(opts.params()) > 1: raise error.general( '--output can only be used with a single config') print('RTEMS Source Builder, Reporter, %s' % (version.string())) opts.log_info() if not check.host_setup(opts): log.warning('forcing build with known host setup problems') configs = build.get_configs(opts) if not setbuilder.list_bset_cfg_files(opts, configs): output = opts.get_arg('--output') if output is not None: output = output[1] formatter = text_formatter() format_opt = opts.get_arg('--format') if format_opt: if len(format_opt) != 2: raise error.general('invalid format option: %s' % ('='.join(format_opt))) if format_opt[1] == 'text': pass elif format_opt[1] == 'markdown': formatter = markdown_formatter() elif format_opt[1] == 'html': formatter = html_formatter() elif format_opt[1] == 'ini': formatter = ini_formatter() elif format_opt[1] == 'xml': formatter = xml_formatter() else: raise error.general('invalid format: %s' % (format_opt[1])) sanitize = False if opts.get_arg('--sanitize'): sanitize = True r = report(formatter, sanitize, configs, opts) for _config in opts.params(): if output is None: outname = path.splitext(_config)[0] + formatter.ext() outname = outname.replace('/', '-') else: outname = output config = build.find_config(_config, configs) if config is None: raise error.general('config file not found: %s' % (_config)) r.create(config, outname) del r except error.general as gerr: print(gerr) sys.exit(1) except error.internal as ierr: print(ierr) sys.exit(1) except error.exit as eerr: pass except KeyboardInterrupt: log.notice('abort: user terminated') sys.exit(1) sys.exit(0)