Skip to content

Commit b27af7e

Browse files
committed
cmake: Add cross tests
1 parent 7e58f33 commit b27af7e

File tree

24 files changed

+95
-14
lines changed

24 files changed

+95
-14
lines changed

.github/workflows/nonative.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
apt-get -y autoremove
1717
- uses: actions/checkout@v2
1818
- name: Run tests
19-
run: bash -c 'source /ci/env_vars.sh; cd $GITHUB_WORKSPACE; ./run_tests.py $CI_ARGS --cross ubuntu-armhf.txt --cross-only'
19+
run: bash -c 'source /ci/env_vars.sh; cd $GITHUB_WORKSPACE; ./run_tests.py $CI_ARGS --cross ubuntu-armhf.json --cross-only'

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ matrix:
3434
# Also hijack one cross build to test long commandline handling codepath (and avoid overloading Travis)
3535
- os: linux
3636
compiler: gcc
37-
env: RUN_TESTS_ARGS="--cross ubuntu-armhf.txt --cross linux-mingw-w64-64bit.txt" MESON_RSP_THRESHOLD=0
37+
env: RUN_TESTS_ARGS="--cross ubuntu-armhf.json --cross linux-mingw-w64-64bit.json" MESON_RSP_THRESHOLD=0
3838
- os: linux
3939
compiler: gcc
40-
env: RUN_TESTS_ARGS="--cross ubuntu-armhf.txt --cross linux-mingw-w64-64bit.txt" MESON_ARGS="--unity=on"
40+
env: RUN_TESTS_ARGS="--cross ubuntu-armhf.json --cross linux-mingw-w64-64bit.json" MESON_ARGS="--unity=on"
4141

4242
before_install:
4343
- python ./skip_ci.py --base-branch-env=TRAVIS_BRANCH --is-pull-env=TRAVIS_PULL_REQUEST

ci/travis_script.sh

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ fi
3131
source /ci/env_vars.sh
3232
cd /root
3333
34+
update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
35+
update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
36+
update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
37+
update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
38+
3439
./run_tests.py $RUN_TESTS_ARGS -- $MESON_ARGS
3540
#./upload.sh
3641

cross/linux-mingw-w64-32bit.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"file": "linux-mingw-w64-32bit.txt",
3+
"tests": ["common", "cmake"],
4+
"env": {
5+
"WINEPATH": "/usr/lib/gcc/i686-w64-mingw32/9.2-posix;/usr/i686-w64-mingw32/bin;/usr/i686-w64-mingw32/lib"
6+
}
7+
}

cross/linux-mingw-w64-32bit.txt

+8
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ system = 'windows'
1919
cpu_family = 'x86'
2020
cpu = 'i686'
2121
endian = 'little'
22+
23+
[cmake]
24+
25+
CMAKE_BUILD_WITH_INSTALL_RPATH = 'ON'
26+
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = 'NEVER'
27+
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = 'ONLY'
28+
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = 'ONLY'
29+
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = 'ONLY'

cross/linux-mingw-w64-64bit.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"file": "linux-mingw-w64-64bit.txt",
3+
"tests": ["common", "cmake"],
4+
"env": {
5+
"WINEPATH": "/usr/lib/gcc/x86_64-w64-mingw32/9.2-posix;/usr/x86_64-w64-mingw32/bin;/usr/x86_64-w64-mingw32/lib"
6+
}
7+
}

cross/linux-mingw-w64-64bit.txt

+8
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ system = 'windows'
1818
cpu_family = 'x86_64'
1919
cpu = 'x86_64'
2020
endian = 'little'
21+
22+
[cmake]
23+
24+
CMAKE_BUILD_WITH_INSTALL_RPATH = 'ON'
25+
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = 'NEVER'
26+
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = 'ONLY'
27+
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = 'ONLY'
28+
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = 'ONLY'

cross/ubuntu-armhf.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"file": "ubuntu-armhf.txt",
3+
"tests": ["common"],
4+
"env": {}
5+
}

run_cross_test.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
import subprocess
2424
from mesonbuild import mesonlib
2525
from mesonbuild.coredata import version as meson_version
26+
from pathlib import Path
27+
import json
28+
import os
2629

2730

28-
def runtests(cross_file, failfast, cross_only):
29-
tests = ['--only', 'common']
31+
def runtests(cross_file, failfast, cross_only, test_list, env=None):
32+
tests = ['--only'] + test_list
3033
if not cross_only:
3134
tests.append('native')
3235
cmd = mesonlib.python_command + ['run_project_tests.py', '--backend', 'ninja']
@@ -36,15 +39,24 @@ def runtests(cross_file, failfast, cross_only):
3639
cmd += ['--cross-file', cross_file]
3740
if cross_only:
3841
cmd += ['--native-file', 'cross/none.txt']
39-
return subprocess.call(cmd)
42+
return subprocess.call(cmd, env=env)
4043

