diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-03-25 15:13:18 -0700 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2021-05-28 09:26:38 -0400 |
commit | a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7 (patch) | |
tree | 49f9a3afdca15e688a12ddc68f1e1e33939b5cb1 /mesonbuild/mesonlib/universal.py | |
parent | 336f2f88358ad369478e4261bdfed1bc5707df36 (diff) | |
download | meson-a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7.zip meson-a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7.tar.gz meson-a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7.tar.bz2 |
Add a helper to simplify the usage of PerMachineDefaultable
Diffstat (limited to 'mesonbuild/mesonlib/universal.py')
-rw-r--r-- | mesonbuild/mesonlib/universal.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index 684d223..66149f9 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -547,6 +547,21 @@ class PerMachineDefaultable(PerMachine[T.Optional[_T]]): def __repr__(self) -> str: return f'PerMachineDefaultable({self.build!r}, {self.host!r})' + @classmethod + def default(cls, is_cross: bool, build: _T, host: _T) -> PerMachine[_T]: + """Easy way to get a defaulted value + + This allows simplifying the case where you can control whether host and + build are separate or not with a boolean. If the is_cross value is set + to true then the optional host value will be used, otherwise the host + will be set to the build value. + """ + m = cls(build) + if is_cross: + m.host = host + return m.default_missing() + + class PerThreeMachineDefaultable(PerMachineDefaultable, PerThreeMachine[T.Optional[_T]]): """Extends `PerThreeMachine` with the ability to default from `None`s. |