aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-03-25 15:13:18 -0700
committerXavier Claessens <xclaesse@gmail.com>2021-05-28 09:26:38 -0400
commita5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7 (patch)
tree49f9a3afdca15e688a12ddc68f1e1e33939b5cb1 /mesonbuild
parent336f2f88358ad369478e4261bdfed1bc5707df36 (diff)
downloadmeson-a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7.zip
meson-a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7.tar.gz
meson-a5b43aa16cab6c97273a4c645fd6c2f0a90bf1b7.tar.bz2
Add a helper to simplify the usage of PerMachineDefaultable
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/build.py29
-rw-r--r--mesonbuild/coredata.py9
-rw-r--r--mesonbuild/mesonlib/universal.py15
3 files changed, 29 insertions, 24 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index a60b2b7..13eb0c1 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -206,21 +206,14 @@ class Build:
self.projects = {}
self.targets: T.MutableMapping[str, 'Target'] = OrderedDict()
self.run_target_names: T.Set[T.Tuple[str, str]] = set()
-
- global_args: PerMachineDefaultable[T.Dict[str, T.List[str]]] = PerMachineDefaultable({})
- global_link_args: PerMachineDefaultable[T.Dict[str, T.List[str]]] = PerMachineDefaultable({})
- project_args: PerMachineDefaultable[T.Dict[str, T.List[str]]] = PerMachineDefaultable({})
- project_link_args: PerMachineDefaultable[T.Dict[str, T.List[str]]] = PerMachineDefaultable({})
- if environment.is_cross_build():
- global_args.host = {}
- global_link_args.host = {}
- project_args.host = {}
- project_link_args.host = {}
- self.global_args = global_args.default_missing()
- self.projects_args = project_args.default_missing()
- self.global_link_args = global_link_args.default_missing()
- self.projects_link_args = project_link_args.default_missing()
-
+ self.global_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachineDefaultable.default(
+ environment.is_cross_build(), {}, {})
+ self.global_link_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachineDefaultable.default(
+ environment.is_cross_build(), {}, {})
+ self.projects_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachineDefaultable.default(
+ environment.is_cross_build(), {}, {})
+ self.projects_link_args: PerMachine[T.Dict[str, T.List[str]]] = PerMachineDefaultable.default(
+ environment.is_cross_build(), {}, {})
self.tests: T.List['Test'] = []
self.benchmarks: T.List['Test'] = []
self.headers: T.List[Headers] = []
@@ -243,10 +236,8 @@ class Build:
# If we are doing a cross build we need two caches, if we're doing a
# build == host compilation the both caches should point to the same place.
- dependency_overrides: PerMachineDefaultable[T.Dict[T.Tuple, DependencyOverride]] = PerMachineDefaultable({})
- if environment.is_cross_build():
- dependency_overrides.host = {}
- self.dependency_overrides = dependency_overrides.default_missing()
+ self.dependency_overrides: PerMachine[T.Dict[T.Tuple, DependencyOverride]] = PerMachineDefaultable.default(
+ environment.is_cross_build(), {}, {})
self.devenv: T.List[EnvironmentVariables] = []
def get_build_targets(self):
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 7f94d18..5e726a4 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -407,11 +407,10 @@ class CoreData:
self.initialized_subprojects: T.Set[str] = set()
# For host == build configuraitons these caches should be the same.
- deps: PerMachineDefaultable[DependencyCache] = PerMachineDefaultable(
- DependencyCache(self.options, MachineChoice.BUILD))
- if self.is_cross_build():
- deps.host = DependencyCache(self.options, MachineChoice.HOST)
- self.deps = deps.default_missing()
+ self.deps: PerMachine[DependencyCache] = PerMachineDefaultable.default(
+ self.is_cross_build(),
+ DependencyCache(self.options, MachineChoice.BUILD),
+ DependencyCache(self.options, MachineChoice.HOST))
self.compiler_check_cache = OrderedDict() # type: T.Dict[CompilerCheckCacheKey, compiler.CompileResult]
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.