4144
def main():
4245
parser = argparse.ArgumentParser()
4346
parser.add_argument('--failfast', action='store_true')
4447
parser.add_argument('--cross-only', action='store_true')
4548
parser.add_argument('cross_file')
4649
options = parser.parse_args()
47-
return runtests(options.cross_file, options.failfast, options.cross_only)
50+
cf_path = Path(options.cross_file)
51+
try:
52+
data = json.loads(cf_path.read_text())
53+
real_cf = cf_path.resolve().parent / data['file']
54+
assert real_cf.exists()
55+
env = os.environ.copy()
56+
env.update(data['env'])
57+
return runtests(real_cf.as_posix(), options.failfast, options.cross_only, data['tests'], env=env)
58+
except Exception:
59+
return runtests(options.cross_file, options.failfast, options.cross_only, ['common'])
4860

4961
if __name__ == '__main__':
5062
print('Meson build system', meson_version, 'Cross Tests')

run_project_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ def check_format():
11631163
'.dub', # external deps are here
11641164
'.pytest_cache',
11651165
'meson-logs', 'meson-private',
1166+
'work area',
11661167
'.eggs', '_cache', # e.g. .mypy_cache
11671168
'venv', # virtualenvs have DOS line endings
11681169
}

test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ target_link_libraries(testEXE cmModLib)
2525

2626
target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE)
2727

28-
install(TARGETS cmModLib testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
28+
install(TARGETS testEXE LIBRARY DESTINATION lib RUNTIME DESTINATION bin)

test cases/cmake/2 advanced/test.json

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"installed": [
3-
{"type": "expr", "file": "usr/?lib/libcm_cmModLib?so"},
4-
{"type": "implib", "file": "usr/lib/libcm_cmModLib"},
53
{"type": "exe", "file": "usr/bin/cm_testEXE"}
64
],
75
"tools": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(MESON_TEST_VAR2 VAR2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project('cmake toolchain test', ['c', 'cpp'])
2+
3+
if meson.is_cross_build()
4+
error('MESON_SKIP_TEST: skip this on cross builds')
5+
endif
6+
7+
cm = import('cmake')
8+
9+
sub_pro = cm.subproject('cmMod')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[properties]
2+
3+
cmake_toolchain_file = '@MESON_TEST_ROOT@/CMakeToolchain.cmake'
4+
5+
[cmake]
6+
7+
MESON_TEST_VAR1 = 'VAR1 space'
8+
MESON_TEST_VAR2 = 'VAR2 error'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(cmMod)
4+
5+
if(NOT "${MESON_TEST_VAR1}" STREQUAL "VAR1 space")
6+
message(FATAL_ERROR "MESON_TEST_VAR1 -- '${MESON_TEST_VAR1}' != 'VAR1 space'")
7+
endif()
8+
9+
if(NOT "${MESON_TEST_VAR2}" STREQUAL "VAR2")
10+
message(FATAL_ERROR "MESON_TEST_VAR2 -- '${MESON_TEST_VAR2}' != 'VAR2'")
11+
endif()

test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ target_link_libraries(testEXE2 cmModLib)
2323

2424
target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE)
2525

26-
install(TARGETS cmModLib testEXE testEXE2 LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
26+
install(TARGETS testEXE testEXE2 LIBRARY DESTINATION lib RUNTIME DESTINATION bin)

test cases/cmake/3 advanced no dep/test.json

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"installed": [
3-
{"type": "expr", "file": "usr/?lib/libcm_cmModLib?so"},
4-
{"type": "implib", "file": "usr/lib/libcm_cmModLib"},
5-
{"type": "pdb", "file": "usr/bin/cm_cmModLib"},
63
{"type": "pdb", "file": "usr/bin/cm_testEXE"},
74
{"type": "exe", "file": "usr/bin/cm_testEXE"},
85
{"type": "pdb", "file": "usr/bin/cm_testEXE2"},
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required(VERSION 3.7)
22

3+
project(CMCodeGen)
34
set(CMAKE_CXX_STANDARD 14)
45

56
add_executable(genA main.cpp)

test cases/cmake/7 cmake options/test.json

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"options": {
44
"cmake_prefix_path": [
55
{ "val": ["val1", "val2"] }
6+
],
7+
"build.cmake_prefix_path": [
8+
{ "val": ["val1", "val2"] }
69
]
710
}
811
}

0 commit comments

Comments
 (0)