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
This commit is contained in:
Chris Johns 2022-09-01 15:57:28 +10:00
parent ce77a10078
commit 18b4507fc5
2 changed files with 26 additions and 28 deletions

View File

@ -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'

View File

@ -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)
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 ':' 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))
name = path.basename(configname)
try:
log.trace('config: %s: _open: %s' % (self.name, path.host(configname)))