From 542ba6ac1a50c3900457431819e5eb328f3a29ee Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 14 Jan 2022 12:26:55 -0500 Subject: Tests: Add CPack/DMG case covering SLA from CPACK_RESOURCE_FILE_LICENSE --- Tests/RunCMake/CPack/RunCMakeTest.cmake | 1 + .../RunCMake/CPack/tests/DMG_SLA_FILE/Example.txt | 4 ++++ .../CPack/tests/DMG_SLA_FILE/ExpectedFiles.cmake | 2 ++ .../CPack/tests/DMG_SLA_FILE/VerifyResult.cmake | 22 ++++++++++++++++++++++ Tests/RunCMake/CPack/tests/DMG_SLA_FILE/test.cmake | 2 ++ 5 files changed, 31 insertions(+) create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_FILE/Example.txt create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_FILE/ExpectedFiles.cmake create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_FILE/VerifyResult.cmake create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_FILE/test.cmake diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake index eb9ff03..d318ce6 100644 --- a/Tests/RunCMake/CPack/RunCMakeTest.cmake +++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake @@ -21,6 +21,7 @@ if(NOT "${DEBUGEDIT}" STREQUAL "DEBUGEDIT-NOTFOUND") endif() run_cpack_test(DIST "RPM.DIST" false "MONOLITHIC") run_cpack_test(DMG_SLA "DragNDrop" false "MONOLITHIC") +run_cpack_test(DMG_SLA_FILE "DragNDrop" false "MONOLITHIC") run_cpack_test(EMPTY_DIR "RPM.EMPTY_DIR;DEB.EMPTY_DIR;TGZ" true "MONOLITHIC;COMPONENT") run_cpack_test(VERSION "RPM.VERSION;DEB.VERSION" false "MONOLITHIC;COMPONENT") run_cpack_test(EXTRA "DEB.EXTRA" false "COMPONENT") diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/Example.txt b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/Example.txt new file mode 100644 index 0000000..94b19c3 --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/Example.txt @@ -0,0 +1,4 @@ +Example License File +-------------------- + +This is an example license file for a DMG. diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/ExpectedFiles.cmake new file mode 100644 index 0000000..d1a3a5f --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/ExpectedFiles.cmake @@ -0,0 +1,2 @@ +set(EXPECTED_FILES_COUNT "1") +set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt") diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/VerifyResult.cmake new file mode 100644 index 0000000..55fb3fb --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/VerifyResult.cmake @@ -0,0 +1,22 @@ +set(dmg "${bin_dir}/${FOUND_FILE_1}") +execute_process(COMMAND hdiutil udifderez -xml "${dmg}" OUTPUT_VARIABLE out ERROR_VARIABLE err RESULT_VARIABLE res) +if(NOT res EQUAL 0) + string(REPLACE "\n" "\n " err " ${err}") + message(FATAL_ERROR "Running 'hdiutil udifderez -xml' on\n ${dmg}\nfailed with:\n${err}") +endif() +foreach(key "LPic" "STR#" "TEXT") + if(NOT out MATCHES "${key}") + string(REPLACE "\n" "\n " out " ${out}") + message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${dmg}\ndid not show '${key}' key:\n${out}") + endif() +endforeach() +foreach(line + # TEXT first and last base64 lines + "\tRXhhbXBsZSBMaWNlbnNlIEZpbGUNLS0tLS0tLS0tLS0tLS0tLS0t\n" + "\tYSBETUcuDQ0=\n" + ) + if(NOT out MATCHES "${line}") + string(REPLACE "\n" "\n " out " ${out}") + message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${dmg}\ndid not show '${line}':\n${out}") + endif() +endforeach() diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/test.cmake b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/test.cmake new file mode 100644 index 0000000..eac820e --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_FILE/test.cmake @@ -0,0 +1,2 @@ +install(FILES CMakeLists.txt DESTINATION foo) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/Example.txt") -- cgit v0.12 From 9e38bfa915c142edcf7d6e154fa1dc10bba400f1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 14 Jan 2022 11:40:23 -0500 Subject: CPack/DMG: Add explicit option to use CPACK_RESOURCE_FILE_LICENSE for SLA Since macOS 12.0, the ``hdiutil udifrez`` and ``hdiutil udifderez`` commands to embed and extract resources in a disk image are deprecated. The CPack DragNDrop Generator uses these to attach the SLA specified by the `CPACK_RESOURCE_FILE_LICENSE` option. Since that option is shared by multiple CPack generators, we cannot deprecate it. Instead, add an explicit option to control the behavior. This will give projects a way to package on future macOS versions that remove the commands. In order to provide a long-term transition away from attaching SLAs to disk images, update `cpack` to default this behavior to OFF. To retain compatibility for CMake projects, teach the CPack module to default the option to ON. Later a policy can be added to change the default. Issue: #22978 --- Help/cpack_gen/dmg.rst | 21 +++++++++++++++++++++ Help/release/dev/cpack-dmg-sla.rst | 9 +++++++++ Modules/CPack.cmake | 5 +++++ Source/CPack/cmCPackDragNDropGenerator.cxx | 10 +++++++--- Tests/RunCMake/CPack/RunCMakeTest.cmake | 1 + Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt | 4 ++++ .../CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake | 2 ++ .../CPack/tests/DMG_SLA_OFF/VerifyResult.cmake | 12 ++++++++++++ Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake | 3 +++ 9 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 Help/release/dev/cpack-dmg-sla.rst create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_OFF/VerifyResult.cmake create mode 100644 Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake diff --git a/Help/cpack_gen/dmg.rst b/Help/cpack_gen/dmg.rst index 1f05618..b4ef5a2 100644 --- a/Help/cpack_gen/dmg.rst +++ b/Help/cpack_gen/dmg.rst @@ -54,6 +54,27 @@ on macOS: Default behavior is to include a symlink to ``/Applications`` in the DMG. Set this option to ``ON`` to avoid adding the symlink. +.. variable:: CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE + + .. versionadded:: 3.23 + + Control whether :variable:`CPACK_RESOURCE_FILE_LICENSE`, if set to a + non-default value, is used as the license agreement provided when + mounting the DMG. If ``CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE`` is + not set, :manual:`cpack(1)` defaults to off. + + In a CMake project that uses the :module:`CPack` module to generate + ``CPackConfig.cmake``, ``CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE`` + is automatically enabled by default if it is not set and + :variable:`CPACK_RESOURCE_FILE_LICENSE` is set to a non-default value. + + .. note:: + + This option was added in response to macOS 12.0's deprecation of + the ``hdiutil udifrez`` command to make its use optional. + CPack 3.22 and below always use :variable:`CPACK_RESOURCE_FILE_LICENSE`, + if set to a non-default value, as the DMG license. + .. variable:: CPACK_DMG_SLA_DIR .. versionadded:: 3.5 diff --git a/Help/release/dev/cpack-dmg-sla.rst b/Help/release/dev/cpack-dmg-sla.rst new file mode 100644 index 0000000..c6a3596 --- /dev/null +++ b/Help/release/dev/cpack-dmg-sla.rst @@ -0,0 +1,9 @@ +cpack-dmg-sla +------------- + +* The :cpack_gen:`CPack DragNDrop Generator` no longer attaches + :variable:`CPACK_RESOURCE_FILE_LICENSE` as the license agreement in + the generated ``.dmg`` unless explicitly activated by a + :variable:`CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE` option. + In CMake projects, the :module:`CPack` module enables the option + by default for compatibility. diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index 50a9525..6650f7c 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -805,6 +805,11 @@ _cpack_set_default(CPACK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") _cpack_set_default(CPACK_NSIS_INSTALLER_ICON_CODE "") _cpack_set_default(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "") +# DragNDrop specific variables +if(CPACK_RESOURCE_FILE_LICENSE AND NOT CPACK_RESOURCE_FILE_LICENSE STREQUAL "${CMAKE_ROOT}/Templates/CPack.GenericLicense.txt") + _cpack_set_default(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE ON) +endif() + # WiX specific variables _cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}") diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 9385a5a..0f7acfb 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -98,7 +98,9 @@ int cmCPackDragNDropGenerator::InitializeInternal() if (this->IsSet("CPACK_DMG_SLA_DIR")) { slaDirectory = this->GetOption("CPACK_DMG_SLA_DIR"); - if (!slaDirectory.empty() && this->IsSet("CPACK_RESOURCE_FILE_LICENSE")) { + if (!slaDirectory.empty() && + this->IsOn("CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE") && + this->IsSet("CPACK_RESOURCE_FILE_LICENSE")) { std::string license_file = this->GetOption("CPACK_RESOURCE_FILE_LICENSE"); if (!license_file.empty() && @@ -278,8 +280,10 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, : "HFS+"; // Get optional arguments ... - std::string cpack_license_file = - *this->GetOption("CPACK_RESOURCE_FILE_LICENSE"); + std::string cpack_license_file; + if (this->IsOn("CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE")) { + cpack_license_file = *this->GetOption("CPACK_RESOURCE_FILE_LICENSE"); + } cmValue cpack_dmg_background_image = this->GetOption("CPACK_DMG_BACKGROUND_IMAGE"); diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake index d318ce6..ef4cf5e 100644 --- a/Tests/RunCMake/CPack/RunCMakeTest.cmake +++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake @@ -22,6 +22,7 @@ endif() run_cpack_test(DIST "RPM.DIST" false "MONOLITHIC") run_cpack_test(DMG_SLA "DragNDrop" false "MONOLITHIC") run_cpack_test(DMG_SLA_FILE "DragNDrop" false "MONOLITHIC") +run_cpack_test(DMG_SLA_OFF "DragNDrop" false "MONOLITHIC") run_cpack_test(EMPTY_DIR "RPM.EMPTY_DIR;DEB.EMPTY_DIR;TGZ" true "MONOLITHIC;COMPONENT") run_cpack_test(VERSION "RPM.VERSION;DEB.VERSION" false "MONOLITHIC;COMPONENT") run_cpack_test(EXTRA "DEB.EXTRA" false "COMPONENT") diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt new file mode 100644 index 0000000..94b19c3 --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/Example.txt @@ -0,0 +1,4 @@ +Example License File +-------------------- + +This is an example license file for a DMG. diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake new file mode 100644 index 0000000..d1a3a5f --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/ExpectedFiles.cmake @@ -0,0 +1,2 @@ +set(EXPECTED_FILES_COUNT "1") +set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt") diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/VerifyResult.cmake new file mode 100644 index 0000000..571a4df --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/VerifyResult.cmake @@ -0,0 +1,12 @@ +set(dmg "${bin_dir}/${FOUND_FILE_1}") +execute_process(COMMAND hdiutil udifderez -xml "${dmg}" OUTPUT_VARIABLE out ERROR_VARIABLE err RESULT_VARIABLE res) +if(NOT res EQUAL 0) + string(REPLACE "\n" "\n " err " ${err}") + message(FATAL_ERROR "Running 'hdiutil udifderez -xml' on\n ${dmg}\nfailed with:\n${err}") +endif() +foreach(key "LPic" "STR#" "TEXT") + if(out MATCHES "${key}") + string(REPLACE "\n" "\n " out " ${out}") + message(FATAL_ERROR "error: running 'hdiutil udifderez -xml' on\n ${dmg}\nhas unexpected '${key}' key:\n${out}") + endif() +endforeach() diff --git a/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake new file mode 100644 index 0000000..2b09cab --- /dev/null +++ b/Tests/RunCMake/CPack/tests/DMG_SLA_OFF/test.cmake @@ -0,0 +1,3 @@ +install(FILES CMakeLists.txt DESTINATION foo) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/Example.txt") +set(CPACK_DMG_SLA_USE_RESOURCE_FILE_LICENSE OFF) -- cgit v0.12