def __init__(self, name=None, original=None, rtdir='.'): self.files = [] self.macro_filter = re.compile(r'%{[^}]+}') if original is None: self.macros = {} self.read_maps = [] self.read_map_locked = False self.write_map = 'global' self.rtpath = path.abspath(path.dirname(inspect.getfile(macros))) if path.dirname(self.rtpath).endswith('/share/rtems'): self.prefix = path.dirname(self.rtpath)[:-len('/share/rtems')] else: self.prefix = '.' self.macros['global'] = {} self.macros['global']['nil'] = ('none', 'none', '') self.macros['global']['_cwd'] = ('dir', 'required', path.abspath(os.getcwd())) self.macros['global']['_prefix'] = ('dir', 'required', self.prefix) self.macros['global']['_rtdir'] = ('dir', 'required', path.abspath( self.expand(rtdir))) self.macros['global']['_rttop'] = ('dir', 'required', self.prefix) else: self.macros = {} for m in original.macros: if m not in self.macros: self.macros[m] = {} for k in original.macros[m]: self.macros[m][k] = copy.copy(original.macros[m][k]) self.read_maps = sorted(copy.copy(original.read_maps)) self.read_map_locked = copy.copy(original.read_map_locked) self.write_map = copy.copy(original.write_map) if name is not None: self.load(name)
def _find_covoar(self): covoar_exe = 'covoar' tester_dir = path.dirname(path.abspath(sys.argv[0])) base = path.dirname(tester_dir) exe = path.join(self.prefix, 'share', 'rtems', 'tester', 'bin', covoar_exe) if path.isfile(exe): return exe exe = path.join(base, 'build', 'tester', 'covoar', covoar_exe) if path.isfile(exe): return exe raise error.general('coverage: %s not found'% (covoar_exe))
def load(args, optargs=None, command_path=None, defaults='%s' % (defaults_mc)): # # The path to this command if not supplied by the upper layers. # if command_path is None: command_path = path.dirname(args[0]) if len(command_path) == 0: command_path = '.' # # Check if there is a defaults.mc file under the command path. If so this is # the tester being run from within the git repo. If not found assume the tools # have been installed and the defaults is in the install prefix. # if path.exists(path.join(command_path, defaults_mc)): rtdir = command_path else: rtdir = '%{_prefix}/share/rtems/tester' defaults = '%s/%s' % (rtdir, defaults_mc) # # The command line contains the base defaults object all build objects copy # and modify by loading a configuration. # opts = command_line(args, optargs, macros.macros(name=defaults, rtdir=rtdir), command_path) options.load(opts) return opts
def load(self, name): # # Load all the files. # self.ini = {'base': path.dirname(name), 'files': []} includes = [name] still_loading = True while still_loading: still_loading = False for include in includes: if not path.exists(include): rebased_inc = path.join(self.ini['base'], path.basename(include)) if not path.exists(rebased_inc): e = 'config: cannot find configuration: %s' % (include) raise error.general(e) include = rebased_inc if include not in self.ini['files']: try: self.config.read(include) except configparser.ParsingError as ce: raise error.general('config: %s' % (ce)) still_loading = True self.ini['files'] += [include] includes = [] if still_loading: for section in self.config.sections(): includes += self.comma_list(section, 'include', err=False)
def load(args, optargs=None, command_path=None, defaults="%s" % (defaults_mc)): # # The path to this command if not supplied by the upper layers. # if command_path is None: command_path = path.dirname(args[0]) if len(command_path) == 0: command_path = "." # # Check if there is a defaults.mc file under the command path. If so this is # the tester being run from within the git repo. If not found assume the tools # have been installed and the defaults is in the install prefix. # if path.exists(path.join(command_path, defaults_mc)): rtdir = command_path else: rtdir = "%{_prefix}/share/rtems/tester" defaults = "%s/%s" % (rtdir, defaults_mc) # # The command line contains the base defaults object all build objects copy # and modify by loading a configuration. # opts = command_line(args, optargs, macros.macros(name=defaults, rtdir=rtdir), command_path) options.load(opts) return opts
def load(bsp, opts): mandatory = ['bsp', 'arch', 'tester'] cfg = configuration.configuration() path_ = opts.defaults.expand('%%{_configdir}/bsps/%s.ini' % (bsp)) ini_name = path.basename(path_) for p in path.dirname(path_).split(':'): if path.exists(path.join(p, ini_name)): cfg.load(path.join(p, ini_name)) if not cfg.has_section(bsp): raise error.general('bsp section not found in ini: [%s]' % (bsp)) item_names = cfg.get_item_names(bsp, err=False) for m in mandatory: if m not in item_names: raise error.general( 'mandatory item not found in bsp section: %s' % (m)) opts.defaults.set_write_map(bsp, add=True) for i in cfg.get_items(bsp, flatten=False): opts.defaults[i[0]] = i[1] if not opts.defaults.set_read_map(bsp): raise error.general('cannot set BSP read map: %s' % (bsp)) # Get a copy of the required fields we need requires = cfg.comma_list(bsp, 'requires', err=False) del cfg user_config = opts.find_arg('--user-config') if user_config is not None: user_config = path.expanduser(user_config[1]) if not path.exists(user_config): raise error.general( 'cannot find user configuration file: %s' % (user_config)) else: if 'HOME' in os.environ: user_config = path.join(os.environ['HOME'], '.rtemstesterrc') if user_config: if path.exists(user_config): cfg = configuration.configuration() cfg.load(user_config) if cfg.has_section(bsp): for i in cfg.get_items(bsp, flatten=False): opts.defaults[i[0]] = i[1] # Check for the required values. for r in requires: if opts.defaults.get(r) is None: raise error.general('user value missing, BSP %s requires \'%s\': missing: %s' % \ (bsp, ', '.join(requires), r)) return opts.defaults['bsp'] raise error.general('cannot find bsp configuration file: %s.ini' % (bsp))
def load(args, optargs = None, command_path = None, defaults = '%{_rtdir}/rtems/testing/defaults.mc'): # # The path to this command if not supplied by the upper layers. # if command_path is None: command_path = path.dirname(args[0]) if len(command_path) == 0: command_path = '.' # # The command line contains the base defaults object all build objects copy # and modify by loading a configuration. # opts = command_line(args, optargs, macros.macros(name = defaults, rtdir = command_path), command_path) options.load(opts) return opts
def load(self, name): def common_end(left, right): end = '' while len(left) and len(right): if left[-1] != right[-1]: return end end = left[-1] + end left = left[:-1] right = right[:-1] return end if self.load_depth == 0: self.in_error = False self.lc = 0 self.name = name self.conditionals = {} self.load_depth += 1 save_name = self.name save_lc = self.lc self.name = name self.lc = 0 # # Locate the config file. Expand any macros then add the # extension. Check if the file exists, therefore directly # referenced. If not see if the file contains ':' or the path # separator. If it does split the path else use the standard config dir # path in the defaults. # exname = self.expand(name) # # Macro could add an extension. # if exname.endswith('.cfg'): configname = exname else: configname = '%s.cfg' % (exname) name = '%s.cfg' % (name) if ':' in configname: cfgname = path.basename(configname) else: cfgname = common_end(configname, name) if not path.exists(configname): if ':' in configname: configdirs = path.dirname(configname).split(':') else: configdirs = self.define('_configdir').split(':') for cp in configdirs: configname = path.join(path.abspath(cp), cfgname) if path.exists(configname): break configname = None if configname is None: raise error.general('no config file found: %s' % (cfgname)) try: log.trace('config: %s: _open: %s' % (self.init_name, path.host(configname))) config = open(path.host(configname), 'r') except IOError as err: raise error.general('error opening config file: %s' % (path.host(configname))) self.configpath += [configname] self._includes += [configname] try: dir = None info = None data = [] while True: r = self._parse(config, dir, info) if r[0] == 'control': if r[1] == '%end': break log.warning("unexpected '%s'" % (r[1])) elif r[0] == 'directive': if r[1] == '%include': self.load(r[2][0]) continue dir, info, data = self._process_directive(r, dir, info, data) elif r[0] == 'data': dir, info, data = self._process_data(r, dir, info, data) else: self._error("%d: invalid parse state: '%s" % (self.lc, r[0])) if dir is not None: self._directive_extend(dir, data) except: config.close() raise config.close() self.name = save_name self.lc = save_lc self.load_depth -= 1