closest_existing_path = closest_existing_path.parent_path();
}
- const auto add_relpath_candidates = [&](auto p) {
- relpath_candidates.push_back(p.lexically_relative(actual_cwd));
- if (apparent_cwd != actual_cwd) {
- relpath_candidates.emplace_back(p.lexically_relative(apparent_cwd));
- }
- };
-
- add_relpath_candidates(closest_existing_path);
- const fs::path real_closest_existing_path =
- fs::canonical(closest_existing_path).value_or(closest_existing_path);
- if (real_closest_existing_path != closest_existing_path) {
- add_relpath_candidates(real_closest_existing_path);
+ relpath_candidates.push_back(
+ closest_existing_path.lexically_relative(actual_cwd));
+ if (apparent_cwd != actual_cwd) {
+ relpath_candidates.emplace_back(
+ closest_existing_path.lexically_relative(apparent_cwd));
}
// Find best (i.e. shortest existing) match:
# -------------------------------------------------------------------------
if ! $HOST_OS_WINDOWS && ! $HOST_OS_CYGWIN; then
- TEST "Symlink to source file"
+ TEST "Symlink to source file, shorter symlink path"
mkdir dir
cd dir
fi
fi
+ # -------------------------------------------------------------------------
+if ! $HOST_OS_WINDOWS && ! $HOST_OS_CYGWIN; then
+ TEST "Symlink to source file, longer symlink path"
+
+ mkdir dir
+ cd dir
+ mkdir d
+ echo '#define A "BUG"' >h.h
+ cat <<EOF >c.c
+#include <stdio.h>
+#include "h.h"
+int main() { printf("%s\n", A); }
+EOF
+ echo '#define A "OK"' >d/h.h
+ ln -s ../c.c d/c.c
+
+ CCACHE_BASEDIR=/ $CCACHE_COMPILE -c $PWD/d/c.c
+ $COMPILER c.o -o c
+ if [ "$(./c)" != OK ]; then
+ test_failed "Incorrect header file used"
+ fi
+fi
+
# -------------------------------------------------------------------------
if ! $HOST_OS_WINDOWS && ! $HOST_OS_CYGWIN; then
TEST "Symlinked build dir inside source dir"
TEST "Relative PWD"
cd dir1
- CCACHE_BASEDIR="$(pwd)" PWD=. $CCACHE_COMPILE -I$(pwd)/include -c src/test.c
+ CCACHE_BASEDIR="$(pwd -P)" PWD=. $CCACHE_COMPILE -I$(pwd -P)/include -c src/test.c
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
cd ../dir2
- CCACHE_BASEDIR="$(pwd)" PWD=. $CCACHE_COMPILE -I$(pwd)/include -c src/test.c
+ CCACHE_BASEDIR="$(pwd -P)" PWD=. $CCACHE_COMPILE -I$(pwd -P)/include -c src/test.c
expect_stat direct_cache_hit 1
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
unset PWD
cd dir1
- CCACHE_BASEDIR="$(pwd)" $CCACHE_COMPILE -I$(pwd)/include -c src/test.c
+ CCACHE_BASEDIR="$(pwd -P)" $CCACHE_COMPILE -I$(pwd -P)/include -c src/test.c
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
cd ../dir2
- CCACHE_BASEDIR="$(pwd)" $CCACHE_COMPILE -I$(pwd)/include -c src/test.c
+ CCACHE_BASEDIR="$(pwd -P)" $CCACHE_COMPILE -I$(pwd -P)/include -c src/test.c
expect_stat direct_cache_hit 1
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
-// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
CHECK(make_relative_path(actual_cwd, apparent_cwd, apparent_cwd + "/x")
== "x");
}
-
- SUBCASE("Match if using resolved (using realpath(3)) path")
- {
- CHECK(make_relative_path(actual_cwd, actual_cwd, apparent_cwd + "/x")
- == "x");
- }
#endif
}