Tests: Convert CPackWiXGenerator to RunCMake.CPack_WIX

This commit is contained in:
Brad King
2024-03-18 14:04:25 -04:00
parent 0b3756a7e3
commit 9c472b9482
17 changed files with 90 additions and 100 deletions

View File

@@ -978,28 +978,6 @@ if(BUILD_TESTING)
endif()
endif()
if(WIN32)
if(CMake_TEST_CPACK_WIX)
add_test(CPackWiXGenerator ${CMAKE_CTEST_COMMAND}
-C \${CTEST_CONFIGURATION_TYPE}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/CPackWiXGenerator"
"${CMake_BINARY_DIR}/Tests/CPackWiXGenerator"
${build_generator_args}
--build-project CPackWiXGenerator
--build-options
--test-command ${CMAKE_CMAKE_COMMAND}
"-DCPackWiXGenerator_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackWiXGenerator"
"-Dno_verify:BOOL=${CMake_TEST_WIX_NO_VERIFY}"
"-Dconfig=\${CTEST_CONFIGURATION_TYPE}"
-P "${CMake_SOURCE_DIR}/Tests/CPackWiXGenerator/RunCPackVerifyResult.cmake")
set_property(TEST CPackWiXGenerator PROPERTY
ATTACHED_FILES_ON_FAIL
"${CMake_BINARY_DIR}/Tests/CPackWiXGenerator/_CPack_Packages/win32/WIX/wix.log")
endif()
endif()
# On Windows run the CPackInnoSetupGenerator test
if(WIN32 AND CMake_TEST_CPACK_INNOSETUP)
add_test(CPackInnoSetupGenerator ${CMAKE_CTEST_COMMAND}

View File

@@ -1,78 +0,0 @@
message(STATUS "=============================================================")
message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
message(STATUS "")
if(NOT CPackWiXGenerator_BINARY_DIR)
message(FATAL_ERROR "CPackWiXGenerator_BINARY_DIR not set")
endif()
message(STATUS "CMAKE_COMMAND: ${CMAKE_COMMAND}")
message(STATUS "CMAKE_CPACK_COMMAND: ${CMAKE_CPACK_COMMAND}")
message(STATUS "CPackWiXGenerator_BINARY_DIR: ${CPackWiXGenerator_BINARY_DIR}")
if(config)
set(_C_config -C ${config})
endif()
execute_process(COMMAND "${CMAKE_CPACK_COMMAND}"
${_C_config}
RESULT_VARIABLE CPack_result
OUTPUT_VARIABLE CPack_output
ERROR_VARIABLE CPack_error
WORKING_DIRECTORY "${CPackWiXGenerator_BINARY_DIR}")
if(CPack_result)
message(FATAL_ERROR "CPack execution went wrong!, CPack_output=${CPack_output}, CPack_error=${CPack_error}")
else ()
message(STATUS "CPack_output=${CPack_output}")
endif()
set(expected_file_mask "*.msi")
file(GLOB installer_file "${expected_file_mask}")
message(STATUS "installer_file='${installer_file}'")
message(STATUS "expected_file_mask='${expected_file_mask}'")
if(NOT installer_file)
message(FATAL_ERROR "installer_file does not exist.")
endif()
function(run_wix_command command)
file(TO_CMAKE_PATH "$ENV{WIX}" WIX_ROOT)
find_program(WIX_PROGRAM NAMES ${command} NO_CACHE PATHS "${WIX_ROOT}" PATH_SUFFIXES "bin")
if(NOT WIX_PROGRAM)
message(FATAL_ERROR "Failed to find WiX Tool: ${WIX_PROGRAM}")
endif()
message(STATUS "Running WiX Tool: ${command} ${ARGN}")
execute_process(COMMAND "${WIX_PROGRAM}" ${ARGN}
RESULT_VARIABLE WIX_result
OUTPUT_VARIABLE WIX_output
ERROR_VARIABLE WIX_output
WORKING_DIRECTORY "${CPackWiXGenerator_BINARY_DIR}")
message(STATUS "${command} Output: \n${WIX_output}")
if(WIX_result)
message(FATAL_ERROR "WiX ${command} failed: ${WIX_result}")
endif()
endfunction()
file(GLOB WXS_SOURCE_FILES
"${CPackWiXGenerator_BINARY_DIR}/_CPack_Packages/*/WIX/*.wxs")
if(NOT WXS_SOURCE_FILES)
message(FATAL_ERROR "Failed finding WiX source files to validate.")
endif()
foreach(WXS_SOURCE_FILE IN LISTS WXS_SOURCE_FILES)
run_wix_command(wixcop "${WXS_SOURCE_FILE}")
endforeach()
# error SMOK1076 : ICE61: This product should remove only older
# versions of itself. The Maximum version is not less
# than the current product. (1.0.0 1.0.0)
if (NOT no_verify)
run_wix_command(smoke -nologo -wx -sw1076 "${installer_file}")
endif ()

View File

@@ -1096,6 +1096,11 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k" AND NOT DEFINED CMake_TEST_E2K_BROKEN_L
endif()
add_RunCMake_test_group(CPack "${cpack_tests}")
if(CMake_TEST_CPACK_WIX)
add_RunCMake_test(CPack_WIX)
endif()
# add a test to make sure symbols are exported from a shared library
# for MSVC compilers CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS property is used
add_RunCMake_test(AutoExportDll

View File

@@ -0,0 +1 @@
include(${RunCMake_SOURCE_DIR}/cpack-check-common.cmake)

View File

@@ -0,0 +1,11 @@
CPack: Create package using WIX
CPack: Install projects
CPack: - Install project: CPackWiXGenerator \[Release\]
CPack: - Install component: applications
CPack: - Install component: applications2
CPack: - Install component: extras
CPack: - Install component: headers
CPack: - Install component: libraries
CPack: Create package
CPack: - package: [^
]*/Tests/RunCMake/CPack_WIX/AppWiX-build/MyLib-1\.0\.0-win64\.msi generated\.

View File

@@ -0,0 +1,33 @@
-- MyLib-1\.0\.0-win64\.msi
Component: 'CM_CP_applications.bin.my_libapp.exe' 'CM_DP_applications.bin'
Component: 'CM_SHORTCUT_applications' 'PROGRAM_MENU_FOLDER'
Component: 'CM_SHORTCUT_DESKTOP_applications' 'DesktopFolder'
Component: 'CM_CP_applications2.bin.my_other_app.exe' 'CM_DP_applications2.bin'
Component: 'CM_SHORTCUT_applications2' 'PROGRAM_MENU_FOLDER'
Component: 'CM_SHORTCUT_DESKTOP_applications2' 'DesktopFolder'
Component: 'CM_C_EMPTY_CM_DP_extras.extras.empty' 'CM_DP_extras.extras.empty'
Component: 'CM_CP_headers.include.file_with_spaces.h' 'CM_DP_headers.include'
Component: 'CM_CP_headers.include.mylib.h' 'CM_DP_headers.include'
Component: 'CM_CP_libraries.lib.mylib.lib' 'CM_DP_libraries.lib'
Directory: 'INSTALL_ROOT' 'ProgramFiles64Folder' '[^']*\|CPack Component Example'
Directory: 'CM_DP_applications.bin' 'INSTALL_ROOT' 'bin'
Directory: 'PROGRAM_MENU_FOLDER' 'ProgramMenuFolder' 'MyLib'
Directory: 'DesktopFolder' 'TARGETDIR' 'Desktop'
Directory: 'CM_DP_applications2.bin' 'INSTALL_ROOT' 'bin'
Directory: 'CM_DP_extras.extras.empty' 'CM_DP_extras.extras' 'empty'
Directory: 'CM_DP_headers.include' 'INSTALL_ROOT' 'include'
Directory: 'CM_DP_libraries.lib' 'INSTALL_ROOT' 'lib'
Directory: 'CM_DP_extras.extras' 'INSTALL_ROOT' 'extras'
Directory: 'ProgramFiles64Folder' 'TARGETDIR' '.'
Directory: 'TARGETDIR' '' 'SourceDir'
Directory: 'ProgramMenuFolder' 'TARGETDIR' '.'
File: 'CM_FP_applications.bin.my_libapp.exe' 'CM_CP_applications.bin.my_libapp.exe' '[^']*\|my-libapp.exe'
File: 'CM_FP_applications2.bin.my_other_app.exe' 'CM_CP_applications2.bin.my_other_app.exe' '[^']*\|my-other-app.exe'
File: 'CM_FP_headers.include.file_with_spaces.h' 'CM_CP_headers.include.file_with_spaces.h' '[^']*\|file with spaces.h'
File: 'CM_FP_headers.include.mylib.h' 'CM_CP_headers.include.mylib.h' 'mylib.h'
File: 'CM_FP_libraries.lib.mylib.lib' 'CM_CP_libraries.lib.mylib.lib' 'mylib.lib'
Shortcut: 'CM_SP_applications.bin.my_libapp.exe' 'PROGRAM_MENU_FOLDER' '[^']*\|CPack WiX Test' 'CM_SHORTCUT_applications'
Shortcut: 'CM_DSP_applications.bin.my_libapp.exe' 'DesktopFolder' '[^']*\|CPack WiX Test' 'CM_SHORTCUT_DESKTOP_applications'
Shortcut: 'CM_SP_applications2.bin.my_other_app.exe' 'PROGRAM_MENU_FOLDER' '[^']*\|Second CPack WiX Test' 'CM_SHORTCUT_applications2'
Shortcut: 'CM_DSP_applications2.bin.my_other_app.exe' 'DesktopFolder' '[^']*\|Second CPack WiX Test' 'CM_SHORTCUT_DESKTOP_applications2'
--

