From 45ed314bfff5b9b59dcba8139ab1c695a81a05f3 Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Mon, 27 Jul 2020 20:56:26 -0400 Subject: BundleUtilities: do not run install_name_tool on scripts Use the same approach as commit 08be74bfd7 (GetPrerequisites: Fix handling of executable scripts, 2018-12-16, v3.14.0-rc1~206^2). --- Modules/BundleUtilities.cmake | 15 ++++++++++----- Tests/RunCMake/BundleUtilities/ExecutableScripts.cmake | 18 ++++++++++++++++++ Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake | 1 + Tests/RunCMake/BundleUtilities/test.app/script | 3 +++ Tests/RunCMake/BundleUtilities/test.app/script.bat | 3 +++ Tests/RunCMake/BundleUtilities/test.app/script.sh | 3 +++ 6 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 Tests/RunCMake/BundleUtilities/ExecutableScripts.cmake create mode 100755 Tests/RunCMake/BundleUtilities/test.app/script create mode 100755 Tests/RunCMake/BundleUtilities/test.app/script.bat create mode 100755 Tests/RunCMake/BundleUtilities/test.app/script.sh diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake index 2f3b9e1..f521d22 100644 --- a/Modules/BundleUtilities.cmake +++ b/Modules/BundleUtilities.cmake @@ -894,11 +894,16 @@ function(fixup_bundle_item resolved_embedded_item exepath dirs) # to install_name_tool: # if(changes) - set(cmd ${CMAKE_INSTALL_NAME_TOOL} ${changes} "${resolved_embedded_item}") - execute_process(COMMAND ${cmd} RESULT_VARIABLE install_name_tool_result) - if(NOT install_name_tool_result EQUAL 0) - string(REPLACE ";" "' '" msg "'${cmd}'") - message(FATAL_ERROR "Command failed:\n ${msg}") + # Check for a script by extension (.bat,.sh,...) or if the file starts with "#!" (shebang) + file(READ ${resolved_embedded_item} file_contents LIMIT 5) + if(NOT "${resolved_embedded_item}" MATCHES "\\.(bat|c?sh|bash|ksh|cmd)$" AND + NOT file_contents MATCHES "^#!") + set(cmd ${CMAKE_INSTALL_NAME_TOOL} ${changes} "${resolved_embedded_item}") + execute_process(COMMAND ${cmd} RESULT_VARIABLE install_name_tool_result) + if(NOT install_name_tool_result EQUAL 0) + string(REPLACE ";" "' '" msg "'${cmd}'") + message(FATAL_ERROR "Command failed:\n ${msg}") + endif() endif() endif() endfunction() diff --git a/Tests/RunCMake/BundleUtilities/ExecutableScripts.cmake b/Tests/RunCMake/BundleUtilities/ExecutableScripts.cmake new file mode 100644 index 0000000..78a9b66 --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/ExecutableScripts.cmake @@ -0,0 +1,18 @@ +include(BundleUtilities) + +set(BU_CHMOD_BUNDLE_ITEMS ON) + +function(check_script script) + fixup_bundle_item(${script} ${script} "" "") +endfunction() + +# Should not throw any errors +# Shell script +set(script_sh_EMBEDDED_ITEM ${CMAKE_CURRENT_LIST_DIR}/test.app/script.sh) +check_script(${CMAKE_CURRENT_LIST_DIR}/test.app/script.sh) +# Batch script +set(script_bat_EMBEDDED_ITEM ${CMAKE_CURRENT_LIST_DIR}/test.app/script.bat) +check_script(${CMAKE_CURRENT_LIST_DIR}/test.app/script.bat) +# Shell script without extension +set(script_EMBEDDED_ITEM ${CMAKE_CURRENT_LIST_DIR}/test.app/script) +check_script(${CMAKE_CURRENT_LIST_DIR}/test.app/script) diff --git a/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake b/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake index 14aaff1..df28102 100644 --- a/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake +++ b/Tests/RunCMake/BundleUtilities/RunCMakeTest.cmake @@ -9,3 +9,4 @@ run_cmake(CMP0080-WARN) run_cmake_command(CMP0080-COMMAND-OLD ${CMAKE_COMMAND} -DCMP0080_VALUE:STRING=OLD -P ${RunCMake_SOURCE_DIR}/CMP0080-COMMAND.cmake) run_cmake_command(CMP0080-COMMAND-NEW ${CMAKE_COMMAND} -DCMP0080_VALUE:STRING=NEW -P ${RunCMake_SOURCE_DIR}/CMP0080-COMMAND.cmake) run_cmake_command(CMP0080-COMMAND-WARN ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/CMP0080-COMMAND.cmake) +run_cmake_command(ExecutableScripts ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/ExecutableScripts.cmake) diff --git a/Tests/RunCMake/BundleUtilities/test.app/script b/Tests/RunCMake/BundleUtilities/test.app/script new file mode 100755 index 0000000..23bf47c --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/test.app/script @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Hello World" diff --git a/Tests/RunCMake/BundleUtilities/test.app/script.bat b/Tests/RunCMake/BundleUtilities/test.app/script.bat new file mode 100755 index 0000000..dbb0ec2 --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/test.app/script.bat @@ -0,0 +1,3 @@ +@echo off + +echo "Hello world" diff --git a/Tests/RunCMake/BundleUtilities/test.app/script.sh b/Tests/RunCMake/BundleUtilities/test.app/script.sh new file mode 100755 index 0000000..23bf47c --- /dev/null +++ b/Tests/RunCMake/BundleUtilities/test.app/script.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Hello World" -- cgit v0.12