summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel.rosdahl@maxar.com>2022-12-21 13:16:12 +0100
committerJoel Rosdahl <joel@rosdahl.net>2022-12-23 10:56:43 +0100
commita68cae9021a445550afdcd1bcce3cb3352c3c8f9 (patch)
tree5d58d1e1a3ba1a7d624934f5d5a634c59e809fe5
parent7cf41457e07ae0c2f8a05f96ed7894c9ac707dde (diff)
downloadccache-a68cae9021a445550afdcd1bcce3cb3352c3c8f9.tar.gz
fix: Fix matching of base directory for MSVC
The base directory will now match case-insensitively with absolute paths in preprocessed output, or from /showIncludes in the depend mode case, when compiling with MSVC.
-rw-r--r--src/Util.cpp22
-rw-r--r--src/ccache.cpp5
-rw-r--r--src/util/path.cpp6
-rw-r--r--unittest/test_argprocessing.cpp4
-rw-r--r--unittest/test_util_path.cpp2
5 files changed, 27 insertions, 12 deletions
diff --git a/src/Util.cpp b/src/Util.cpp
index 844e5497..8f6b4102 100644
--- a/src/Util.cpp
+++ b/src/Util.cpp
@@ -910,20 +910,14 @@ matches_dir_prefix_or_file(std::string_view dir_prefix_or_file,
|| is_dir_separator(dir_prefix_or_file.back()));
}
-std::string
-normalize_abstract_absolute_path(std::string_view path)
+static std::string
+do_normalize_abstract_absolute_path(std::string_view path)
{
if (!util::is_absolute_path(path)) {
return std::string(path);
}
#ifdef _WIN32
- if (path.find("\\") != std::string_view::npos) {
- std::string new_path(path);
- std::replace(new_path.begin(), new_path.end(), '\\', '/');
- return normalize_abstract_absolute_path(new_path);
- }
-
std::string drive(path.substr(0, 2));
path = path.substr(2);
#endif
@@ -971,6 +965,18 @@ normalize_abstract_absolute_path(std::string_view path)
}
std::string
+normalize_abstract_absolute_path(std::string_view path)
+{
+#ifdef _WIN32
+ std::string new_path(path);
+ std::replace(new_path.begin(), new_path.end(), '\\', '/');
+ return do_normalize_abstract_absolute_path(new_path);
+#else
+ return do_normalize_abstract_absolute_path(path);
+#endif
+}
+
+std::string
normalize_concrete_absolute_path(const std::string& path)
{
const auto normalized_path = normalize_abstract_absolute_path(path);
diff --git a/src/ccache.cpp b/src/ccache.cpp
index c8a21ac3..8f71e2a2 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -704,9 +704,10 @@ struct DoExecuteResult
static std::optional<Digest>
result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
{
- for (std::string_view token : core::MsvcShowIncludesOutput::get_includes(
+ for (std::string_view include : core::MsvcShowIncludesOutput::get_includes(
stdout_data, ctx.config.msvc_dep_prefix())) {
- const std::string path = Util::make_relative_path(ctx, token);
+ const std::string path = Util::make_relative_path(
+ ctx, Util::normalize_abstract_absolute_path(include));
remember_include_file(ctx, path, hash, false, &hash);
}
diff --git a/src/util/path.cpp b/src/util/path.cpp
index a1e797de..d1e6b7e8 100644
--- a/src/util/path.cpp
+++ b/src/util/path.cpp
@@ -73,10 +73,14 @@ path_starts_with(std::string_view path, std::string_view prefix)
if (path[i] == '\\' && prefix[j] == '/') {
continue;
}
-#endif
+ if (std::tolower(path[i]) != std::tolower(prefix[j])) {
+ return false;
+ }
+#else
if (path[i] != prefix[j]) {
return false;
}
+#endif
}
return true;
}
diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp
index 1a59f6a2..062d6622 100644
--- a/unittest/test_argprocessing.cpp
+++ b/unittest/test_argprocessing.cpp
@@ -59,7 +59,9 @@ get_posix_path(const std::string& path)
std::string posix;
// /-escape volume.
- if (path[0] >= 'A' && path[0] <= 'Z' && path[1] == ':') {
+ if (path[1] == ':'
+ && ((path[0] >= 'A' && path[0] <= 'Z')
+ || (path[0] >= 'a' && path[0] <= 'z'))) {
posix = "/" + path;
} else {
posix = path;
diff --git a/unittest/test_util_path.cpp b/unittest/test_util_path.cpp
index 43defcad..8bb703df 100644
--- a/unittest/test_util_path.cpp
+++ b/unittest/test_util_path.cpp
@@ -131,6 +131,8 @@ TEST_CASE("util::path_starts_with")
CHECK(util::path_starts_with("C:/foo/bar", "C:\\\\foo"));
CHECK(util::path_starts_with("C:\\foo\\bar", "C:/foo"));
CHECK(util::path_starts_with("C:\\\\foo\\\\bar", "C:/foo"));
+ CHECK(util::path_starts_with("C:/FOO/BAR", "c:\\foo"));
+ CHECK(util::path_starts_with("c:/foo/bar", "C:\\FOO"));
CHECK(!util::path_starts_with("C:\\foo\\bar", "/foo/baz"));
CHECK(!util::path_starts_with("C:\\foo\\bar", "C:/foo/baz"));
CHECK(!util::path_starts_with("C:\\beh\\foo", "/foo"));