From 2cc7baa1bc7f9e37b1a19d6700c64890142030d8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 7 Apr 2020 10:14:58 -0400 Subject: Tests: Fix get_filename_component PROGRAM test to use an executable --- Tests/RunCMake/get_filename_component/KnownComponents.cmake | 8 ++++---- Tests/RunCMake/get_filename_component/KnownComponents.sh | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100755 Tests/RunCMake/get_filename_component/KnownComponents.sh diff --git a/Tests/RunCMake/get_filename_component/KnownComponents.cmake b/Tests/RunCMake/get_filename_component/KnownComponents.cmake index 54b858f..c2762ad 100644 --- a/Tests/RunCMake/get_filename_component/KnownComponents.cmake +++ b/Tests/RunCMake/get_filename_component/KnownComponents.cmake @@ -85,12 +85,12 @@ check("PROGRAM with args output: args" "${test_program_args}" " arg1 arg2") get_filename_component(test_program_name " " PROGRAM) check("PROGRAM with just a space" "${test_program_name}" "") -get_filename_component(test_program_name "${CMAKE_CURRENT_LIST_FILE}" PROGRAM) -check("PROGRAM specified explicitly without quoting" "${test_program_name}" "${CMAKE_CURRENT_LIST_FILE}") +get_filename_component(test_program_name "${CMAKE_CURRENT_LIST_DIR}/KnownComponents.sh" PROGRAM) +check("PROGRAM specified explicitly without quoting" "${test_program_name}" "${CMAKE_CURRENT_LIST_DIR}/KnownComponents.sh") -get_filename_component(test_program_name "\"${CMAKE_CURRENT_LIST_FILE}\" arg1 arg2" PROGRAM +get_filename_component(test_program_name "\"${CMAKE_CURRENT_LIST_DIR}/KnownComponents.sh\" arg1 arg2" PROGRAM PROGRAM_ARGS test_program_args) -check("PROGRAM specified explicitly with arguments: name" "${test_program_name}" "${CMAKE_CURRENT_LIST_FILE}") +check("PROGRAM specified explicitly with arguments: name" "${test_program_name}" "${CMAKE_CURRENT_LIST_DIR}/KnownComponents.sh") check("PROGRAM specified explicitly with arguments: args" "${test_program_args}" " arg1 arg2") list(APPEND non_cache_vars test_program_name) diff --git a/Tests/RunCMake/get_filename_component/KnownComponents.sh b/Tests/RunCMake/get_filename_component/KnownComponents.sh new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/Tests/RunCMake/get_filename_component/KnownComponents.sh @@ -0,0 +1 @@ +#!/bin/sh -- cgit v0.12 From c5635588adbfa0428ca738c3ed3e690ae058af37 Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Tue, 7 Apr 2020 08:05:31 -0400 Subject: KWSys 2020-04-07 (caff9c3b) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit caff9c3bf3c9a95f4ac7f700532633603352e506 (master). Upstream Shortlog ----------------- Vladimir Menshakov (1): 66724af8 SystemTools: Teach FindProgram to find non-readable programs --- SystemTools.cxx | 19 ++++++++++++------- SystemTools.hxx.in | 5 +++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index 5ae4ff8..880b2d2 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2807,7 +2807,7 @@ std::string SystemTools::FindProgram(const std::string& name, for (std::string const& ext : extensions) { tryPath = name; tryPath += ext; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -2815,7 +2815,7 @@ std::string SystemTools::FindProgram(const std::string& name, #endif // now try just the name - if (SystemTools::FileExists(name, true)) { + if (SystemTools::FileIsExecutable(name)) { return SystemTools::CollapseFullPath(name); } // now construct the path @@ -2845,7 +2845,7 @@ std::string SystemTools::FindProgram(const std::string& name, tryPath = p; tryPath += name; tryPath += ext; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -2853,7 +2853,7 @@ std::string SystemTools::FindProgram(const std::string& name, // now try it without them tryPath = p; tryPath += name; - if (SystemTools::FileExists(tryPath, true)) { + if (SystemTools::FileIsExecutable(tryPath)) { return SystemTools::CollapseFullPath(tryPath); } } @@ -3008,6 +3008,11 @@ bool SystemTools::FileIsDirectory(const std::string& inName) } } +bool SystemTools::FileIsExecutable(const std::string& name) +{ + return !FileIsDirectory(name) && TestFileAccess(name, TEST_FILE_EXECUTE); +} + bool SystemTools::FileIsSymlink(const std::string& name) { #if defined(_WIN32) @@ -3172,7 +3177,7 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, failures.push_back(self); SystemTools::ConvertToUnixSlashes(self); self = SystemTools::FindProgram(self); - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { if (buildDir) { std::string intdir = "."; #ifdef CMAKE_INTDIR @@ -3187,14 +3192,14 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut, } } if (installPrefix) { - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); self = installPrefix; self += "/bin/"; self += exeName; } } - if (!SystemTools::FileExists(self)) { + if (!SystemTools::FileIsExecutable(self)) { failures.push_back(self); std::ostringstream msg; msg << "Can not find the command line program "; diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index e13d03e..cd7b728 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -677,6 +677,11 @@ public: static bool FileIsDirectory(const std::string& name); /** + * Return true if the file is an executable + */ + static bool FileIsExecutable(const std::string& name); + + /** * Return true if the file is a symlink */ static bool FileIsSymlink(const std::string& name); -- cgit v0.12