From: Joel Rosdahl Date: Fri, 9 Jul 2021 08:25:46 +0000 (+0200) Subject: Move is_full_path to util X-Git-Tag: v4.4~143 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e3e29c94f2848702573888b4757a41eb7a5bd87a;p=thirdparty%2Fccache.git Move is_full_path to util --- diff --git a/src/Util.hpp b/src/Util.hpp index 0c8328aa2..61f697a75 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -286,18 +286,6 @@ is_dir_separator(char ch) ; } -// Return whether `path` is a full path. -inline bool -is_full_path(nonstd::string_view path) -{ -#ifdef _WIN32 - if (path.find('\\') != nonstd::string_view::npos) { - return true; - } -#endif - return path.find('/') != nonstd::string_view::npos; -} - // Return whether `path` represents a precompiled header (see "Precompiled // Headers" in GCC docs). bool is_precompiled_header(nonstd::string_view path); diff --git a/src/ccache.cpp b/src/ccache.cpp index 69534f1e3..211575216 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1843,7 +1843,7 @@ find_compiler(Context& ctx, : ctx.orig_args[compiler_pos]); const std::string resolved_compiler = - Util::is_full_path(compiler) + util::is_full_path(compiler) ? compiler : find_executable_function(ctx, compiler, CCACHE_NAME); diff --git a/src/util/path_utils.hpp b/src/util/path_utils.hpp index 6e81a683d..17d422c4c 100644 --- a/src/util/path_utils.hpp +++ b/src/util/path_utils.hpp @@ -28,6 +28,18 @@ namespace util { // Return whether `path` is absolute. bool is_absolute_path(nonstd::string_view path); +// Return whether `path` includes at least one directory separator. +inline bool +is_full_path(nonstd::string_view path) +{ +#ifdef _WIN32 + if (path.find('\\') != nonstd::string_view::npos) { + return true; + } +#endif + return path.find('/') != nonstd::string_view::npos; +} + // Split a list of paths (such as the content of $PATH on Unix platforms or // %PATH% on Windows platforms) into paths. std::vector split_path_list(nonstd::string_view path_list); diff --git a/unittest/test_util_path_utils.cpp b/unittest/test_util_path_utils.cpp index 038e37ff8..b49f80935 100644 --- a/unittest/test_util_path_utils.cpp +++ b/unittest/test_util_path_utils.cpp @@ -38,6 +38,20 @@ TEST_CASE("util::is_absolute_path") CHECK(!util::is_absolute_path("foo/fie")); } +TEST_CASE("util::is_absolute_path") +{ + CHECK(!util::is_full_path("")); + CHECK(!util::is_full_path("foo")); + CHECK(util::is_full_path("/foo")); + CHECK(util::is_full_path("foo/")); + CHECK(util::is_full_path("foo/bar")); +#ifdef _WIN32 + CHECK(util::is_full_path("foo\\bar")); +#else + CHECK(!util::is_full_path("foo\\bar")); +#endif +} + TEST_CASE("util::split_path_list") { CHECK(util::split_path_list("").empty());