move CMAKE_PREFIX_PATH env var handling to environment

This causes the variable to be read up front and stored, rather than be
re-read on each invocation of meson.

This does have two slight behavioral changes. First is the obvious one
that changing the variable between `meson --reconfigure` invocations has
no effect. This is the way PKG_CONFIG_PATH already works. The second
change is that CMAKE_PREFIX_PATH the env var is no longer appended to
the values set in the machine file or on the command line, and is
instead replaced by them. CMAKE_PREFIX_PATH is the only env var in meson
that works this way, every other one is replaced not appended, so while
this is a behavioral change, I also think its a bug fix.
pull/8159/head
Dylan Baker 4 years ago
parent 284b89c321
commit 3949c2a0e0
  1. 18
      mesonbuild/cmake/executor.py
  2. 26
      mesonbuild/environment.py

@ -24,7 +24,6 @@ import os
from .. import mlog
from ..mesonlib import PerMachine, Popen_safe, version_compare, MachineChoice, is_windows, OptionKey
from ..envconfig import get_env_var
if T.TYPE_CHECKING:
from ..environment import Environment
@ -63,23 +62,6 @@ class CMakeExecutor:
return
self.prefix_paths = self.environment.coredata.options[OptionKey('cmake_prefix_path', machine=self.for_machine)].value
env_pref_path_raw = get_env_var(
self.for_machine,
self.environment.is_cross_build(),
'CMAKE_PREFIX_PATH')
if env_pref_path_raw is not None:
env_pref_path = [] # type: T.List[str]
if is_windows():
# Cannot split on ':' on Windows because its in the drive letter
env_pref_path = env_pref_path_raw.split(os.pathsep)
else:
# https://github.com/mesonbuild/meson/issues/7294
env_pref_path = re.split(r':|;', env_pref_path_raw)
env_pref_path = [x for x in env_pref_path if x] # Filter out empty strings
if not self.prefix_paths:
self.prefix_paths = []
self.prefix_paths += env_pref_path
if self.prefix_paths:
self.extra_cmake_args += ['-DCMAKE_PREFIX_PATH={}'.format(';'.join(self.prefix_paths))]

@ -1,4 +1,4 @@
# Copyright 2012-2016 The Meson development team
# Copyright 2012-2020 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -579,7 +579,7 @@ class Environment:
# Stores machine infos, the only *three* machine one because we have a
# target machine info on for the user (Meson never cares about the
# target machine.)
machines = PerThreeMachineDefaultable() # type: PerMachineDefaultable[MachineInfo]
machines: PerThreeMachineDefaultable[MachineInfo] = PerThreeMachineDefaultable()
# Similar to coredata.compilers, but lower level in that there is no
# meta data, only names/paths.
@ -751,14 +751,28 @@ class Environment:
def set_default_options_from_env(self) -> None:
for for_machine in MachineChoice:
for evar, keyname in [('PKG_CONFIG_PATH', 'pkg_config_path')]:
for evar, keyname in [('PKG_CONFIG_PATH', 'pkg_config_path'),
('CMAKE_PREFIX_PATH', 'cmake_prefix_path')]:
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
# PKG_CONFIG_PATH may contain duplicates, which must be
# removed, else a duplicates-in-array-option warning arises.
p_list = list(mesonlib.OrderedSet(p_env.split(':')))
# these may contain duplicates, which must be removed, else
# a duplicates-in-array-option warning arises.
if keyname == 'cmake_prefix_path':
if self.machines[for_machine].is_windows():
# Cannot split on ':' on Windows because its in the drive letter
_p_env = p_env.split(os.pathsep)
else:
# https://github.com/mesonbuild/meson/issues/7294
_p_env = re.split(r':|;', p_env)
p_list = list(mesonlib.OrderedSet(_p_env))
elif keyname == 'pkg_config_path':
p_list = list(mesonlib.OrderedSet(p_env.split(':')))
else:
raise RuntimeError('Should be unreachable')
p_list = [e for e in p_list if e] # filter out any empty eelemnts
# Take env vars only on first invocation, if the env changes when
# reconfiguring it gets ignored.
# FIXME: We should remember if we took the value from env to warn

Loading…
Cancel
Save