[vcpkg_fixup_pkgconfig] Check for more problems, add unit test (#23898)

* Print stack traces for failed unit tests

* Add test for vcpkg_fixup_pkgconfig.cmake

* Check for 'optimized' and 'debug' in pc files

* Check for 'NOTFOUND' and for 'ns::target' in pc files

* Check for, and fix, line continuations

* Test file path substitutions

* Move contents processing into separate function

* Update and leverage line break normalization

* Pass prefix to data processing

* Validate only the collapsed Libs

* Test removal of '<field>.private'

* Declare unit test license (same as vcpkg)

* Replace ';' with ' ' in 'Libs:'

* Disambiguate parameter variable names

* Test quoting of variables

* Fix quoting of variables

* Quote whole parameters

* Process and quote libs item-wise

* Resolve keywords 'optimized', 'debug', 'debug'

* Consistency

* CI [skip actions]

* CI [skip actions]

* Don't fail on detected errors

* Disable unit-testing for fatal errors

Co-authored-by: Billy O'Neal <bion@microsoft.com>
This commit is contained in:
Kai Pastor 2023-01-20 03:27:29 +01:00 committed by GitHub
parent d02bde4898
commit edcf949452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 290 additions and 77 deletions

View File

@ -1,4 +1,108 @@
function(z_vcpkg_fixup_pkgconfig_check_files file config)
function(z_vcpkg_fixup_pkgconfig_process_data arg_variable arg_config arg_prefix)
# This normalizes all data to start and to end with a newline, and
# to use LF instead of CRLF. This allows to use simpler regex matches.
string(REPLACE "\r\n" "\n" contents "\n${${arg_variable}}\n")
string(REPLACE "${CURRENT_PACKAGES_DIR}" [[${prefix}]] contents "${contents}")
string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${prefix}]] contents "${contents}")
if(VCPKG_HOST_IS_WINDOWS)
string(REGEX REPLACE "^([a-zA-Z]):/" [[/\1/]] unix_packages_dir "${CURRENT_PACKAGES_DIR}")
string(REPLACE "${unix_packages_dir}" [[${prefix}]] contents "${contents}")
string(REGEX REPLACE "^([a-zA-Z]):/" [[/\1/]] unix_installed_dir "${CURRENT_INSTALLED_DIR}")
string(REPLACE "${unix_installed_dir}" [[${prefix}]] contents "${contents}")
endif()
string(REGEX REPLACE "\n[\t ]*prefix[\t ]*=[^\n]*" "" contents "prefix=${arg_prefix}${contents}")
if("${arg_config}" STREQUAL "DEBUG")
# prefix points at the debug subfolder
string(REPLACE [[${prefix}/debug]] [[${prefix}]] contents "${contents}")
string(REPLACE [[${prefix}/include]] [[${prefix}/../include]] contents "${contents}")
string(REPLACE [[${prefix}/share]] [[${prefix}/../share]] contents "${contents}")
endif()
# Remove line continuations before transformations
string(REGEX REPLACE "[ \t]*\\\\\n[ \t]*" " " contents "${contents}")
# This section fuses XYZ.private and XYZ according to VCPKG_LIBRARY_LINKAGE
#
# Pkgconfig searches Requires.private transitively for Cflags in the dynamic case,
# which prevents us from removing it.
#
# Once this transformation is complete, users of vcpkg should never need to pass
# --static.
if("${VCPKG_LIBRARY_LINKAGE}" STREQUAL "static")
# how this works:
# we want to transform:
# Libs: $1
# Libs.private: $2
# into
# Libs: $1 $2
# and the same thing for Requires and Requires.private
foreach(item IN ITEMS "Libs" "Requires" "Cflags")
set(line "")
if("${contents}" MATCHES "\n${item}: *([^\n]*)")
string(APPEND line " ${CMAKE_MATCH_1}")
endif()
if("${contents}" MATCHES "\n${item}\\.private: *([^\n]*)")
string(APPEND line " ${CMAKE_MATCH_1}")
endif()
string(REGEX REPLACE "\n${item}(\\.private)?:[^\n]*" "" contents "${contents}")
if(NOT "${line}" STREQUAL "")
string(APPEND contents "${item}:${line}\n")
endif()
endforeach()
endif()
if(contents MATCHES "\nLibs: *([^\n]*)")
set(libs "${CMAKE_MATCH_1}")
if(libs MATCHES [[;]])
# Assuming that ';' comes from CMake lists only. Candidate for parameter control.
string(REPLACE ";" " " no_lists "${libs}")
string(REPLACE "${libs}" "${no_lists}" contents "${contents}")
set(libs "${no_lists}")
endif()
separate_arguments(libs_list UNIX_COMMAND "${libs}")
set(skip_next 0)
set(libs_filtered "")
foreach(item IN LISTS libs_list)
if(skip_next)
set(skip_next 0)
continue()
elseif(item MATCHES "^(-l|-L)?optimized")
string(COMPARE EQUAL "${arg_config}" "DEBUG" skip_next)
continue()
elseif(item MATCHES "^(-l|-L)?debug")
string(COMPARE EQUAL "${arg_config}" "RELEASE" skip_next)
continue()
elseif(item MATCHES "^(-l|-L)?general")
continue()
endif()
if(item MATCHES "[\$`\"\\ ]")
set(item "\"${item}\"")
endif()
list(APPEND libs_filtered "${item}")
endforeach()
list(JOIN libs_filtered " " libs_filtered)
string(REPLACE "${libs}" "${libs_filtered}" contents "${contents}")
set(libs "${libs_filtered}")
if(libs MATCHES "[^ ]*-NOTFOUND")
message(WARNING "Error in ${file}: 'Libs' refers to a missing lib:\n...${CMAKE_MATCH_0}")
endif()
if(libs MATCHES "[^\n]*::[^\n ]*")
message(WARNING "Error in ${file}: 'Libs' refers to a CMake target:\n...${CMAKE_MATCH_0}")
endif()
endif()
# Quote -L, -I, and -l paths starting with `${blah}`
# This was already handled for "Libs", but there might be additional occurrences in other lines.
string(REGEX REPLACE "([ =])(-[LIl]\\\${[^}]*}[^ ;\n\t]*)" [[\1"\2"]] contents "${contents}")
set("${arg_variable}" "${contents}" PARENT_SCOPE)
endfunction()
function(z_vcpkg_fixup_pkgconfig_check_files arg_file arg_config)
set(path_suffix_DEBUG /debug)
set(path_suffix_RELEASE "")
@ -9,15 +113,15 @@ function(z_vcpkg_fixup_pkgconfig_check_files file config)
endif()
vcpkg_host_path_list(PREPEND ENV{PKG_CONFIG_PATH}
"${CURRENT_PACKAGES_DIR}${path_suffix_${config}}/lib/pkgconfig"
"${CURRENT_PACKAGES_DIR}${path_suffix_${arg_config}}/lib/pkgconfig"
"${CURRENT_PACKAGES_DIR}/share/pkgconfig"
"${CURRENT_INSTALLED_DIR}${path_suffix_${config}}/lib/pkgconfig"
"${CURRENT_INSTALLED_DIR}${path_suffix_${arg_config}}/lib/pkgconfig"
"${CURRENT_INSTALLED_DIR}/share/pkgconfig"
)
# First make sure everything is ok with the package and its deps
cmake_path(GET file STEM LAST_ONLY package_name)
debug_message("Checking package (${config}): ${package_name}")
cmake_path(GET arg_file STEM LAST_ONLY package_name)
debug_message("Checking package (${arg_config}): ${package_name}")
execute_process(
COMMAND "${PKGCONFIG}" --print-errors --exists "${package_name}"
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
@ -68,14 +172,8 @@ function(vcpkg_fixup_pkgconfig)
endforeach()
endif()
string(REGEX REPLACE "^([a-zA-Z]):/" [[/\1/]] unix_packages_dir "${CURRENT_PACKAGES_DIR}")
string(REGEX REPLACE "^([a-zA-Z]):/" [[/\1/]] unix_installed_dir "${CURRENT_INSTALLED_DIR}")
foreach(config IN ITEMS RELEASE DEBUG)
debug_message("${config} Files: ${arg_${config}_FILES}")
if("${VCPKG_BUILD_TYPE}" STREQUAL "debug" AND "${config}" STREQUAL "RELEASE")
continue()
endif()
if("${VCPKG_BUILD_TYPE}" STREQUAL "release" AND "${config}" STREQUAL "DEBUG")
continue()
endif()
@ -91,60 +189,8 @@ function(vcpkg_fixup_pkgconfig)
endif()
#Correct *.pc file
file(READ "${file}" contents)
# this normalizes all files to end with a newline, and use LF instead of CRLF;
# this allows us to use regex matches easier to modify these files.
if(NOT "${contents}" MATCHES "\n$")
string(APPEND contents "\n")
endif()
string(REPLACE "\r\n" "\n" contents "${contents}")
string(REPLACE "${CURRENT_PACKAGES_DIR}" [[${prefix}]] contents "${contents}")
string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${prefix}]] contents "${contents}")
string(REPLACE "${unix_packages_dir}" [[${prefix}]] contents "${contents}")
string(REPLACE "${unix_installed_dir}" [[${prefix}]] contents "${contents}")
string(REGEX REPLACE "(^|\n) *prefix[\t ]*=[^\n]*" "" contents "${contents}")
if("${config}" STREQUAL "DEBUG")
# prefix points at the debug subfolder
string(REPLACE [[${prefix}/debug]] [[${prefix}]] contents "${contents}")
string(REPLACE [[${prefix}/include]] [[${prefix}/../include]] contents "${contents}")
string(REPLACE [[${prefix}/share]] [[${prefix}/../share]] contents "${contents}")
endif()
# quote -L, -I, and -l paths starting with `${blah}`
string(REGEX REPLACE " -([LIl])(\\\${[^}]*}[^ \n\t]*)" [[ -\1"\2"]] contents "${contents}")
# This section fuses XYZ.private and XYZ according to VCPKG_LIBRARY_LINKAGE
#
# Pkgconfig searches Requires.private transitively for Cflags in the dynamic case,
# which prevents us from removing it.
#
# Once this transformation is complete, users of vcpkg should never need to pass
# --static.
if("${VCPKG_LIBRARY_LINKAGE}" STREQUAL "static")
# how this works:
# we want to transform:
# Libs: $1
# Libs.private: $2
# into
# Libs: $1 $2
# and the same thing for Requires and Requires.private
foreach(item IN ITEMS "Libs" "Requires" "Cflags")
set(line "")
if("${contents}" MATCHES "(^|\n)${item}: *([^\n]*)")
string(APPEND line " ${CMAKE_MATCH_2}")
endif()
if("${contents}" MATCHES "(^|\n)${item}\\.private: *([^\n]*)")
string(APPEND line " ${CMAKE_MATCH_2}")
endif()
string(REGEX REPLACE "(^|\n)${item}(\\.private)?:[^\n]*\n" [[\1]] contents "${contents}")
if(NOT "${line}" STREQUAL "")
string(APPEND contents "${item}:${line}\n")
endif()
endforeach()
endif()
file(WRITE "${file}" "prefix=\${pcfiledir}/${relative_pc_path}\n${contents}")
z_vcpkg_fixup_pkgconfig_process_data(contents "${config}" "\${pcfiledir}/${relative_pc_path}")
file(WRITE "${file}" "${contents}")
endforeach()
if(NOT arg_SKIP_CHECK) # The check can only run after all files have been corrected!

