]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move is_full_path to util
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 9 Jul 2021 08:25:46 +0000 (10:25 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 9 Jul 2021 08:25:46 +0000 (10:25 +0200)
src/Util.hpp
src/ccache.cpp
src/util/path_utils.hpp
unittest/test_util_path_utils.cpp

index 0c8328aa23bfb1039c05c76e2b3db3de4dc4202a..61f697a75ff14885c2d28ce668739f5477cf708d 100644 (file)
@@ -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);
index 69534f1e377e8a14833f133a6cc4895fc51a1642..2115752164e62da19a0524295d9e9a81ea399d2b 100644 (file)
@@ -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);
 
index 6e81a683de0c029c612fe279a9cd0a2f6543786f..17d422c4c44058e31a60ebf601b7edbba3388230 100644 (file)
@@ -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<std::string> split_path_list(nonstd::string_view path_list);
index 038e37ff84524a5b32f3531f76092ec3a30dd4f3..b49f80935d0fbdef7c23375f4e01e016f642ea02 100644 (file)
@@ -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());