Commit 7d58b3ab authored by Harry Mallon's avatar Harry Mallon

Add soem test to the productbuild generator

parent 3874843f
......@@ -26,3 +26,17 @@
# on OS X. This variable can be used to override the automatically detected
# command (or specify its location if the auto-detection fails to find it.)
#
# .. variable:: CPACK_PRODUCTBUILD_PREINSTALL_SCRIPT_FILE
# CPACK_PRODUCTBUILD_<component>_PREINSTALL_SCRIPT_FILE
#
# Path to a shell script to be added as a pre-installation script. During a
# component install the <component> form can be used to override the global
# variable.
#
# .. variable:: CPACK_PRODUCTBUILD_POSTINSTALL_SCRIPT_FILE
# CPACK_PRODUCTBUILD_<component>_POSTINSTALL_SCRIPT_FILE
#
# Path to a shell script to be added as a post-installation script. During a
# component install the <component> form can be used to override the global
# variable.
#
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include <map>
#include <sstream>
#include <stddef.h>
#include <iostream>
#include "cmCPackComponentGroup.h"
#include "cmCPackLog.h"
......@@ -152,8 +153,14 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage(
const char* comp_name = component ? component->Name.c_str() : NULL;
const char* preflight = this->GetComponentScript("PREFLIGHT", comp_name);
const char* postflight = this->GetComponentScript("POSTFLIGHT", comp_name);
const char* preflight = this->GetComponentScript("PREINSTALL", comp_name);
if (!preflight) {
preflight = this->GetComponentScript("PREINSTALL", CM_NULLPTR);
}
const char* postflight = this->GetComponentScript("POSTINSTALL", comp_name);
if (!postflight) {
postflight = this->GetComponentScript("POSTINSTALL", CM_NULLPTR);
}
std::string resDir = packageFileDir;
if (component) {
......@@ -208,12 +215,12 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage(
const char* cmCPackProductBuildGenerator::GetComponentScript(
const char* script, const char* component_name)
{
std::string scriptname = std::string("CPACK_") + script + "_";
std::string scriptname = std::string("CPACK_PRODUCTBUILD_");
if (component_name) {
scriptname += cmSystemTools::UpperCase(component_name);
scriptname += "_";
}
scriptname += "SCRIPT";
scriptname += script + std::string("_SCRIPT_FILE");
return this->GetOption(scriptname);
}
......@@ -344,7 +344,7 @@ if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
add_RunCMake_test(CompilerLauncher)
endif()
add_RunCMake_test_group(CPack "DEB;RPM;TGZ")
add_RunCMake_test_group(CPack "DEB;RPM;TGZ;productbuild")
# 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)
......
......@@ -206,6 +206,9 @@ To add a new generator we must
should be performed
+ CONTENT_VAR that will contain the input list and is also the variable
in parent scope which should contain the result (converted content list)
- Also in this script a variable must exist:
- ALL_FILES_GLOB: A globbing expression which covers all the output files
(e.g. "*.tar.gz").
- add 'Prerequirements.cmake' script to generator directory. In this script a
function named 'get_test_prerequirements' must exist. This function should
set a variable in parent scope (name of the variable is the first parameter)
......
......@@ -12,7 +12,7 @@ run_cpack_test(EMPTY_DIR "RPM;DEB;TGZ" true "MONOLITHIC;COMPONENT")
run_cpack_test(EXTRA "DEB" false "COMPONENT")
run_cpack_test(GENERATE_SHLIBS "DEB" true "COMPONENT")
run_cpack_test(GENERATE_SHLIBS_LDCONFIG "DEB" true "COMPONENT")
run_cpack_test(INSTALL_SCRIPTS "RPM" false "COMPONENT")
run_cpack_test(INSTALL_SCRIPTS "RPM;productbuild" false "COMPONENT") #
run_cpack_test(LONG_FILENAMES "DEB" false "MONOLITHIC")
run_cpack_test_subtests(MAIN_COMPONENT "invalid;found" "RPM" false "COMPONENT")
run_cpack_test(MINIMAL "RPM;DEB;TGZ" false "MONOLITHIC")
......
set(ALL_FILES_GLOB "*.pkg")
function(getPackageContent FILE RESULT_VAR)
execute_process(COMMAND ${PKGUTIL_EXECUTABLE} --payload-files "${FILE}"
OUTPUT_VARIABLE package_content_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "\./" "/" package_content_ "${package_content_}")
string(REPLACE "\.\n" "" package_content_ "${package_content_}")
set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
endfunction()
function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_VAR)
if(COMPONENT)
set(COMPONENT "-${COMPONENT}")
endif()
set(${RESULT_VAR} "${NAME}-${VERSION}-*${COMPONENT}.pkg" PARENT_SCOPE)
endfunction()
function(getPackageContentList FILE RESULT_VAR)
execute_process(COMMAND ${PKGUTIL_EXECUTABLE} --payload-files "${FILE}"
OUTPUT_VARIABLE package_content_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "\./" "/" package_content_ "${package_content_}")
string(REPLACE "\.\n" "" package_content_ "${package_content_}")
string(REPLACE "\n" ";" package_content_ "${package_content_}")
list(REMOVE_DUPLICATES package_content_)
set(${RESULT_VAR} "${package_content_}" PARENT_SCOPE)
endfunction()
function(toExpectedContentList FILE_NO CONTENT_VAR)
# Do nothing
endfunction()
function(get_test_prerequirements found_var config_file)
find_program(PKGBUILD_EXECUTABLE pkgbuild)
find_program(PRODUCTBUILD_EXECUTABLE productbuild)
find_program(PKGUTIL_EXECUTABLE pkgutil)
if(PKGBUILD_EXECUTABLE AND PRODUCTBUILD_EXECUTABLE AND PKGUTIL_EXECUTABLE)
file(WRITE "${config_file}"
"set(PKGBUILD_EXECUTABLE \"${PKGBUILD_EXECUTABLE}\")")
file(APPEND "${config_file}"
"\nset(PRODUCTBUILD_EXECUTABLE \"${PRODUCTBUILD_EXECUTABLE}\")")
file(APPEND "${config_file}"
"\nset(PKGUTIL_EXECUTABLE \"${PKGUTIL_EXECUTABLE}\")")
set(${found_var} true PARENT_SCOPE)
endif()
endfunction()
set(EXPECTED_FILES_COUNT "2")
set(EXPECTED_FILE_1_COMPONENT "foo")
set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_COMPONENT "bar")
set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
if(GENERATOR_TYPE STREQUAL "RPM")
set(EXPECTED_FILES_COUNT "2")
set(EXPECTED_FILE_1_COMPONENT "foo")
set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_COMPONENT "bar")
set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
elseif(GENERATOR_TYPE STREQUAL "productbuild")
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST "/Applications;/Applications/bar;/Applications/bar/CMakeLists.txt;/Applications/foo;/Applications/foo/CMakeLists.txt")
endif()
\ No newline at end of file
function(checkScripts_ FILE COMPARE_LIST)
set(whitespaces_ "[\t\n\r ]*")
if(GENERATOR_TYPE STREQUAL "RPM")
function(checkScripts_ FILE COMPARE_LIST)
set(whitespaces_ "[\t\n\r ]*")
execute_process(COMMAND ${RPM_EXECUTABLE} -qp --scripts ${FILE}
WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
OUTPUT_VARIABLE FILE_SCRIPTS_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${RPM_EXECUTABLE} -qp --scripts ${FILE}
WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
OUTPUT_VARIABLE FILE_SCRIPTS_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "\n" ";" FILE_SCRIPTS_LIST_ "${FILE_SCRIPTS_}")
string(REPLACE "\n" ";" FILE_SCRIPTS_LIST_ "${FILE_SCRIPTS_}")
foreach(COMPARE_REGEX_ IN LISTS COMPARE_LIST)
unset(FOUND_)
foreach(COMPARE_REGEX_ IN LISTS COMPARE_LIST)
unset(FOUND_)
foreach(COMPARE_ IN LISTS FILE_SCRIPTS_LIST_)
if(COMPARE_ MATCHES "${COMPARE_REGEX_}")
set(FOUND_ true)
break()
foreach(COMPARE_ IN LISTS FILE_SCRIPTS_LIST_)
if(COMPARE_ MATCHES "${COMPARE_REGEX_}")
set(FOUND_ true)
break()
endif()
endforeach()
if(NOT FOUND_)
message(FATAL_ERROR "Missing scripts in '${FILE}'; file info: '${FILE_SCRIPTS_}'; missing: '${COMPARE_REGEX_}'")
endif()
endforeach()
endfunction()
checkScripts_("${FOUND_FILE_1}" "echo \"pre install foo\";echo \"post install foo\";echo \"pre uninstall foo\";echo \"post uninstall foo\"")
checkScripts_("${FOUND_FILE_2}" "echo \"pre install\";echo \"post install\";echo \"pre uninstall\";echo \"post uninstall\"")
elseif(GENERATOR_TYPE STREQUAL "productbuild")
function(checkScripts_ FILE SUBPACKAGE COMPARE_LIST)
set(whitespaces_ "[\t\n\r ]*")
file(REMOVE_RECURSE ${CPACK_TEMPORARY_DIRECTORY}/expanded_tree)
execute_process(COMMAND ${PKGUTIL_EXECUTABLE} --expand ${FILE} expanded_tree
WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}"
ERROR_QUIET
OUTPUT_QUIET
RESULT_VARIABLE success_)
if(NOT FOUND_)
message(FATAL_ERROR "Missing scripts in '${FILE}'; file info: '${FILE_SCRIPTS_}'; missing: '${COMPARE_REGEX_}'")
if(NOT success_ EQUAL 0)
message(FATAL_ERROR "Failed to unpack '${FILE}' ${success_}")
endif()
endforeach()
endfunction()
checkScripts_("${FOUND_FILE_1}" "echo \"pre install foo\";echo \"post install foo\";echo \"pre uninstall foo\";echo \"post uninstall foo\"")
checkScripts_("${FOUND_FILE_2}" "echo \"pre install\";echo \"post install\";echo \"pre uninstall\";echo \"post uninstall\"")
get_filename_component(FILE_NAME_ "${FILE}" NAME_WE)
get_filename_component(FILE_EXT_ "${FILE}" EXT)
set(OUTPUT_DIR_ "${CPACK_TEMPORARY_DIRECTORY}/expanded_tree/${FILE_NAME_}-${SUBPACKAGE}${FILE_EXT_}")
message(ERROR "scac ${OUTPUT_DIR_}")
endfunction()
checkScripts_("${FOUND_FILE_1}" foo "echo \"pre install foo\";echo \"post install foo\"")
checkScripts_("${FOUND_FILE_1}" bar "echo \"pre install\";echo \"post install\"")
endif()
......@@ -16,6 +16,16 @@ if(GENERATOR_TYPE STREQUAL "RPM")
"${CMAKE_CURRENT_BINARY_DIR}/pre_uninstall_foo.sh")
set(CPACK_RPM_foo_POST_UNINSTALL_SCRIPT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/post_uninstall_foo.sh")
elseif(GENERATOR_TYPE STREQUAL "productbuild")
set(CPACK_PRODUCTBUILD_PREINSTALL_SCRIPT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/pre_install.sh")
set(CPACK_PRODUCTBUILD_POSTINSTALL_SCRIPT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/post_install.sh")
set(CPACK_PRODUCTBUILD_FOO_PREINSTALL_SCRIPT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/pre_install_foo.sh")
set(CPACK_PRODUCTBUILD_FOO_POSTINSTALL_SCRIPT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/post_install_foo.sh")
endif()
set(CMAKE_BUILD_WITH_INSTALL_RPATH 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment