From 808ae844830da1e2fc686fdd21faf7bd3b7607c6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 17 Oct 2024 14:48:37 -0400 Subject: [PATCH] cmFind*Command: Simplify file validation code paths --- Source/cmFindLibraryCommand.cxx | 7 ++----- Source/cmFindProgramCommand.cxx | 17 +++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 3d3ee2527f..ecd1130b78 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -422,18 +422,15 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, if (name.TryRaw) { std::string testPath = cmStrCat(path, name.Raw); - const bool exists = cmSystemTools::FileExists(testPath, true); - if (!exists) { - this->DebugLibraryFailed(name.Raw, path); - } else { + if (cmSystemTools::FileExists(testPath, true)) { testPath = cmSystemTools::CollapseFullPath(testPath); if (this->Validate(testPath)) { this->DebugLibraryFound(name.Raw, path); this->BestPath = testPath; return true; } - this->DebugLibraryFailed(name.Raw, path); } + this->DebugLibraryFailed(name.Raw, path); } // No library file has yet been found. diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index d73d38adb0..fc251fc808 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -88,17 +88,18 @@ struct cmFindProgramHelper std::string testNameExt = cmStrCat(name, ext); std::string testPath = cmSystemTools::CollapseFullPath(testNameExt, path); - bool exists = this->FileIsValid(testPath); - exists ? this->DebugSearches.FoundAt(testPath) - : this->DebugSearches.FailedAt(testPath); - if (exists) { - this->BestPath = testPath; - return true; + if (this->FileIsExecutable(testPath)) { + if (this->FindBase->Validate(testPath)) { + this->BestPath = testPath; + this->DebugSearches.FoundAt(testPath); + return true; + } } + this->DebugSearches.FailedAt(testPath); return false; }); } - bool FileIsValid(std::string const& file) const + bool FileIsExecutable(std::string const& file) const { if (!this->FileIsExecutableCMP0109(file)) { return false; @@ -114,7 +115,7 @@ struct cmFindProgramHelper } } #endif - return this->FindBase->Validate(file); + return true; } bool FileIsExecutableCMP0109(std::string const& file) const {