[unit-test-cmake,vcpkg-make] Fixes, more triplet checks (#45655)

This commit is contained in:
Kai Pastor 2025-05-29 10:48:45 +02:00 committed by GitHub
parent bf340b9bf2
commit 3a4124f89f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 75 additions and 4 deletions

View File

@ -32,7 +32,7 @@ endmacro()
set(Z_VCPKG_UNIT_TEST_HAS_ERROR OFF CACHE BOOL "" FORCE)
unset_fatal_error()
# in order to allow namespacing
# Set <namespace>_MATCHED, preserve parent scope's CMAKE_MATCH_<...>
function(unit_test_match namespace value regex)
if("${value}" MATCHES "${regex}")
set("${namespace}_MATCHED" ON PARENT_SCOPE)
@ -93,7 +93,8 @@ function(unit_test_check_variable_equal utcve_test utcve_variable utcve_value)
return()
endif()
if(NOT DEFINED "${utcve_variable}" AND NOT "${utcve_variable}" MATCHES "^ENV\\{")
unit_test_match(utcve "${utcve_variable}" "^ENV\\{")
if(NOT DEFINED "${utcve_variable}" AND NOT utcve_MATCHED)
message(SEND_ERROR "${utcve_test} failed to set ${utcve_variable};
expected: \"${utcve_value}\"")
set_has_error()

View File

@ -15,7 +15,10 @@ set(CURRENT_INSTALLED_DIR "I")
z_vcpkg_setup_pkgconfig_path(CONFIG RELEASE)
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
unit_test_match([[]] ENV{PKG_CONFIG_PATH} "^P.lib.pkgconfig.P.share.pkgconfig.I.lib.pkgconfig.I.share.pkgconfig.1\$")
unit_test_check_variable_not_equal(
[[ string(REGEX MATCH "^P.lib.pkgconfig.P.share.pkgconfig.I.lib.pkgconfig.I.share.pkgconfig.1\$" output "$ENV{PKG_CONFIG_PATH}") ]]
output ""
)
z_vcpkg_restore_pkgconfig_path()
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
@ -24,7 +27,10 @@ unit_test_check_variable_equal([[]] ENV{PKG_CONFIG_PATH} "1")
z_vcpkg_setup_pkgconfig_path(CONFIG DEBUG)
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])
unit_test_check_variable_not_equal([[]] ENV{PKG_CONFIG_PATH} "1")
unit_test_match([[]] ENV{PKG_CONFIG_PATH} "^P.debug.lib.pkgconfig.P.share.pkgconfig.I.debug.lib.pkgconfig.I.share.pkgconfig.1\$")
unit_test_check_variable_not_equal(
[[ string(REGEX MATCH "^P.debug.lib.pkgconfig.P.share.pkgconfig.I.debug.lib.pkgconfig.I.share.pkgconfig.1\$" output "$ENV{PKG_CONFIG_PATH}") ]]
output ""
)
z_vcpkg_restore_pkgconfig_path()
unit_test_check_variable_equal([[]] ENV{PKG_CONFIG} [[/a/pkgconf]])

View File

@ -1,3 +1,5 @@
block(SCOPE_FOR VARIABLES)
# Test 1: Basic Transformation
set(all_libs_list "libexample.dll;libutil.a;libutil2.lib;libutil3.so")
set(expected "-llibexample.dll;-llibutil;-llibutil2;-llibutil3")
@ -49,3 +51,5 @@ unit_test_check_variable_equal(
all_libs_list
"${expected}"
)
endblock()

View File

@ -17,3 +17,63 @@ if(VCPKG_TARGET_IS_LINUX AND NOT host_arch STREQUAL "arm64")
)
endblock()
endif()
# branching as in vcpkg_make_configure
if(VCPKG_MAKE_BUILD_TRIPLET)
set(triplets "${VCPKG_MAKE_BUILD_TRIPLET}")
else()
z_vcpkg_make_get_configure_triplets(triplets)
endif()
if(VCPKG_HOST_IS_WINDOWS)
unit_test_check_variable_equal(
[[ string(REGEX MATCH "--build=[^;]*-([^-;]*-[^-;]*)" output "${triplets}") ]]
CMAKE_MATCH_1 "pc-mingw32"
)
if(NOT VCPKG_CROSSCOMPILING)
# expected bad: there is --build but not --host
unit_test_check_variable_unset(
[[ string(REGEX MATCH "--host=([^;]*)" output "${triplets}") ]]
CMAKE_MATCH_1
)
elseif(VCPKG_TARGET_IS_UWP)
unit_test_check_variable_equal(
[[ string(REGEX MATCH "--host=[^;]*-([^-;]*-[^-;]*)" output "${triplets}") ]]
CMAKE_MATCH_1 "unknown-mingw32"
)
else()
# maybe there is --host
endif()
elseif(NOT VCPKG_CROSSCOMPILING)
if(triplets)
unit_test_check_variable_not_equal(
[[ string(REGEX MATCH "--host=([^;]*)" output "${triplets}") ]]
CMAKE_MATCH_1
)
set(autotools_host_triplet "${CMAKE_MATCH_1}")
unit_test_check_variable_equal(
[[ string(REGEX MATCH "--build=([^;]*)" output "${triplets}") ]]
CMAKE_MATCH_1 "${autotools_host_triplet}"
)
endif()
elseif(VCPKG_TARGET_IS_ANDROID)
unit_test_check_variable_equal(
[[ string(REGEX MATCH "--host=[^;]*-([^-;]*-(android|[^-;]*))" output "${triplets}") ]]
CMAKE_MATCH_1 "linux-android"
)
# expected bad: there is --host but not --build
unit_test_check_variable_unset(
[[ string(REGEX MATCH "--build=([^;]*)" output "${triplets}") ]]
CMAKE_MATCH_1
)
elseif(VCPKG_TARGET_IS_MINGW)
unit_test_check_variable_equal(
[[ string(REGEX MATCH "--host=[^;]*-(mingw32|[^-;]*)" output "${triplets}") ]]
CMAKE_MATCH_1 "mingw32"
)
# expected bad: there is --host but not --build
unit_test_check_variable_unset(
[[ string(REGEX MATCH "--build=([^;]*)" output "${triplets}") ]]
CMAKE_MATCH_1
)
endif()