Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
cmake: Add cross tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mensinda committed Oct 13, 2020
1 parent 7e58f33 commit b27af7e
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nonative.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ci/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions cross/linux-mingw-w64-32bit.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions cross/linux-mingw-w64-32bit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
7 changes: 7 additions & 0 deletions cross/linux-mingw-w64-64bit.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions cross/linux-mingw-w64-64bit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
5 changes: 5 additions & 0 deletions cross/ubuntu-armhf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"file": "ubuntu-armhf.txt",
"tests": ["common"],
"env": {}
}
20 changes: 16 additions & 4 deletions run_cross_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
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']
Expand All @@ -36,15 +39,24 @@ 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()
parser.add_argument('--failfast', action='store_true')
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')
Expand Down
1 change: 1 addition & 0 deletions run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 0 additions & 2 deletions test cases/cmake/2 advanced/test.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 1 addition & 0 deletions test cases/cmake/23 cmake toolchain/CMakeToolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(MESON_TEST_VAR2 VAR2)
9 changes: 9 additions & 0 deletions test cases/cmake/23 cmake toolchain/meson.build
Original file line number Diff line number Diff line change
@@ -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')
8 changes: 8 additions & 0 deletions test cases/cmake/23 cmake toolchain/nativefile.ini.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[properties]

cmake_toolchain_file = '@MESON_TEST_ROOT@/CMakeToolchain.cmake'

[cmake]

MESON_TEST_VAR1 = 'VAR1 space'
MESON_TEST_VAR2 = 'VAR2 error'
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 0 additions & 3 deletions test cases/cmake/3 advanced no dep/test.json
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.7)

project(CMCodeGen)
set(CMAKE_CXX_STANDARD 14)

add_executable(genA main.cpp)
3 changes: 3 additions & 0 deletions test cases/cmake/7 cmake options/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"options": {
"cmake_prefix_path": [
{ "val": ["val1", "val2"] }
],
"build.cmake_prefix_path": [
{ "val": ["val1", "val2"] }
]
}
}
Expand Down

0 comments on commit b27af7e

Please sign in to comment.