cmake: add PATH logic to preliminary dep check (fixes #8133)

This commit is contained in:
Daniel Mensinger 2020-12-30 10:40:25 +01:00 committed by Jussi Pakkanen
parent a8c138ebc1
commit 8f1d9bb7b0
7 changed files with 35 additions and 5 deletions

View File

@ -219,8 +219,12 @@ Exanple `test.json`:
#### env #### env
The `env` key contains a dictionary which specifies additional The `env` key contains a dictionary which specifies additional
environment variables to be set during the configure step of the test. `@ROOT@` environment variables to be set during the configure step of the test.
is replaced with the absolute path of the source directory.
There is some basic support for configuring the string with the `@<VAR>@` syntax:
- `@ROOT@`: absolute path of the source directory
- `@PATH@`: current value of the `PATH` env variable
#### installed #### installed

View File

@ -1186,7 +1186,12 @@ class CMakeDependency(ExternalDependency):
return None return None
def process_paths(l: T.List[str]) -> T.Set[str]: def process_paths(l: T.List[str]) -> T.Set[str]:
l = [x.split(':') for x in l] if mesonlib.is_windows():
# Cannot split on ':' on Windows because its in the drive letter
l = [x.split(os.pathsep) for x in l]
else:
# https://github.com/mesonbuild/meson/issues/7294
l = [re.split(r':|;', x) for x in l]
l = [x for sublist in l for x in sublist] l = [x for sublist in l for x in sublist]
return set(l) return set(l)
@ -1290,8 +1295,17 @@ class CMakeDependency(ExternalDependency):
if search_lib_dirs(i): if search_lib_dirs(i):
return True return True
# Check PATH
system_env = [] # type: T.List[str]
for i in os.environ.get('PATH', '').split(os.pathsep):
if i.endswith('/bin') or i.endswith('\\bin'):
i = i[:-4]
if i.endswith('/sbin') or i.endswith('\\sbin'):
i = i[:-5]
system_env += [i]
# Check the system paths # Check the system paths
for i in self.cmakeinfo['module_paths']: for i in self.cmakeinfo['module_paths'] + system_env:
if find_module(i): if find_module(i):
return True return True

View File

@ -653,6 +653,7 @@ def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
env = test_def['env'] env = test_def['env']
for key, val in env.items(): for key, val in env.items():
val = val.replace('@ROOT@', t.path.resolve().as_posix()) val = val.replace('@ROOT@', t.path.resolve().as_posix())
val = val.replace('@PATH@', t.env.get('PATH', ''))
env[key] = val env[key] = val
# Handle installed files # Handle installed files

View File

@ -0,0 +1,9 @@
find_package(ZLIB)
if(ZLIB_FOUND OR ZLIB_Found)
set(cmMesonTestF3_FOUND ON)
set(cmMesonTestF3_LIBRARIES ${ZLIB_LIBRARY})
set(cmMesonTestF3_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
else()
set(cmMesonTestF3_FOUND OFF)
endif()

View File

@ -46,6 +46,7 @@ assert(depf2.found() == false, 'Invalid CMake targets should fail')
depPrefEnv = dependency('cmMesonTestDep', required : true, method : 'cmake') depPrefEnv = dependency('cmMesonTestDep', required : true, method : 'cmake')
depPrefEnv1 = dependency('cmMesonTestF1', required : true, method : 'cmake') depPrefEnv1 = dependency('cmMesonTestF1', required : true, method : 'cmake')
depPrefEnv2 = dependency('cmMesonTestF2', required : true, method : 'cmake') depPrefEnv2 = dependency('cmMesonTestF2', required : true, method : 'cmake')
depPrefEnv3 = dependency('cmMesonTestF3', required : true, method : 'cmake')
# Try to find a dependency with a custom CMake module # Try to find a dependency with a custom CMake module

View File

@ -1,5 +1,6 @@
{ {
"env": { "env": {
"CMAKE_PREFIX_PATH": "@ROOT@/cmake_fake1;@ROOT@/cmake_fake2:@ROOT@/cmake_pref_env" "CMAKE_PREFIX_PATH": "@ROOT@/cmake_fake1;@ROOT@/cmake_fake2:@ROOT@/cmake_pref_env",
"PATH": "@ROOT@/cmake_fake3/bin:@PATH@"
} }
} }