From 0253d81ad2a19101c540c49c54b314e0290a6189 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Thu, 1 Sep 2022 15:57:28 +1000 Subject: sb/config: Correctly handle multiple config paths - Add rtems/config to the config directories searched to better support deployment - Correctly expand the configdir and path searchs Updates #4716 --- source-builder/defaults.mc | 2 +- source-builder/sb/config.py | 52 ++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/source-builder/defaults.mc b/source-builder/defaults.mc index 8ed7003..4658277 100644 --- a/source-builder/defaults.mc +++ b/source-builder/defaults.mc @@ -98,7 +98,7 @@ _host_cc: none, none, 'gcc' _host_cxx: none, none, 'g++' _arch: none, none, '%{_host_arch}' _topdir: dir, required, '%{_cwd}' -_configdir: dir, optional, '%{_topdir}/config:%{_sbdir}/config:%{_sbtop}/bare/config' +_configdir: dir, optional, '%{_topdir}/config:%{_sbdir}/config:%{_sbtop}/bare/config:%{_sbtop}/rtems/config' _tardir: dir, optional, '%{_topdir}/tar' _sourcedir: dir, optional, '%{_topdir}/sources' _patchdir: dir, optional, '%{_topdir}/patches:%{_sbdir}/patches' diff --git a/source-builder/sb/config.py b/source-builder/sb/config.py index df2aa31..9250896 100644 --- a/source-builder/sb/config.py +++ b/source-builder/sb/config.py @@ -785,7 +785,16 @@ class file: mn = '%{nil}' if mn: if mn.lower() in self.macros: - s = s.replace(m, self.macros[mn.lower()]) + em = self.macros[mn.lower()] + if self.macros.get_type(mn) == 'dir' and ':' in em: + ss = [] + for sp in s.split(): + if m in sp: + sp = ':'.join([sp.replace(mn, ps) for ps in em.split(':')]) + ss += [sp] + s = ' '.join(ss) + else: + s = s.replace(m, self.macros[mn.lower()]) expanded = True elif show_warning: self._error("macro '%s' not found" % (mn)) @@ -1345,6 +1354,14 @@ class file: right = right[:-1] return end + def search_path(confignames): + for configname in confignames.split(':'): + if not configname.endswith('.cfg'): + configname = '%s.cfg' % (configname) + if path.exists(configname): + return configname + return None + if self.load_depth == 0: self._packages[self.package] = package(self.package, self.define('%{_arch}'), @@ -1358,7 +1375,7 @@ class file: # # Locate the config file. Expand any macros then add the - # extension. Check if the file exists, therefore directly + # extension. Check if the file exists then it is 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. @@ -1366,32 +1383,13 @@ class file: 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) + configname = search_path(exname) + if configname is None: + configname = search_path(self.expand(path.join('%{_configdir}', exname))) + if configname is None: + raise error.general('no config file found: %s' % (','.join(exname.split(':')))) - 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)) + name = path.basename(configname) try: log.trace('config: %s: _open: %s' % (self.name, path.host(configname))) -- cgit v1.2.3