def _target_command(self, command, bsp_arch=None, bsp=None, exe=None, fexe=None): if self.defined('target_%s_command' % (command)): cmd = self.expand('%%{target_%s_command}' % (command)).strip() if bsp_arch is not None and '@ARCH@' in cmd: cmd = cmd.replace('@ARCH@', bsp_arch) if bsp is not None and '@BSP@' in cmd: cmd = cmd.replace('@BSP@', bsp) if exe is not None and '@EXE@' in cmd: cmd = cmd.replace('@EXE@', exe) if fexe is not None and '@FEXE@' in cmd: cmd = cmd.replace('@FEXE@', exe) if len(cmd) > 0: output = '' if not self.opts.dry_run(): rs_proc = execute.capture_execution() ec, proc, output = rs_proc.open(cmd, shell=True) self._capture_console('target %s: %s' % (command, cmd)) if len(output) > 0: output = os.linesep.join( [' ' + l for l in output.splitlines()]) self._capture_console(output)
def _lo_triplets(self, opt, macro, value): # # This is a target triplet. Run it past config.sub to make make sure it # is ok. The target triplet is 'cpu-vendor-os'. # e = execute.capture_execution() config_sub = path.join(self.command_path, basepath, 'config.sub') exit_code, proc, output = e.shell(config_sub + ' ' + value) if exit_code == 0: value = output self.defaults[macro] = ('triplet', 'none', value) self.opts[opt[2:]] = value _cpu = macro + '_cpu' _arch = macro + '_arch' _vendor = macro + '_vendor' _os = macro + '_os' _arch_value = '' _vendor_value = '' _os_value = '' dash = value.find('-') if dash >= 0: _arch_value = value[:dash] value = value[dash + 1:] dash = value.find('-') if dash >= 0: _vendor_value = value[:dash] value = value[dash + 1:] if len(value): _os_value = value self.defaults[_cpu] = _arch_value self.defaults[_arch] = _arch_value self.defaults[_vendor] = _vendor_value self.defaults[_os] = _os_value
def cpus(): psrinfo = '/sbin/psrinfo|wc -l' e = execute.capture_execution() exit_code, proc, output = e.shell(psrinfo) if exit_code == 0: ncpus = int(output) else: ncpus = 1 return ncpus
def cpus(): sysctl = '/usr/sbin/sysctl ' e = execute.capture_execution() exit_code, proc, output = e.shell(sysctl + 'hw.ncpu') if exit_code == 0: ncpus = int(output.split(' ')[1].strip()) else: ncpus = 1 return ncpus
def __init__(self, opts): self.opts = opts self.gitconfig_lines = None if opts.find_arg('--use-gitconfig') is not None: # Read the output of `git config --list` instead of reading the # .gitconfig file directly because Python 2 ConfigParser does not # accept tabs at the beginning of lines. e = execute.capture_execution() exit_code, proc, output = e.open('git config --list', shell=True) if exit_code == 0: self.gitconfig_lines = output.split(os.linesep)
def _run(self, args, check=False): e = execute.capture_execution() if path.exists(self.path): cwd = self.path else: cwd = None cmd = [self.git] + args log.trace('cmd: (%s) %s' % (str(cwd), ' '.join(cmd))) exit_code, proc, output = e.spawn(cmd, cwd=path.host(cwd)) log.trace(output) if check: self._git_exit_code(exit_code, cmd, output) return exit_code, output
def _command(cmd, cwd): e = execute.capture_execution() cwd = path.abspath(cwd) log.output('>> cwd: %s' % (cwd)) log.output('> %s' % (cmd)) exit_code, proc, output = e.shell(cmd, cwd=path.host(cwd)) output_split = output.split(os.linesep) if len(output_split) >= 1 and len(output_split[0]) > 0: log.output(['> ' + l for l in output_split]) log.output('> exit: %d' % (exit_code)) if exit_code != 0: err = 'executing failure: (exit:%d) %s' % (exit_code, cmd) raise error.general(err) return output
def cpus(): processors = '/bin/grep processor /proc/cpuinfo' e = execute.capture_execution() exit_code, proc, output = e.shell(processors) ncpus = 0 if exit_code == 0: try: for l in output.split('\n'): count = l.split(':')[1].strip() if int(count) > ncpus: ncpus = int(count) except: pass return ncpus + 1
def _shell(self, line): sl = self.sf.findall(line) if len(sl): e = execute.capture_execution() for s in sl: if host.is_windows: cmd = '%s -c "%s"' % (self.macros.expand('%{__sh}'), s[2:-1]) else: cmd = s[2:-1] exit_code, proc, output = e.shell(cmd) if exit_code == 0: line = line.replace(s, output) else: raise error.general('shell macro failed: %s:%d: %s' % (s, exit_code, output)) return line
def _execute(self, phase): exit_code = 0 cmd = self.commands[phase] try: # This should locked; not sure how to do that self.proc = execute.capture_execution(log=self.output) log.output(wrap(('run:', self.build.key(), cmd), lineend='\\')) if not self.commands['dry-run']: exit_code, proc, output = self.proc.shell( cmd, cwd=path.host(self._build_dir())) except: traceback.print_exc() self.lock.acquire() if self.proc is not None: self.proc.kill() self.lock.release() exit_code = 1 self.lock.acquire() self.proc = None self.lock.release() return exit_code == 0
def build_arch_bsp(self, arch, bsp): if not self.config.bsp_present(arch, bsp): raise error.general('BSP not found: %s/%s' % (arch, bsp)) log.output('-' * 70) log.notice('] BSP: %s/%s' % (arch, bsp)) log.notice('. Creating: %s' % (self._path(arch, bsp))) self._arch_bsp_dir_clean(arch, bsp) self._arch_bsp_dir_make(arch, bsp) variations = self._variations(arch, bsp) build_set = self._build_set(variations) bsp_start = datetime.datetime.now() bsp_warnings = warnings_counter(self.rtems) env_path = os.environ['PATH'] os.environ['PATH'] = path.host(path.join(self.tools, 'bin')) + \ os.pathsep + os.environ['PATH'] for bs in sorted(build_set.keys()): warnings = warnings_counter(self.rtems) start = datetime.datetime.now() log.output('- ' * 35) log.notice('. Configuring: %s' % (bs)) try: result = '+ Pass' bpath = self._build_dir(arch, bsp, bs) path.mkdir(bpath) config_cmd = self._config_command(build_set[bs], arch, bsp) cmd = config_cmd e = execute.capture_execution(log = warnings) log.output('run: ' + cmd) if self.options['dry-run']: exit_code = 0 else: exit_code, proc, output = e.shell(cmd, cwd = path.host(bpath)) if exit_code != 0: result = '- FAIL' self.errors['configure'] += 1 log.notice('- Configure failed: %s' % (bs)) log.output('cmd failed: %s' % (cmd)) if self.options['stop-on-error']: raise error.general('Configuring %s failed' % (bs)) else: log.notice('. Building: %s' % (bs)) cmd = 'make' if 'jobs' in self.options: cmd += ' -j %s' % (self.options['jobs']) log.output('run: ' + cmd) if self.options['dry-run']: exit_code = 0 else: exit_code, proc, output = e.shell(cmd, cwd = path.host(bpath)) if exit_code != 0: result = '- FAIL' self.errors['build'] += 1 log.notice('- FAIL: %s: %s' % (bs, self._error_str())) log.output('cmd failed: %s' % (cmd)) if self.options['stop-on-error']: raise error.general('Building %s failed' % (bs)) files = self._count_files(arch, bsp, bs) log.notice('%s: %s: warnings:%d exes:%d objs:%s libs:%d' % \ (result, bs, warnings.get(), files['exes'], files['objs'], files['libs'])) log.notice(' %s' % (self._error_str())) self.results.add(result[0] == '+', arch, bsp, config_cmd, warnings.get()) finally: end = datetime.datetime.now() if not self.options['no-clean']: log.notice('. Cleaning: %s' % (self._build_dir(arch, bsp, bs))) path.removeall(self._build_dir(arch, bsp, bs)) log.notice('^ Time %s' % (str(end - start))) log.output('Warnings Report:') log.output(warnings.report()) warnings.accumulate(bsp_warnings) warnings.accumulate(self.warnings) bsp_end = datetime.datetime.now() log.notice('^ BSP Time %s' % (str(bsp_end - bsp_start))) log.output('BSP Warnings Report:') log.output(bsp_warnings.report()) os.environ['PATH'] = env_path
def build_arch_bsp(self, arch, bsp): if not self.config.bsp_present(arch, bsp): raise error.general('BSP not found: %s/%s' % (arch, bsp)) log.output('-' * 70) log.notice('] BSP: %s/%s' % (arch, bsp)) log.notice('. Creating: %s' % (self._path(arch, bsp))) self._arch_bsp_dir_clean(arch, bsp) self._arch_bsp_dir_make(arch, bsp) variations = self._variations(arch, bsp) build_set = self._build_set(variations) bsp_start = datetime.datetime.now() bsp_warnings = warnings_counter(self.rtems) env_path = os.environ['PATH'] os.environ['PATH'] = path.host(path.join(self.tools, 'bin')) + \ os.pathsep + os.environ['PATH'] for bs in sorted(build_set.keys()): warnings = warnings_counter(self.rtems) start = datetime.datetime.now() log.output('- ' * 35) log.notice('. Configuring: %s' % (bs)) try: result = '+ Pass' bpath = self._build_dir(arch, bsp, bs) path.mkdir(bpath) config_cmd = self._config_command(build_set[bs], arch, bsp) cmd = config_cmd e = execute.capture_execution(log=warnings) log.output('run: ' + cmd) if self.options['dry-run']: exit_code = 0 else: exit_code, proc, output = e.shell(cmd, cwd=path.host(bpath)) if exit_code != 0: result = '- FAIL' self.errors['configure'] += 1 log.notice('- Configure failed: %s' % (bs)) log.output('cmd failed: %s' % (cmd)) if self.options['stop-on-error']: raise error.general('Configuring %s failed' % (bs)) else: log.notice('. Building: %s' % (bs)) cmd = 'make' if 'jobs' in self.options: cmd += ' -j %s' % (self.options['jobs']) log.output('run: ' + cmd) if self.options['dry-run']: exit_code = 0 else: exit_code, proc, output = e.shell(cmd, cwd=path.host(bpath)) if exit_code != 0: result = '- FAIL' self.errors['build'] += 1 log.notice('- FAIL: %s: %s' % (bs, self._error_str())) log.output('cmd failed: %s' % (cmd)) if self.options['stop-on-error']: raise error.general('Building %s failed' % (bs)) files = self._count_files(arch, bsp, bs) log.notice('%s: %s: warnings:%d exes:%d objs:%s libs:%d' % \ (result, bs, warnings.get(), files['exes'], files['objs'], files['libs'])) log.notice(' %s' % (self._error_str())) self.results.add(result[0] == '+', arch, bsp, config_cmd, warnings.get()) finally: end = datetime.datetime.now() if not self.options['no-clean']: log.notice('. Cleaning: %s' % (self._build_dir(arch, bsp, bs))) path.removeall(self._build_dir(arch, bsp, bs)) log.notice('^ Time %s' % (str(end - start))) log.output('Warnings Report:') log.output(warnings.report()) warnings.accumulate(bsp_warnings) warnings.accumulate(self.warnings) bsp_end = datetime.datetime.now() log.notice('^ BSP Time %s' % (str(bsp_end - bsp_start))) log.output('BSP Warnings Report:') log.output(bsp_warnings.report()) os.environ['PATH'] = env_path