aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/envconfig.py
diff options
context:
space:
mode:
authorJohn Ericson <git@JohnEricson.me>2019-02-26 00:55:43 -0500
committerDylan Baker <dylan@pnwbakers.com>2019-02-27 13:10:16 -0800
commitc2db7a9ceed3286683967768e6fcc1c170c24c42 (patch)
tree21fcc3ca3be725d4208f3b50a81b06e82caa48be /mesonbuild/envconfig.py
parent2622e9ec323126edadfcd7017e6ee63c026abb9c (diff)
downloadmeson-c2db7a9ceed3286683967768e6fcc1c170c24c42.zip
meson-c2db7a9ceed3286683967768e6fcc1c170c24c42.tar.gz
meson-c2db7a9ceed3286683967768e6fcc1c170c24c42.tar.bz2
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.
Diffstat (limited to 'mesonbuild/envconfig.py')
-rw-r--r--mesonbuild/envconfig.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py
index e074d07..f2510c1 100644
--- a/mesonbuild/envconfig.py
+++ b/mesonbuild/envconfig.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