Repository navigation
Conversation
With ccache and `base_dir` set, `__FILE__` is relative to the directory the compiler ran in. `get_path_relative_to_workspace` resolved it against the directory the benchmark runs in instead, so benchmark URIs started with `../../../` and pointed outside the repository. CMake now gives every target that links codspeed a `CODSPEED_COMPILE_DIR` definition: the top build directory with Ninja, the target's build directory with other generators. `CUR_FILE` passes it to `get_path_relative_to_workspace`, which joins it to a relative path before making it relative to the workspace. Absolute paths, Bazel builds and build systems that don't set the definition behave as before. Benchmark URIs of projects built with ccache `base_dir` change, so their history restarts. Closes COD-4223 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging this PR will not alter performance2 warnings
Comparing Footnotes
|
Resolves a relative
__FILE__against the directory the compiler ran in, so benchmark URIs stay inside the repository when ccache rewrites paths.With ccache and
base_dir(CCACHE_BASEDIR) set, ccache rewrites the absolute source path CMake passes to the compiler into a path relative to the compiler's working directory.get_path_relative_to_workspacethen resolved that relative path against the directory the benchmark runs in, so URIs became../../../tests/benchmarks/bench.cpp::…. The number of..also depended on how deep the checkout is.core/CMakeLists.txtadds anINTERFACEdefinitionCODSPEED_COMPILE_DIRto every target that linkscodspeed:CMAKE_BINARY_DIRwith Ninja (which compiles everything from the top build directory), the consuming target'sBINARY_DIRotherwise (Makefiles compile from each target's build directory).CUR_FILE(benchmark.h) passes it toget_path_relative_to_workspace, which joins it to a relative path before making it relative to the workspace root.__FILE__, Bazel, and build systems that don't set the definition behave as before.Reproduced in Docker (checkout at
/home/runner/work/repro/repro, benchmark attests/benchmarks/bench.cpp, ccache 4.12.3):__FILE__../../../tests/benchmarks/bench.cpp../../../tests/benchmarks/bench.cpp::BM_sum../tests/benchmarks/bench.cpp../tests/benchmarks/bench.cpp::BM_sum../../../tests/benchmarks/bench.cpptests/benchmarks/bench.cpp::BM_sum../tests/benchmarks/bench.cpptests/benchmarks/bench.cpp::BM_sumAccepted gaps
BINARY_DIRbranch.base_dirchange, so their benchmark history restarts.Refs COD-4223 (the issue also covers fixes in other integrations and the platform, so it stays open)