View File

@ -44,9 +44,9 @@ function(unit_test_check_variable_unset utcvu_test utcvu_variable)
if(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
unset_fatal_error()
set_has_error()
message(STATUS "${utcvu_test} had an unexpected FATAL_ERROR;
message(SEND_ERROR "${utcvu_test} had an unexpected FATAL_ERROR;
expected: \"${utcvu_value}\"")
message(STATUS "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
message(SEND_ERROR "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
return()
endif()
@ -65,7 +65,7 @@ function(unit_test_check_variable_unset utcvu_test utcvu_variable)
endif()
if(DEFINED "${utcvu_variable}")
message(STATUS "${utcvu_test} set ${utcvu_variable};
message(SEND_ERROR "${utcvu_test} set ${utcvu_variable};
expected: \"${utcvu_variable}\" unset
actual : \"${utcvu_actual_value}\"")
set_has_error()
@ -78,14 +78,14 @@ function(unit_test_check_variable_equal utcve_test utcve_variable utcve_value)
if(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
unset_fatal_error()
set_has_error()
message(STATUS "${utcve_test} had an unexpected FATAL_ERROR;
message(SEND_ERROR "${utcve_test} had an unexpected FATAL_ERROR;
expected: \"${utcve_value}\"")
message(STATUS "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
message(SEND_ERROR "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
return()
endif()
if(NOT DEFINED "${utcve_variable}" AND NOT "${utcve_variable}" MATCHES "^ENV\\{")
message(STATUS "${utcve_test} failed to set ${utcve_variable};
message(SEND_ERROR "${utcve_test} failed to set ${utcve_variable};
expected: \"${utcve_value}\"")
set_has_error()
return()
@ -105,7 +105,7 @@ function(unit_test_check_variable_equal utcve_test utcve_variable utcve_value)
endif()
if(NOT "${utcve_actual_value}" STREQUAL "${utcve_value}")
message(STATUS "${utcve_test} resulted in the wrong value for ${utcve_variable};
message(SEND_ERROR "${utcve_test} resulted in the wrong value for ${utcve_variable};
expected: \"${utcve_value}\"
actual : \"${utcve_actual_value}\"")
set_has_error()
@ -118,9 +118,9 @@ function(unit_test_check_variable_not_equal utcve_test utcve_variable utcve_valu
if(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
unset_fatal_error()
set_has_error()
message(STATUS "${utcve_test} had an unexpected FATAL_ERROR;
message(SEND_ERROR "${utcve_test} had an unexpected FATAL_ERROR;
expected: \"${utcve_value}\"")
message(STATUS "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
message(SEND_ERROR "FATAL_ERROR: ${Z_VCPKG_UNIT_TEST_FATAL_ERROR}")
return()
endif()
@ -138,7 +138,7 @@ function(unit_test_check_variable_not_equal utcve_test utcve_variable utcve_valu
endif()
if("${utcve_actual_value}" STREQUAL "${utcve_value}")
message(STATUS "${utcve_test} failed to change ${utcve_variable};
message(SEND_ERROR "${utcve_test} failed to change ${utcve_variable};
unchanged: \"${utcve_value}\"")
set_has_error()
return()
@ -149,7 +149,7 @@ function(unit_test_ensure_success utcve_test)
cmake_language(EVAL CODE "${utcve_test}")
if(Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
set_has_error()
message(STATUS "${utcve_test} was expected to be successful.")
message(SEND_ERROR "${utcve_test} was expected to be successful.")
endif()
unset_fatal_error()
endfunction()
@ -157,7 +157,7 @@ function(unit_test_ensure_fatal_error utcve_test)
cmake_language(EVAL CODE "${utcve_test}")
if(NOT Z_VCPKG_UNIT_TEST_HAS_FATAL_ERROR)
set_has_error()
message(STATUS "${utcve_test} was expected to be a FATAL_ERROR.")
message(SEND_ERROR "${utcve_test} was expected to be a FATAL_ERROR.")
endif()
unset_fatal_error()
endfunction()
@ -185,6 +185,9 @@ endif()
if("setup-pkgconfig-path" IN_LIST FEATURES)
include("${CMAKE_CURRENT_LIST_DIR}/test-z_vcpkg_setup_pkgconfig_path.cmake")
endif()
if("fixup-pkgconfig" IN_LIST FEATURES)
include("${CMAKE_CURRENT_LIST_DIR}/test-vcpkg_fixup_pkgconfig.cmake")
endif()
if(Z_VCPKG_UNIT_TEST_HAS_ERROR)
_message(FATAL_ERROR "At least one test failed")

View File

@ -0,0 +1,159 @@
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/pkgconfig")
set(pc_file_release "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/unit-test-cmake.pc")
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig")
set(pc_file_debug "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/unit-test-cmake.pc")
set(reload_pc_strings 0)
function(write_pkgconfig)
file(WRITE "${pc_file_release}" ${ARGN})
file(WRITE "${pc_file_debug}" ${ARGN})
file(STRINGS "${pc_file_release}" pc_strings_input)
set(pc_strings_INPUT "${pc_strings_input}" PARENT_SCOPE)
set(reload_pc_strings 1 PARENT_SCOPE)
endfunction()
function(unit_test_pkgconfig_check_key build_types field value)
if(NOT build_types)
message(SEND_ERROR "The build_type parameter must be list of debug;release.")
endif()
if(reload_pc_strings)
file(STRINGS "${pc_file_release}" pc_strings_release)
file(STRINGS "${pc_file_debug}" pc_strings_debug)
set(pc_strings_release "${pc_strings_release}" PARENT_SCOPE)
set(pc_strings_debug "${pc_strings_debug}" PARENT_SCOPE)
set(reload_pc_strings 0 PARENT_SCOPE)
endif()
foreach(build_type IN LISTS build_types)
set(listname "pc_strings_${build_type}")
set(expected "${field}${value}")
list(FILTER ${listname} INCLUDE REGEX "^${field}")
if(NOT "${${listname}}" STREQUAL "${expected}" AND NOT "${${listname}}_is_empty" STREQUAL "${value}_is_empty")
message(SEND_ERROR "vcpkg_fixup_pkgconfig() resulted in a wrong value for ${build_type} builds;
input: [[${pc_strings_INPUT}]]
expected: [[${expected}]]
actual : [[${${listname}}]]")
set_has_error()
return()
endif()
endforeach()
endfunction()
# "Libs:" only
write_pkgconfig([[
Libs: -L${prefix}/lib -l"aaa"
]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa]])
# "Libs:" and "Libs.private:"
write_pkgconfig([[
Libs: -L"${prefix}/lib" -l"aaa"
Libs.private: -l"bbb ccc"
]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa "-lbbb ccc"]])
unit_test_pkgconfig_check_key("debug;release" "Libs.private:" "")
else()
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa]])
endif()
# line continuations
write_pkgconfig([[
Libs.private: \
-lbbb
Libs: -L"${prefix}/lib" \
-l"aaa"
]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa -lbbb]])
unit_test_pkgconfig_check_key("debug;release" "Libs.private:" "")
else()
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa]])
endif()
# Replace ';' with ' '
write_pkgconfig([[
Libs: -L${prefix}/lib\;-l"aaa"
Libs.private: -lbbb\;-l"ccc"
]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa -lbbb -lccc]])
unit_test_pkgconfig_check_key("debug;release" "Libs.private:" "")
else()
unit_test_pkgconfig_check_key("debug;release" "Libs:" [[ "-L${prefix}/lib" -laaa]])
endif()
# invalid: ...-NOTFOUND
write_pkgconfig([[Libs: LIB-NOTFOUND]])
# Only warning: unit_test_ensure_fatal_error([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) # ...-NOTFOUND # ]])
# invalid: optimized/debug
write_pkgconfig([[Libs: -laaa -loptimized -lrel -ldebug -ldbg -lbbb]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug" "Libs:" [[ -laaa -ldbg -lbbb]])
unit_test_pkgconfig_check_key("release" "Libs:" [[ -laaa -lrel -lbbb]])
write_pkgconfig([[Libs: -laaa -Loptimized -Lrel -Ldebug -Ldbg -lbbb]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug" "Libs:" [[ -laaa -Ldbg -lbbb]])
unit_test_pkgconfig_check_key("release" "Libs:" [[ -laaa -Lrel -lbbb]])
write_pkgconfig([[Libs: optimized\;librel.a\;debug\;libdbg.a\;aaa.lib]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug" "Libs:" [[ libdbg.a aaa.lib]])
unit_test_pkgconfig_check_key("release" "Libs:" [[ librel.a aaa.lib]])
write_pkgconfig([[Libs: aaa.lib\;optimized\;librel.a\;debug\;libdbg.a]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug" "Libs:" [[ aaa.lib libdbg.a]])
unit_test_pkgconfig_check_key("release" "Libs:" [[ aaa.lib librel.a]])
write_pkgconfig([[Libs: aaa.lib optimized librel.a debug libdbg.a bbb.lib]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug" "Libs:" [[ aaa.lib libdbg.a bbb.lib]])
unit_test_pkgconfig_check_key("release" "Libs:" [[ aaa.lib librel.a bbb.lib]])
# invalid: namespaced targets
write_pkgconfig([[Libs: -lAAA::aaa]])
# Only warning: unit_test_ensure_fatal_error([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) # namespaced target # ]])
# prefix
write_pkgconfig(
"prefix=${CURRENT_PACKAGES_DIR}
execprefix=\${prefix}
libdir=${CURRENT_PACKAGES_DIR}/lib
includedir=${CURRENT_PACKAGES_DIR}/include
datarootdir=${CURRENT_PACKAGES_DIR}/share
datadir=\${datarootdir}/${PORT}
")
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("release" "prefix=" [[${pcfiledir}/../..]])
unit_test_pkgconfig_check_key("release" "execprefix=" [[${prefix}]])
unit_test_pkgconfig_check_key("release" "libdir=" [[${prefix}/lib]])
unit_test_pkgconfig_check_key("release" "includedir=" [[${prefix}/include]])
unit_test_pkgconfig_check_key("release" "datarootdir=" [[${prefix}/share]])
unit_test_pkgconfig_check_key("release" "datadir=" [[${datarootdir}/unit-test-cmake]])
write_pkgconfig(
"prefix=${CURRENT_PACKAGES_DIR}/debug
execprefix=\${prefix}
libdir=${CURRENT_PACKAGES_DIR}/debug/lib
includedir=${CURRENT_PACKAGES_DIR}/include
datarootdir=${CURRENT_PACKAGES_DIR}/share
datadir=\${datarootdir}/${PORT}
")
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug" "prefix=" [[${pcfiledir}/../..]])
unit_test_pkgconfig_check_key("debug" "execprefix=" [[${prefix}]])
unit_test_pkgconfig_check_key("debug" "libdir=" [[${prefix}/lib]])
unit_test_pkgconfig_check_key("debug" "includedir=" [[${prefix}/../include]])
unit_test_pkgconfig_check_key("debug" "datarootdir=" [[${prefix}/../share]])
unit_test_pkgconfig_check_key("debug" "datadir=" [[${datarootdir}/unit-test-cmake]])
# -I, -l or -L with ${blah} in variables
write_pkgconfig([[blah_libs=-L${blah}/lib64 -l${blah}/libblah.a -I${blah}/include]])
unit_test_ensure_success([[ vcpkg_fixup_pkgconfig(SKIP_CHECK) ]])
unit_test_pkgconfig_check_key("debug;release" "blah_libs=" [["-L${blah}/lib64" "-l${blah}/libblah.a" "-I${blah}/include"]])

View File

@ -2,9 +2,11 @@
"name": "unit-test-cmake",
"version-string": "0",
"description": "Ensures that the CMake scripts are unit tested.",
"license": "MIT",
"supports": "x64",
"default-features": [
"backup-restore-env-vars",
"fixup-pkgconfig",
"function-arguments",
"host-path-list",
"list",
@ -16,6 +18,9 @@
"backup-restore-env-vars": {
"description": "Test the vcpkg_backup/restore_env_vars functions"
},
"fixup-pkgconfig": {
"description": "Test the vcpkg_fixup_pkgconfig function"
},
"function-arguments": {
"description": "Test the z_vcpkg_function_arguments function"
},