diff options
author | Alexander Grund <git@grundis.de> | 2018-12-16 17:05:23 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2019-01-04 22:09:39 (GMT) |
commit | 08be74bfd7e24af9ffdb64dddffd3d56bf52c3ce (patch) | |
tree | 78cb35917baeebf19f4521152c1dc66ab3451e9d | |
parent | 52445300d67df73b5b8c288cc33c915053c7ba24 (diff) | |
download | CMake-08be74bfd7e24af9ffdb64dddffd3d56bf52c3ce.zip CMake-08be74bfd7e24af9ffdb64dddffd3d56bf52c3ce.tar.gz CMake-08be74bfd7e24af9ffdb64dddffd3d56bf52c3ce.tar.bz2 |
GetPrerequisites: Fix handling of executable scripts
Fixes: #18667
-rw-r--r-- | Modules/GetPrerequisites.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake | 19 | ||||
-rw-r--r-- | Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake | 1 | ||||
-rwxr-xr-x | Tests/RunCMake/GetPrerequisites/script | 3 | ||||
-rwxr-xr-x | Tests/RunCMake/GetPrerequisites/script.bat | 3 | ||||
-rwxr-xr-x | Tests/RunCMake/GetPrerequisites/script.sh | 3 |
7 files changed, 41 insertions, 0 deletions
diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index d3b773c..fa6d75a 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -660,6 +660,15 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa return() endif() + # Check for a script by extension (.bat,.sh,...) or if the file starts with "#!" (shebang) + file(READ ${target} file_contents LIMIT 5) + if(target MATCHES "\\.(bat|c?sh|bash|ksh|cmd)$" OR file_contents MATCHES "^#!") + message(STATUS "GetPrequisites(${target}) : ignoring script file") + # Clear var + set(${prerequisites_var} "" PARENT_SCOPE) + return() + endif() + set(gp_cmd_paths ${gp_cmd_paths} "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0;InstallDir]/../../VC/bin" "$ENV{VS140COMNTOOLS}/../../VC/bin" diff --git a/Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt b/Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt new file mode 100644 index 0000000..5a353d8 --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt @@ -0,0 +1,3 @@ +-- GetPrequisites\(.*script.sh\) : ignoring script file +-- GetPrequisites\(.*script.bat\) : ignoring script file +-- GetPrequisites\(.*script\) : ignoring script file diff --git a/Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake b/Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake new file mode 100644 index 0000000..d1bc9b1 --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake @@ -0,0 +1,19 @@ +include(GetPrerequisites) + +function(check_script script) + set(prereqs "") + get_prerequisites(${script} prereqs 1 1 "" "") + if(NOT "${prereqs}" STREQUAL "") + message(FATAL_ERROR "Prerequisites for ${script} not empty") + endif() +endfunction() + +# Should not throw any errors +# Regular executable +get_prerequisites(${CMAKE_COMMAND} cmake_prereqs 1 1 "" "") +# Shell script +check_script(${CMAKE_CURRENT_LIST_DIR}/script.sh) +# Batch script +check_script(${CMAKE_CURRENT_LIST_DIR}/script.bat) +# Shell script without extension +check_script(${CMAKE_CURRENT_LIST_DIR}/script) diff --git a/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake b/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake index 3856c54..a635e38 100644 --- a/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake +++ b/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake @@ -1,3 +1,4 @@ include(RunCMake) run_cmake_command(TargetMissing ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TargetMissing.cmake) +run_cmake_command(ExecutableScripts ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/ExecutableScripts.cmake) diff --git a/Tests/RunCMake/GetPrerequisites/script b/Tests/RunCMake/GetPrerequisites/script new file mode 100755 index 0000000..23bf47c --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/script @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Hello World" diff --git a/Tests/RunCMake/GetPrerequisites/script.bat b/Tests/RunCMake/GetPrerequisites/script.bat new file mode 100755 index 0000000..dbb0ec2 --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/script.bat @@ -0,0 +1,3 @@ +@echo off + +echo "Hello world" diff --git a/Tests/RunCMake/GetPrerequisites/script.sh b/Tests/RunCMake/GetPrerequisites/script.sh new file mode 100755 index 0000000..23bf47c --- /dev/null +++ b/Tests/RunCMake/GetPrerequisites/script.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Hello World" |