cmake: added test case for environment variables

pull/5687/head
Daniel Mensinger 5 years ago committed by Nirbheek Chauhan
parent e2499fab8b
commit 3b2126531a
  1. 12
      run_project_tests.py
  2. 17
      run_tests.py
  3. 9
      test cases/linuxlike/13 cmake dependency/cmake_pref_env/lib/cmake/cmMesonTestDep/cmMesonTestDepConfig.cmake
  4. 4
      test cases/linuxlike/13 cmake dependency/meson.build
  5. 3
      test cases/linuxlike/13 cmake dependency/setup_env.json

@ -35,6 +35,7 @@ from mesonbuild import mtest
from mesonbuild.mesonlib import MachineChoice, stringlistify, Popen_safe
from mesonbuild.coredata import backendlist
import argparse
import json
import xml.etree.ElementTree as ET
import time
import multiprocessing
@ -348,6 +349,7 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen
compile_commands, clean_commands, install_commands, uninstall_commands = commands
test_args = parse_test_args(testdir)
gen_start = time.time()
setup_env = None
# Configure in-process
if pass_prefix_to_test(testdir):
gen_args = ['--prefix', '/usr']
@ -362,7 +364,15 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen
crossfile = os.path.join(testdir, 'crossfile.ini')
if os.path.exists(crossfile):
gen_args.extend(['--cross-file', crossfile])
(returncode, stdo, stde) = run_configure(gen_args)
setup_env_file = os.path.join(testdir, 'setup_env.json')
if os.path.exists(setup_env_file):
setup_env = os.environ.copy()
with open(setup_env_file, 'r') as fp:
data = json.load(fp)
for key, val in data.items():
val = val.replace('@ROOT@', os.path.abspath(testdir))
setup_env[key] = val
(returncode, stdo, stde) = run_configure(gen_args, env=setup_env)
try:
logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt')
mesonlog = logfile.open(errors='ignore', encoding='utf-8').read()

@ -222,28 +222,33 @@ def clear_meson_configure_class_caches():
mesonbuild.dependencies.PkgConfigDependency.pkgbin_cache = {}
mesonbuild.dependencies.PkgConfigDependency.class_pkgbin = mesonlib.PerMachine(None, None)
def run_configure_inprocess(commandlist):
def run_configure_inprocess(commandlist, env=None):
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
old_stderr = sys.stderr
sys.stderr = mystderr = StringIO()
old_environ = os.environ.copy()
if env is not None:
os.environ.update(env)
try:
returncode = mesonmain.run(commandlist, get_meson_script())
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
clear_meson_configure_class_caches()
os.environ.clear()
os.environ.update(old_environ)
return returncode, mystdout.getvalue(), mystderr.getvalue()
def run_configure_external(full_command):
pc, o, e = mesonlib.Popen_safe(full_command)
def run_configure_external(full_command, env=None):
pc, o, e = mesonlib.Popen_safe(full_command, env=env)
return pc.returncode, o, e
def run_configure(commandlist):
def run_configure(commandlist, env=None):
global meson_exe
if meson_exe:
return run_configure_external(meson_exe + commandlist)
return run_configure_inprocess(commandlist)
return run_configure_external(meson_exe + commandlist, env=env)
return run_configure_inprocess(commandlist, env=env)
def print_system_info():
print(mlog.bold('System information.').get_text(mlog.colorize_console))

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

@ -36,6 +36,10 @@ depf2 = dependency('ZLIB', required : false, method : 'cmake', modules : 'dfggh:
assert(depf2.found() == false, 'Invalid CMake targets should fail')
# Try to find cmMesonTestDep in a custom prefix
depPrefEnv = dependency('cmMesonTestDep', required : true, method : 'cmake')
# Try to find a dependency with a custom CMake module
depm1 = dependency('SomethingLikeZLIB', required : true, method : 'cmake', cmake_module_path : 'cmake')

@ -0,0 +1,3 @@
{
"CMAKE_PREFIX_PATH": "@ROOT@/cmake_pref_env"
}
Loading…
Cancel
Save