Commit 7c525dac authored by Julien Muchembled's avatar Julien Muchembled Committed by Xavier Thompson

Conditional configuration sections: compute values at most once, add 'multiarch'

For example, existing values were not enough to distinguish
'arm-linux-gnueabi' from 'arm-linux-gnueabihf'.

The 'multiarch' value is the output of

  $CC -dumpmachine

where CC defaults to 'gcc'.

See also https://wiki.debian.org/Multiarch/Tuples
parent 48756121
...@@ -1848,6 +1848,48 @@ def _default_globals(): ...@@ -1848,6 +1848,48 @@ def _default_globals():
return globals_defs return globals_defs
class _default_globals(dict):
"""
Make sure parser context is computed at most once,
even if several files are parsed.
And compute some values only if accessed.
If __getitem__ raises, _doing() calls .get('__doing__'),
but that's not the only reason to subclass dict:
CPython requests it (for performance reasons?). PyPy does not care.
"""
# XXX: The following line is only to keep access to the overridden global.
# If pushed upstream, proper naming would avoid such hack.
# Meanwhile, the patch consists only in this drop-in class
# and that's easier to maintain.
_default_globals = staticmethod(_default_globals)
def __getitem__(self, key):
cls = self.__class__
try:
context = self.context
except AttributeError:
context = self.context = cls._default_globals()
try:
return context[key]
except KeyError as e:
try:
value = getattr(self, key)
except AttributeError:
pass
else:
value = context[key] = value()
return value
raise e # BBB: On Python 3, a bare 'raise' is enough.
def multiarch(self):
args = os.getenv('CC') or 'gcc', '-dumpmachine'
self['__doing__'] = '%r', args
m = subprocess.check_output(args, universal_newlines=True).rstrip()
del self['__doing__']
return m
def _open(base, filename, dl_options, override, seen=None, processing=None): def _open(base, filename, dl_options, override, seen=None, processing=None):
"""Open a configuration file and return the result as a dictionary, """Open a configuration file and return the result as a dictionary,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment