[rtems-source-builder commit] sb/config: Correctly handle multiple config paths

Chris Johns chrisj at rtems.org
Fri Sep 9 01:32:20 UTC 2022


Module:    rtems-source-builder
Branch:    master
Commit:    18b4507fc5721fdd9d6bc1081a03bc5080b7055f
Changeset: http://git.rtems.org/rtems-source-builder/commit/?id=18b4507fc5721fdd9d6bc1081a03bc5080b7055f

Author:    Chris Johns <chrisj at rtems.org>
Date:      Thu Sep  1 15:57:28 2022 +1000

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

Close #4710

---

 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 98775e8..503dd92 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 ad078d9..73e8fcb 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)))



More information about the vc mailing list