View File

@@ -0,0 +1,5 @@
include(RunCPack)
set(RunCPack_GENERATORS WIX)
run_cpack(AppWiX BUILD GLOB *.msi VERIFY powershell -ExecutionPolicy Bypass -File ${CMAKE_CURRENT_LIST_DIR}/print-msi.ps1)

View File

@@ -0,0 +1,6 @@
file(GLOB wix_log_file RELATIVE "${RunCMake_TEST_BINARY_DIR}" "${RunCMake_TEST_BINARY_DIR}/_CPack_Packages/*/WIX/wix.log")
if(wix_log_file)
file(READ "${RunCMake_TEST_BINARY_DIR}/${wix_log_file}" wix_log)
string(REPLACE "\n" "\n wix-log> " wix_log " wix-log> ${wix_log}")
set(RunCMake_TEST_FAILURE_MESSAGE "${wix_log_file}:\n${wix_log}")
endif()

View File

@@ -0,0 +1,29 @@
# https://learn.microsoft.com/en-us/windows/win32/msi/database-tables
param (
$file
)
function printTable {
param (
$msi,
[string]$name,
[int[]]$columns = (1)
)
try {
$view = $msi.OpenView("select * from " + $name)
$view.Execute()
while ($record = $view.Fetch()) {
Write-Host ($name + ": " + ($columns | ForEach-Object {"'" + $record.StringData($_) + "'"}))
}
} catch {}
}
$installer = New-Object -ComObject WindowsInstaller.Installer
$msi = $installer.OpenDatabase($file, 0)
printTable -msi $msi -name "Component" -columns 1,3
printTable -msi $msi -name "Directory" -columns 1,2,3
printTable -msi $msi -name "File" -columns 1,2,3
printTable -msi $msi -name "Shortcut" -columns 1,2,3,4