aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/environment.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-12-11 12:30:19 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-01-11 11:15:07 -0800
commite7a5c75285ce63a7197cd82e893450eb9bb68b6c (patch)
tree1fc774c47d7d709e91e0de441e889b245bba66c0 /mesonbuild/environment.py
parent38c7a7590c25426dfd2d480d805d570d7e645096 (diff)
downloadmeson-e7a5c75285ce63a7197cd82e893450eb9bb68b6c.zip
meson-e7a5c75285ce63a7197cd82e893450eb9bb68b6c.tar.gz
meson-e7a5c75285ce63a7197cd82e893450eb9bb68b6c.tar.bz2
Move BinaryTable environment lookups to Environment
This means that all the env lookups are done once, at initial configure time. This has all of the expected advantages.
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r--mesonbuild/environment.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 12b9dbb..6275da0 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -29,7 +29,7 @@ from .mesonlib import (
from . import mlog
from .envconfig import (
- BinaryTable, MachineInfo,
+ BinaryTable, ENV_VAR_PROG_MAP, MachineInfo,
Properties, known_cpu_families, get_env_var_pair,
CMakeVariables,
)
@@ -129,6 +129,7 @@ from .compilers import (
VisualStudioCCompiler,
VisualStudioCPPCompiler,
)
+from mesonbuild import envconfig
if T.TYPE_CHECKING:
from configparser import ConfigParser
@@ -654,6 +655,7 @@ class Environment:
# Take default value from env if not set in cross/native files or command line.
self.set_default_options_from_env()
+ self._set_default_binaries_from_env()
# Warn if the user is using two different ways of setting build-type
# options that override each other
@@ -804,6 +806,21 @@ class Environment:
v = mesonlib.listify(self.options.get(key, []))
self.options.setdefault(key, v + p_list)
+ def _set_default_binaries_from_env(self) -> None:
+ """Set default binaries from the environment.
+
+ For example, pkg-config can be set via PKG_CONFIG, or in the machine
+ file. We want to set the default to the env variable.
+ """
+ opts = itertools.chain(envconfig.DEPRECATED_ENV_PROG_MAP.items(),
+ envconfig.ENV_VAR_PROG_MAP.items())
+
+ for (name, evar), for_machine in itertools.product(opts, MachineChoice):
+ p_env_pair = get_env_var_pair(for_machine, self.is_cross_build(), evar)
+ if p_env_pair is not None:
+ _, p_env = p_env_pair
+ self.binaries[for_machine].binaries.setdefault(name, mesonlib.split_args(p_env))
+
def create_new_coredata(self, options: 'argparse.Namespace') -> None:
# WARNING: Don't use any values from coredata in __init__. It gets
# re-initialized with project options by the interpreter during
@@ -853,11 +870,8 @@ class Environment:
def is_library(self, fname):
return is_library(fname)
- def lookup_binary_entry(self, for_machine: MachineChoice, name: str):
- return self.binaries[for_machine].lookup_entry(
- for_machine,
- self.is_cross_build(),
- name)
+ def lookup_binary_entry(self, for_machine: MachineChoice, name: str) -> T.List[str]:
+ return self.binaries[for_machine].lookup_entry(name)
@staticmethod
def get_gnu_compiler_defines(compiler):