From b27af7e4654c3b2fe8c68a560c99fbffbd22789b Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Mon, 5 Oct 2020 20:45:21 +0200 Subject: [PATCH] cmake: Add cross tests --- .github/workflows/nonative.yml | 2 +- .travis.yml | 4 ++-- ci/travis_script.sh | 5 +++++ cross/linux-mingw-w64-32bit.json | 7 +++++++ cross/linux-mingw-w64-32bit.txt | 8 ++++++++ cross/linux-mingw-w64-64bit.json | 7 +++++++ cross/linux-mingw-w64-64bit.txt | 8 ++++++++ cross/ubuntu-armhf.json | 5 +++++ run_cross_test.py | 20 +++++++++++++++---- run_project_tests.py | 1 + .../subprojects/cmMod/CMakeLists.txt | 2 +- test cases/cmake/2 advanced/test.json | 2 -- .../cmake_project/CMakeLists.txt | 0 .../meson.build | 0 .../projectConfig.cmake.in | 0 .../test.json | 0 .../23 cmake toolchain/CMakeToolchain.cmake | 1 + .../cmake/23 cmake toolchain/meson.build | 9 +++++++++ .../23 cmake toolchain/nativefile.ini.in | 8 ++++++++ .../subprojects/cmMod/CMakeLists.txt | 11 ++++++++++ .../subprojects/cmMod/CMakeLists.txt | 2 +- test cases/cmake/3 advanced no dep/test.json | 3 --- .../subprojects/cmCodeGen/CMakeLists.txt | 1 + test cases/cmake/7 cmake options/test.json | 3 +++ 24 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 cross/linux-mingw-w64-32bit.json create mode 100644 cross/linux-mingw-w64-64bit.json create mode 100644 cross/ubuntu-armhf.json rename test cases/cmake/{211 cmake module => 22 cmake module}/cmake_project/CMakeLists.txt (100%) rename test cases/cmake/{211 cmake module => 22 cmake module}/meson.build (100%) rename test cases/cmake/{211 cmake module => 22 cmake module}/projectConfig.cmake.in (100%) rename test cases/cmake/{211 cmake module => 22 cmake module}/test.json (100%) create mode 100644 test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake create mode 100644 test cases/cmake/23 cmake toolchain/meson.build create mode 100644 test cases/cmake/23 cmake toolchain/nativefile.ini.in create mode 100644 test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt diff --git a/.github/workflows/nonative.yml b/.github/workflows/nonative.yml index 59386c530..44eeb9e52 100644 --- a/.github/workflows/nonative.yml +++ b/.github/workflows/nonative.yml @@ -16,4 +16,4 @@ jobs: apt-get -y autoremove - uses: actions/checkout@v2 - name: Run tests - run: bash -c 'source /ci/env_vars.sh; cd $GITHUB_WORKSPACE; ./run_tests.py $CI_ARGS --cross ubuntu-armhf.txt --cross-only' + run: bash -c 'source /ci/env_vars.sh; cd $GITHUB_WORKSPACE; ./run_tests.py $CI_ARGS --cross ubuntu-armhf.json --cross-only' diff --git a/.travis.yml b/.travis.yml index 22d76e7ea..ab317be15 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,10 +34,10 @@ matrix: # Also hijack one cross build to test long commandline handling codepath (and avoid overloading Travis) - os: linux compiler: gcc - env: RUN_TESTS_ARGS="--cross ubuntu-armhf.txt --cross linux-mingw-w64-64bit.txt" MESON_RSP_THRESHOLD=0 + env: RUN_TESTS_ARGS="--cross ubuntu-armhf.json --cross linux-mingw-w64-64bit.json" MESON_RSP_THRESHOLD=0 - os: linux compiler: gcc - env: RUN_TESTS_ARGS="--cross ubuntu-armhf.txt --cross linux-mingw-w64-64bit.txt" MESON_ARGS="--unity=on" + env: RUN_TESTS_ARGS="--cross ubuntu-armhf.json --cross linux-mingw-w64-64bit.json" MESON_ARGS="--unity=on" before_install: - python ./skip_ci.py --base-branch-env=TRAVIS_BRANCH --is-pull-env=TRAVIS_PULL_REQUEST diff --git a/ci/travis_script.sh b/ci/travis_script.sh index bdfd4c202..7e26b5232 100755 --- a/ci/travis_script.sh +++ b/ci/travis_script.sh @@ -31,6 +31,11 @@ fi source /ci/env_vars.sh cd /root +update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix +update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix +update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix +update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix + ./run_tests.py $RUN_TESTS_ARGS -- $MESON_ARGS #./upload.sh diff --git a/cross/linux-mingw-w64-32bit.json b/cross/linux-mingw-w64-32bit.json new file mode 100644 index 000000000..476111183 --- /dev/null +++ b/cross/linux-mingw-w64-32bit.json @@ -0,0 +1,7 @@ +{ + "file": "linux-mingw-w64-32bit.txt", + "tests": ["common", "cmake"], + "env": { + "WINEPATH": "/usr/lib/gcc/i686-w64-mingw32/9.2-posix;/usr/i686-w64-mingw32/bin;/usr/i686-w64-mingw32/lib" + } +} diff --git a/cross/linux-mingw-w64-32bit.txt b/cross/linux-mingw-w64-32bit.txt index c2ea605b8..a62f57f9b 100644 --- a/cross/linux-mingw-w64-32bit.txt +++ b/cross/linux-mingw-w64-32bit.txt @@ -19,3 +19,11 @@ system = 'windows' cpu_family = 'x86' cpu = 'i686' endian = 'little' + +[cmake] + +CMAKE_BUILD_WITH_INSTALL_RPATH = 'ON' +CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = 'NEVER' +CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = 'ONLY' +CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = 'ONLY' +CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = 'ONLY' diff --git a/cross/linux-mingw-w64-64bit.json b/cross/linux-mingw-w64-64bit.json new file mode 100644 index 000000000..df344da9d --- /dev/null +++ b/cross/linux-mingw-w64-64bit.json @@ -0,0 +1,7 @@ +{ + "file": "linux-mingw-w64-64bit.txt", + "tests": ["common", "cmake"], + "env": { + "WINEPATH": "/usr/lib/gcc/x86_64-w64-mingw32/9.2-posix;/usr/x86_64-w64-mingw32/bin;/usr/x86_64-w64-mingw32/lib" + } +} diff --git a/cross/linux-mingw-w64-64bit.txt b/cross/linux-mingw-w64-64bit.txt index 1c5c00238..36d73500a 100644 --- a/cross/linux-mingw-w64-64bit.txt +++ b/cross/linux-mingw-w64-64bit.txt @@ -18,3 +18,11 @@ system = 'windows' cpu_family = 'x86_64' cpu = 'x86_64' endian = 'little' + +[cmake] + +CMAKE_BUILD_WITH_INSTALL_RPATH = 'ON' +CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = 'NEVER' +CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = 'ONLY' +CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = 'ONLY' +CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = 'ONLY' diff --git a/cross/ubuntu-armhf.json b/cross/ubuntu-armhf.json new file mode 100644 index 000000000..40f5619c2 --- /dev/null +++ b/cross/ubuntu-armhf.json @@ -0,0 +1,5 @@ +{ + "file": "ubuntu-armhf.txt", + "tests": ["common"], + "env": {} +} diff --git a/run_cross_test.py b/run_cross_test.py index 836cf3165..5ce3e5528 100755 --- a/run_cross_test.py +++ b/run_cross_test.py @@ -23,10 +23,13 @@ import argparse import subprocess from mesonbuild import mesonlib from mesonbuild.coredata import version as meson_version +from pathlib import Path +import json +import os -def runtests(cross_file, failfast, cross_only): - tests = ['--only', 'common'] +def runtests(cross_file, failfast, cross_only, test_list, env=None): + tests = ['--only'] + test_list if not cross_only: tests.append('native') cmd = mesonlib.python_command + ['run_project_tests.py', '--backend', 'ninja'] @@ -36,7 +39,7 @@ def runtests(cross_file, failfast, cross_only): cmd += ['--cross-file', cross_file] if cross_only: cmd += ['--native-file', 'cross/none.txt'] - return subprocess.call(cmd) + return subprocess.call(cmd, env=env) def main(): parser = argparse.ArgumentParser() @@ -44,7 +47,16 @@ def main(): parser.add_argument('--cross-only', action='store_true') parser.add_argument('cross_file') options = parser.parse_args() - return runtests(options.cross_file, options.failfast, options.cross_only) + cf_path = Path(options.cross_file) + try: + data = json.loads(cf_path.read_text()) + real_cf = cf_path.resolve().parent / data['file'] + assert real_cf.exists() + env = os.environ.copy() + env.update(data['env']) + return runtests(real_cf.as_posix(), options.failfast, options.cross_only, data['tests'], env=env) + except Exception: + return runtests(options.cross_file, options.failfast, options.cross_only, ['common']) if __name__ == '__main__': print('Meson build system', meson_version, 'Cross Tests') diff --git a/run_project_tests.py b/run_project_tests.py index 87499570e..037ba4218 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -1163,6 +1163,7 @@ def check_format(): '.dub', # external deps are here '.pytest_cache', 'meson-logs', 'meson-private', + 'work area', '.eggs', '_cache', # e.g. .mypy_cache 'venv', # virtualenvs have DOS line endings } diff --git a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt index c9b2a208f..7fce89e25 100644 --- a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt +++ b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt @@ -25,4 +25,4 @@ target_link_libraries(testEXE cmModLib) target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE) -install(TARGETS cmModLib testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin) +install(TARGETS testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin) diff --git a/test cases/cmake/2 advanced/test.json b/test cases/cmake/2 advanced/test.json index ff3d5a73d..e2d9c051f 100644 --- a/test cases/cmake/2 advanced/test.json +++ b/test cases/cmake/2 advanced/test.json @@ -1,7 +1,5 @@ { "installed": [ - {"type": "expr", "file": "usr/?lib/libcm_cmModLib?so"}, - {"type": "implib", "file": "usr/lib/libcm_cmModLib"}, {"type": "exe", "file": "usr/bin/cm_testEXE"} ], "tools": { diff --git a/test cases/cmake/211 cmake module/cmake_project/CMakeLists.txt b/test cases/cmake/22 cmake module/cmake_project/CMakeLists.txt similarity index 100% rename from test cases/cmake/211 cmake module/cmake_project/CMakeLists.txt rename to test cases/cmake/22 cmake module/cmake_project/CMakeLists.txt diff --git a/test cases/cmake/211 cmake module/meson.build b/test cases/cmake/22 cmake module/meson.build similarity index 100% rename from test cases/cmake/211 cmake module/meson.build rename to test cases/cmake/22 cmake module/meson.build diff --git a/test cases/cmake/211 cmake module/projectConfig.cmake.in b/test cases/cmake/22 cmake module/projectConfig.cmake.in similarity index 100% rename from test cases/cmake/211 cmake module/projectConfig.cmake.in rename to test cases/cmake/22 cmake module/projectConfig.cmake.in diff --git a/test cases/cmake/211 cmake module/test.json b/test cases/cmake/22 cmake module/test.json similarity index 100% rename from test cases/cmake/211 cmake module/test.json rename to test cases/cmake/22 cmake module/test.json diff --git a/test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake b/test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake new file mode 100644 index 000000000..ab5fbace1 --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake @@ -0,0 +1 @@ +set(MESON_TEST_VAR2 VAR2) diff --git a/test cases/cmake/23 cmake toolchain/meson.build b/test cases/cmake/23 cmake toolchain/meson.build new file mode 100644 index 000000000..98f8d21df --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/meson.build @@ -0,0 +1,9 @@ +project('cmake toolchain test', ['c', 'cpp']) + +if meson.is_cross_build() + error('MESON_SKIP_TEST: skip this on cross builds') +endif + +cm = import('cmake') + +sub_pro = cm.subproject('cmMod') diff --git a/test cases/cmake/23 cmake toolchain/nativefile.ini.in b/test cases/cmake/23 cmake toolchain/nativefile.ini.in new file mode 100644 index 000000000..2cd6e947a --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/nativefile.ini.in @@ -0,0 +1,8 @@ +[properties] + +cmake_toolchain_file = '@MESON_TEST_ROOT@/CMakeToolchain.cmake' + +[cmake] + +MESON_TEST_VAR1 = 'VAR1 space' +MESON_TEST_VAR2 = 'VAR2 error' diff --git a/test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt new file mode 100644 index 000000000..8aeabc2a2 --- /dev/null +++ b/test cases/cmake/23 cmake toolchain/subprojects/cmMod/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmMod) + +if(NOT "${MESON_TEST_VAR1}" STREQUAL "VAR1 space") + message(FATAL_ERROR "MESON_TEST_VAR1 -- '${MESON_TEST_VAR1}' != 'VAR1 space'") +endif() + +if(NOT "${MESON_TEST_VAR2}" STREQUAL "VAR2") + message(FATAL_ERROR "MESON_TEST_VAR2 -- '${MESON_TEST_VAR2}' != 'VAR2'") +endif() diff --git a/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt index 4c782cb38..026d4c103 100644 --- a/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt +++ b/test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt @@ -23,4 +23,4 @@ target_link_libraries(testEXE2 cmModLib) target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE) -install(TARGETS cmModLib testEXE testEXE2 LIBRARY DESTINATION lib RUNTIME DESTINATION bin) +install(TARGETS testEXE testEXE2 LIBRARY DESTINATION lib RUNTIME DESTINATION bin) diff --git a/test cases/cmake/3 advanced no dep/test.json b/test cases/cmake/3 advanced no dep/test.json index af25a8ec6..4b266c320 100644 --- a/test cases/cmake/3 advanced no dep/test.json +++ b/test cases/cmake/3 advanced no dep/test.json @@ -1,8 +1,5 @@ { "installed": [ - {"type": "expr", "file": "usr/?lib/libcm_cmModLib?so"}, - {"type": "implib", "file": "usr/lib/libcm_cmModLib"}, - {"type": "pdb", "file": "usr/bin/cm_cmModLib"}, {"type": "pdb", "file": "usr/bin/cm_testEXE"}, {"type": "exe", "file": "usr/bin/cm_testEXE"}, {"type": "pdb", "file": "usr/bin/cm_testEXE2"}, diff --git a/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt b/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt index 268743c73..ff50e54d5 100644 --- a/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt +++ b/test cases/cmake/4 code gen/subprojects/cmCodeGen/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.7) +project(CMCodeGen) set(CMAKE_CXX_STANDARD 14) add_executable(genA main.cpp) diff --git a/test cases/cmake/7 cmake options/test.json b/test cases/cmake/7 cmake options/test.json index 046e2ee4c..f9f0b05a7 100644 --- a/test cases/cmake/7 cmake options/test.json +++ b/test cases/cmake/7 cmake options/test.json @@ -3,6 +3,9 @@ "options": { "cmake_prefix_path": [ { "val": ["val1", "val2"] } + ], + "build.cmake_prefix_path": [ + { "val": ["val1", "val2"] } ] } }