cmake: add PATH logic to preliminary dep check (fixes #8133)
This commit is contained in:
parent
a8c138ebc1
commit
8f1d9bb7b0
|
@ -219,8 +219,12 @@ Exanple `test.json`:
|
|||
#### env
|
||||
|
||||
The `env` key contains a dictionary which specifies additional
|
||||
environment variables to be set during the configure step of the test. `@ROOT@`
|
||||
is replaced with the absolute path of the source directory.
|
||||
environment variables to be set during the configure step of the test.
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -1186,7 +1186,12 @@ class CMakeDependency(ExternalDependency):
|
|||
return None
|
||||
|
||||
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]
|
||||
return set(l)
|
||||
|
||||
|
@ -1290,8 +1295,17 @@ class CMakeDependency(ExternalDependency):
|
|||
if search_lib_dirs(i):
|
||||
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
|
||||
for i in self.cmakeinfo['module_paths']:
|
||||
for i in self.cmakeinfo['module_paths'] + system_env:
|
||||
if find_module(i):
|
||||
return True
|
||||
|
||||
|
|
|
@ -653,6 +653,7 @@ def gather_tests(testdir: Path, stdout_mandatory: bool) -> T.List[TestDef]:
|
|||
env = test_def['env']
|
||||
for key, val in env.items():
|
||||
val = val.replace('@ROOT@', t.path.resolve().as_posix())
|
||||
val = val.replace('@PATH@', t.env.get('PATH', ''))
|
||||
env[key] = val
|
||||
|
||||
# Handle installed files
|
||||
|
|
|
@ -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()
|
|
@ -46,6 +46,7 @@ assert(depf2.found() == false, 'Invalid CMake targets should fail')
|
|||
depPrefEnv = dependency('cmMesonTestDep', required : true, method : 'cmake')
|
||||
depPrefEnv1 = dependency('cmMesonTestF1', 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
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"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@"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue