Sync up initialization logic with Properties and BinaryTable

1. They (and the others) all use PerMachineDefaultable. It's not the
    best class, but consistency come first. (It and all of them can be
    improved accross the board later.)

 2. They use `None` as the default argument so as not to mutate what's
    effectively a global variables. (Thanks @dcbaker!)

 3. They have a `fallback` field to centralize authority on when
    environment variables should be consulted.
pull/4991/head
John Ericson 6 years ago committed by Dylan Baker
parent 2622e9ec32
commit c2db7a9cee
  1. 33
      mesonbuild/envconfig.py
  2. 12
      mesonbuild/environment.py

@ -92,10 +92,27 @@ class MesonConfigFile:
out[s] = section
return out
class Properties:
class HasEnvVarFallback:
"""
A tiny class to indicate that this class contains data that can be
initialized from either a config file or environment file. The `fallback`
field says whether env vars should be used. Downstream logic (e.g. subclass
methods) can check it to decide what to do, since env vars are currently
lazily decoded.
Frankly, this is a pretty silly class at the moment. The hope is the way
that we deal with environment variables will become more structured, and
this can be starting point.
"""
def __init__(self, fallback = True):
self.fallback = fallback
class Properties(HasEnvVarFallback):
def __init__(
self,
properties: typing.Optional[typing.Dict[str, typing.Union[str, typing.List[str]]]] = None):
properties: typing.Optional[typing.Dict[str, typing.Union[str, typing.List[str]]]] = None,
fallback = True):
super().__init__(fallback)
self.properties = properties or {}
def has_stdlib(self, language):
@ -269,10 +286,14 @@ class MachineInfos(PerMachineDefaultable):
def matches_build_machine(self, machine: MachineChoice):
return self.build == self[machine]
class BinaryTable:
def __init__(self, binaries = {}, fallback = True):
self.binaries = binaries
self.fallback = fallback
class BinaryTable(HasEnvVarFallback):
def __init__(
self,
binaries: typing.Optional[typing.Dict[str, typing.Union[str, typing.List[str]]]] = None,
fallback = True):
super().__init__(fallback)
self.binaries = binaries or {}
for name, command in self.binaries.items():
if not isinstance(command, (list, str)):
# TODO generalize message

@ -375,12 +375,13 @@ class Environment:
# that there is no meta data, only names/paths.
self.binaries = PerMachineDefaultable()
# Misc other properties about each machine.
self.properties = PerMachineDefaultable()
# Just uses hard-coded defaults and environment variables. Might be
# overwritten by a native file.
self.binaries.build = BinaryTable({})
# Misc other properties about each machine.
self.properties = PerMachine(Properties(), Properties(), Properties())
self.binaries.build = BinaryTable()
self.properties.build = Properties()
# Store paths for native and cross build files. There is no target
# machine information here because nothing is installed for the target
@ -395,7 +396,7 @@ class Environment:
if self.coredata.cross_file is not None:
config = MesonConfigFile.parse_datafile(self.coredata.cross_file)
self.properties.host.properties = config.get('properties', {})
self.properties.host = Properties(config.get('properties', {}), False)
self.binaries.host = BinaryTable(config.get('binaries', {}), False)
if 'host_machine' in config:
self.machines.host = MachineInfo.from_literal(config['host_machine'])
@ -405,6 +406,7 @@ class Environment:
self.machines.default_missing()
self.binaries.default_missing()
self.properties.default_missing()
self.paths.default_missing()
exe_wrapper = self.binaries.host.lookup_entry('exe_wrapper')

Loading…
Cancel
Save