diff options
author | Brad King <brad.king@kitware.com> | 2020-06-10 14:23:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-06-15 15:58:47 (GMT) |
commit | 9d45a8be085490a6c3ce4db27968247297a8bdd2 (patch) | |
tree | 6a03a90c1d5b667f0c3541f31eb86ce0ef02c048 /Source/cmFindProgramCommand.cxx | |
parent | 43b10e2411858ae7734c54480a8c0c6c3ccd659b (diff) | |
download | CMake-9d45a8be085490a6c3ce4db27968247297a8bdd2.zip CMake-9d45a8be085490a6c3ce4db27968247297a8bdd2.tar.gz CMake-9d45a8be085490a6c3ce4db27968247297a8bdd2.tar.bz2 |
find_program: Find programs that are executable but not readable
This fix was first made by commit 86e6349ef7 (find_program: Find
programs that are executable but not readable, 2020-04-04,
v3.18.0-rc1~372^2) but was reverted for compatibility. Re-introduce it
with a policy for compatibility.
Fixes: #10468
Diffstat (limited to 'Source/cmFindProgramCommand.cxx')
-rw-r--r-- | Source/cmFindProgramCommand.cxx | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 4f3fcdd..77728ec 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -4,6 +4,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmPolicies.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -19,6 +20,7 @@ struct cmFindProgramHelper cmFindProgramHelper(cmMakefile* makefile, cmFindBase const* base) : DebugSearches("find_program", base) , Makefile(makefile) + , PolicyCMP0109(makefile->GetPolicyStatus(cmPolicies::CMP0109)) { #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) // Consider platform-specific extensions. @@ -48,6 +50,8 @@ struct cmFindProgramHelper cmFindBaseDebugState DebugSearches; cmMakefile* Makefile; + cmPolicies::PolicyStatus PolicyCMP0109; + void AddName(std::string const& name) { this->Names.push_back(name); } void SetName(std::string const& name) { @@ -85,7 +89,7 @@ struct cmFindProgramHelper this->TestNameExt = cmStrCat(name, ext); this->TestPath = cmSystemTools::CollapseFullPath(this->TestNameExt, path); - bool exists = cmSystemTools::FileExists(this->TestPath, true); + bool exists = this->FileIsExecutable(this->TestPath); exists ? this->DebugSearches.FoundAt(this->TestPath) : this->DebugSearches.FailedAt(this->TestPath); if (exists) { @@ -95,6 +99,48 @@ struct cmFindProgramHelper } return false; } + bool FileIsExecutable(std::string const& file) const + { + switch (this->PolicyCMP0109) { + case cmPolicies::OLD: + return cmSystemTools::FileExists(file, true); + case cmPolicies::NEW: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + return cmSystemTools::FileIsExecutable(file); + default: + break; + } + bool const isExeOld = cmSystemTools::FileExists(file, true); + bool const isExeNew = cmSystemTools::FileIsExecutable(file); + if (isExeNew == isExeOld) { + return isExeNew; + } + if (isExeNew) { + this->Makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0109), + "\n" + "The file\n" + " ", + file, + "\n" + "is executable but not readable. " + "CMake is ignoring it for compatibility.")); + } else { + this->Makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0109), + "\n" + "The file\n" + " ", + file, + "\n" + "is readable but not executable. " + "CMake is using it for compatibility.")); + } + return isExeOld; + } }; cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status) |