From 4336afc49018b95271bdf48a32a81e55ea57ab07 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 7 Apr 2025 19:20:37 -0400 Subject: [PATCH 1/3] SystemTools: Remove redundant FindProgramPath function It just wraps around `FindProgram` with operations that can be better performed by the caller. --- SystemTools.cxx | 27 --------------------------- SystemTools.hxx.in | 15 --------------- 2 files changed, 42 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index 463ff71..77df8c8 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -3380,33 +3380,6 @@ bool SystemTools::SplitProgramPath(std::string const& in_name, return true; } -bool SystemTools::FindProgramPath(char const* argv0, std::string& pathOut, - std::string& errorMsg) -{ - std::vector failures; - std::string self = argv0 ? argv0 : ""; - failures.push_back(self); - SystemTools::ConvertToUnixSlashes(self); - self = SystemTools::FindProgram(self); - if (!SystemTools::FileIsExecutable(self)) { - failures.push_back(self); - std::ostringstream msg; - msg << "Can not find the command line program "; - msg << "\n"; - if (argv0) { - msg << " argv[0] = \"" << argv0 << "\"\n"; - } - msg << " Attempted paths:\n"; - for (std::string const& ff : failures) { - msg << " \"" << ff << "\"\n"; - } - errorMsg = msg.str(); - return false; - } - pathOut = self; - return true; -} - static void SystemToolsAppendComponents( std::vector& out_components, std::vector::iterator first, diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index c47888e..a7d6b9d 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -382,21 +382,6 @@ public: static bool SplitProgramPath(std::string const& in_name, std::string& dir, std::string& file, bool errorReport = true); - /** - * Given argv[0] for a unix program find the full path to a running - * executable. argv0 can be null for windows WinMain programs - * in this case GetModuleFileName will be used to find the path - * to the running executable. If argv0 is not a full path, - * then this will try to find the full path. If the path is not - * found false is returned, if found true is returned. An error - * message of the attempted paths is stored in errorMsg. - * exeName is the name of the executable. - * buildDir is a possibly null path to the build directory. - * installPrefix is a possibly null pointer to the install directory. - */ - static bool FindProgramPath(char const* argv0, std::string& pathOut, - std::string& errorMsg); - /** * Given a path to a file or directory, convert it to a full path. * This collapses away relative paths relative to the cwd argument -- GitLab From 54219234f4401405d2f87a285f0d7178a959052a Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 7 Apr 2025 19:21:51 -0400 Subject: [PATCH 2/3] SystemTools: Remove redundant FindProgram signatures The caller can easily convert arguments to use the primary signature. --- SystemTools.cxx | 25 ------------------------- SystemTools.hxx.in | 8 -------- 2 files changed, 33 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index 77df8c8..cf9068f 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2893,17 +2893,6 @@ std::string SystemTools::FindDirectory( * the system search path. Returns the full path to the executable if it is * found. Otherwise, the empty string is returned. */ -std::string SystemTools::FindProgram(char const* nameIn, - std::vector const& userPaths, - bool no_system_path) -{ - if (!nameIn || !*nameIn) { - return ""; - } - return SystemTools::FindProgram(std::string(nameIn), userPaths, - no_system_path); -} - std::string SystemTools::FindProgram(std::string const& name, std::vector const& userPaths, bool no_system_path) @@ -2975,20 +2964,6 @@ std::string SystemTools::FindProgram(std::string const& name, return ""; } -std::string SystemTools::FindProgram(std::vector const& names, - std::vector const& path, - bool noSystemPath) -{ - for (std::string const& name : names) { - // Try to find the program. - std::string result = SystemTools::FindProgram(name, path, noSystemPath); - if (!result.empty()) { - return result; - } - } - return ""; -} - /** * Find the library with the given name. Searches the given path and then * the system search path. Returns the full path to the library if it is diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index a7d6b9d..9506f82 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -711,18 +711,10 @@ public: /** * Find an executable in the system PATH, with optional extra paths */ - static std::string FindProgram( - char const* name, - std::vector const& path = std::vector(), - bool no_system_path = false); static std::string FindProgram( std::string const& name, std::vector const& path = std::vector(), bool no_system_path = false); - static std::string FindProgram( - std::vector const& names, - std::vector const& path = std::vector(), - bool no_system_path = false); /** * Find a library in the system PATH, with optional extra paths -- GitLab From 7a633bad6790a7c37a715b8d901387ba19cb1cec Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 8 Apr 2025 09:59:36 -0400 Subject: [PATCH 3/3] SystemTools: Remove FindLibrary This was only used by CMake, which does its own thing now. --- SystemTools.cxx | 85 ---------------------------------------------- SystemTools.hxx.in | 6 ---- 2 files changed, 91 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index cf9068f..595bec0 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2964,91 +2964,6 @@ std::string SystemTools::FindProgram(std::string const& name, return ""; } -/** - * Find the library with the given name. Searches the given path and then - * the system search path. Returns the full path to the library if it is - * found. Otherwise, the empty string is returned. - */ -std::string SystemTools::FindLibrary(std::string const& name, - std::vector const& userPaths) -{ - // See if the executable exists as written. - if (SystemTools::FileExists(name, true)) { - return SystemTools::CollapseFullPath(name); - } - - // Add the system search path to our path. - std::vector path; - SystemTools::GetPath(path); - // now add the additional paths - path.reserve(path.size() + userPaths.size()); - path.insert(path.end(), userPaths.begin(), userPaths.end()); - // Add a trailing slash to all paths to aid the search process. - for (std::string& p : path) { - if (p.empty() || p.back() != '/') { - p += '/'; - } - } - std::string tryPath; - for (std::string const& p : path) { -#if defined(__APPLE__) - tryPath = p; - tryPath += name; - tryPath += ".framework"; - if (SystemTools::FileIsDirectory(tryPath)) { - return SystemTools::CollapseFullPath(tryPath); - } -#endif -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) - tryPath = p; - tryPath += name; - tryPath += ".lib"; - if (SystemTools::FileExists(tryPath, true)) { - return SystemTools::CollapseFullPath(tryPath); - } -#else - tryPath = p; - tryPath += "lib"; - tryPath += name; - tryPath += ".so"; - if (SystemTools::FileExists(tryPath, true)) { - return SystemTools::CollapseFullPath(tryPath); - } - tryPath = p; - tryPath += "lib"; - tryPath += name; - tryPath += ".a"; - if (SystemTools::FileExists(tryPath, true)) { - return SystemTools::CollapseFullPath(tryPath); - } - tryPath = p; - tryPath += "lib"; - tryPath += name; - tryPath += ".sl"; - if (SystemTools::FileExists(tryPath, true)) { - return SystemTools::CollapseFullPath(tryPath); - } - tryPath = p; - tryPath += "lib"; - tryPath += name; - tryPath += ".dylib"; - if (SystemTools::FileExists(tryPath, true)) { - return SystemTools::CollapseFullPath(tryPath); - } - tryPath = p; - tryPath += "lib"; - tryPath += name; - tryPath += ".dll"; - if (SystemTools::FileExists(tryPath, true)) { - return SystemTools::CollapseFullPath(tryPath); - } -#endif - } - - // Couldn't find the library. - return ""; -} - std::string SystemTools::GetRealPath(std::string const& path, std::string* errorMessage) { diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 9506f82..daf6ba3 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -716,12 +716,6 @@ public: std::vector const& path = std::vector(), bool no_system_path = false); - /** - * Find a library in the system PATH, with optional extra paths - */ - static std::string FindLibrary(std::string const& name, - std::vector const& path); - /** * Return true if the file is a directory */ -- GitLab