|==============================================================================
| *Filename* | *Description*
-| `<objectfile>.ccache-input-c` |
+| `<objectfile>.<timestamp>.ccache-input-c` |
Binary input hashed by both the direct mode and the preprocessor mode.
-| `<objectfile>.ccache-input-d` |
+| `<objectfile>.<timestamp>.ccache-input-d` |
Binary input only hashed by the direct mode.
-| `<objectfile>.ccache-input-p` |
+| `<objectfile>.<timestamp>.ccache-input-p` |
Binary input only hashed by the preprocessor mode.
-| `<objectfile>.ccache-input-text` |
+| `<objectfile>.<timestamp>.ccache-input-text` |
Human-readable combined diffable text version of the three files above.
-| `<objectfile>.ccache-log` |
+| `<objectfile>.<timestamp>.ccache-log` |
Log for this object file.
|==============================================================================
+ The timestamp format is
+`<year><month><day>_<hour><minute><second>_<microsecond>`.
+
If <<config_debug_dir,*debug_dir*>> (environment variable `CCACHE_DEBUGDIR`) is
set, the files above will be written to that directory with full absolute paths
instead of next to the object file.
To debug why you don't get an expected cache hit for an object file, you can do
something like this:
-1. Build with debug mode enabled.
-2. Save the `<objectfile>.ccache-++*++` files.
-3. Build again with debug mode enabled.
-4. Compare `<objectfile>.ccache-input-text` for the two builds. This together
- with the `<objectfile>.ccache-log` files should give you some clues about
- what is happening.
+1. Enable `debug` (`CCACHE_DEBUG`).
+2. Build.
+3. Clean and build again.
+4. Compare the `<objectfile>.<timestamp>.ccache-input-text` files for the two
+ builds. This together with the `<objectfile>.<timestamp>.ccache-log` files
+ should give you some clues about what is happening.
== Compiling in different directories
#include "Util.hpp"
#include "hashutil.hpp"
+#include <Win32Util.hpp>
#include <core/wincompat.hpp>
#include <util/path.hpp>
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
inode_cache(config)
#endif
{
+ gettimeofday(&time_of_invocation, nullptr);
}
void
#include <unordered_map>
#include <vector>
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
class SignalHandler;
class Context : NonCopyable
// The original argument list.
Args orig_args;
+ // Time of ccache invocation.
+ timeval time_of_invocation;
+
// Time of compilation. Used to see if include files have changed after
// compilation.
time_t time_of_compilation = 0;
#include <optional>
#include <string_view>
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
static std::string
prepare_debug_path(const std::string& debug_dir,
+ const timeval& time_of_invocation,
const std::string& output_obj,
std::string_view suffix)
{
// Ignore since we can't handle an error in another way in this context. The
// caller takes care of logging when trying to open the path for writing.
}
- return FMT("{}.ccache-{}", prefix, suffix);
+
+ char timestamp[100];
+ const auto tm = Util::localtime(time_of_invocation.tv_sec);
+ if (tm) {
+ strftime(timestamp, sizeof(timestamp), "%Y%m%d_%H%M%S", &*tm);
+ } else {
+ snprintf(timestamp,
+ sizeof(timestamp),
+ "%llu",
+ static_cast<long long unsigned int>(time_of_invocation.tv_sec));
+ }
+ return FMT("{}.{}_{:06}.ccache-{}",
+ prefix,
+ timestamp,
+ time_of_invocation.tv_usec,
+ suffix);
}
static void
return;
}
- const auto path = prepare_debug_path(
- ctx.config.debug_dir(), ctx.args_info.output_obj, FMT("input-{}", type));
+ const auto path = prepare_debug_path(ctx.config.debug_dir(),
+ ctx.time_of_invocation,
+ ctx.args_info.output_obj,
+ FMT("input-{}", type));
File debug_binary_file(path, "wb");
if (debug_binary_file) {
hash.enable_debug(section_name, debug_binary_file.get(), debug_text_file);
// Dump log buffer last to not lose any logs.
if (ctx.config.debug() && !ctx.args_info.output_obj.empty()) {
- Logging::dump_log(prepare_debug_path(
- ctx.config.debug_dir(), ctx.args_info.output_obj, "log"));
+ Logging::dump_log(prepare_debug_path(ctx.config.debug_dir(),
+ ctx.time_of_invocation,
+ ctx.args_info.output_obj,
+ "log"));
}
}
MTR_META_THREAD_NAME(ctx.args_info.output_obj.c_str());
if (ctx.config.debug()) {
- const auto path = prepare_debug_path(
- ctx.config.debug_dir(), ctx.args_info.output_obj, "input-text");
+ const auto path = prepare_debug_path(ctx.config.debug_dir(),
+ ctx.time_of_invocation,
+ ctx.args_info.output_obj,
+ "input-text");
File debug_text_file(path, "w");
if (debug_text_file) {
ctx.hash_debug_files.push_back(std::move(debug_text_file));
unset CCACHE_LOGFILE
unset CCACHE_NODIRECT
CCACHE_DEBUG=1 $CCACHE_COMPILE -c test1.c
- if ! grep -q Result: test1.o.ccache-log; then
+ if ! grep -q Result: test1.o.*.ccache-log; then
test_failed "Unexpected data in <obj>.ccache-log"
fi
- if ! grep -q "PREPROCESSOR MODE" test1.o.ccache-input-text; then
- test_failed "Unexpected data in <obj>.ccache-input-text"
+ if ! grep -q "PREPROCESSOR MODE" test1.o.*.ccache-input-text; then
+ test_failed "Unexpected data in <obj>.<timestamp>.ccache-input-text"
fi
for ext in c p d; do
- if ! [ -f test1.o.ccache-input-$ext ]; then
+ if ! [ -f test1.o.*.ccache-input-$ext ]; then
test_failed "<obj>.ccache-input-$ext missing"
fi
done
CCACHE_DEBUG=1 $CCACHE_COMPILE -c test1.c -save-temps
expect_stat unsupported_compiler_option 1
- expect_exists test1.o.ccache-log
+ expect_exists test1.o.*.ccache-log
# -------------------------------------------------------------------------
TEST "CCACHE_DEBUGDIR"
CCACHE_DEBUG=1 CCACHE_DEBUGDIR=debugdir $CCACHE_COMPILE -c test1.c
- expect_contains debugdir"$(pwd -P)"/test1.o.ccache-log "Result: cache_miss"
+ expect_contains debugdir"$(pwd -P)"/test1.o.*.ccache-log "Result: cache_miss"
# -------------------------------------------------------------------------
TEST "CCACHE_DISABLE"
chmod +x gcc
CCACHE_DEBUG=1 $CCACHE ./gcc -c test1.c
- compiler_type=$(sed -En 's/.*Compiler type: (.*)/\1/p' test1.o.ccache-log)
+ compiler_type=$(sed -En 's/.*Compiler type: (.*)/\1/p' test1.o.*.ccache-log)
if [ "$compiler_type" != gcc ]; then
test_failed "Compiler type $compiler_type != gcc"
fi
- rm test1.o.ccache-log
+ rm test1.o.*.ccache-log
CCACHE_COMPILERTYPE=clang CCACHE_DEBUG=1 $CCACHE ./gcc -c test1.c
- compiler_type=$(sed -En 's/.*Compiler type: (.*)/\1/p' test1.o.ccache-log)
+ compiler_type=$(sed -En 's/.*Compiler type: (.*)/\1/p' test1.o.*.ccache-log)
if [ "$compiler_type" != clang ]; then
test_failed "Compiler type $compiler_type != clang"
fi
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_equal_object_files reference_test.o test.o
- if ! grep -q 'Cloning.*to test.o' test.o.ccache-log; then
+ if ! grep -q 'Cloning.*to test.o' test.o.*.ccache-log; then
test_failed "Did not try to clone file"
fi
- if grep -q 'Failed to clone' test.o.ccache-log; then
+ if grep -q 'Failed to clone' test.o.*.ccache-log; then
test_failed "Failed to clone"
fi
expect_stat cache_miss 1
expect_stat files_in_cache 1
expect_equal_object_files reference_test.o test.o
- if grep -q 'Cloning' test.o.ccache-log; then
+ if grep -q 'Cloning' test.o.*.ccache-log; then
test_failed "Tried to clone"
fi
}
local source_file=$2
local type=$3
- local log_file=$(echo $source_file | sed 's/\.c$/.o.ccache-log/')
- local actual=$(grep -c "inode cache $type: $source_file" "$log_file")
+ local actual=$(grep -c "inode cache $type: $source_file" ${source_file/%.c/.o}.*.ccache-log)
if [ $actual -ne $expected ]; then
test_failed_internal "Found $actual (expected $expected) $type for $source_file"
fi
echo "// recompile" > test1.c
$CCACHE_COMPILE -c test1.c
expect_inode_cache 0 1 1 test1.c
+ rm *.ccache-*
+
$CCACHE_COMPILE -c test1.c
expect_inode_cache 1 0 0 test1.c
echo "// backdate" > test1.c
$CCACHE_COMPILE -c test1.c
expect_inode_cache 0 1 1 test1.c
+ rm *.ccache-*
backdate test1.c
$CCACHE_COMPILE -c test1.c
echo "// replace" > test1.c
$CCACHE_COMPILE -c test1.c
expect_inode_cache 0 1 1 test1.c
+ rm *.ccache-*
rm test1.c
echo "// replace" > test1.c
CCACHE_DEBUG=1 $CCACHE_COMPILE -arch x86_64 -Xarch_x86_64 -I. -c test1.c
expect_stat direct_cache_hit 2
expect_stat cache_miss 4
- expect_contains test1.o.ccache-log "clang -Xarch_x86_64 -I. -arch x86_64 -E test1.c"
- expect_not_contains test1.o.ccache-log "clang -Xarch_x86_64 -I. -I. -arch x86_64 -E test1.c"
+ expect_contains test1.o.*.ccache-log "clang -Xarch_x86_64 -I. -arch x86_64 -E test1.c"
+ expect_not_contains test1.o.*.ccache-log "clang -Xarch_x86_64 -I. -I. -arch x86_64 -E test1.c"
$CCACHE_COMPILE -arch x86_64 -Xarch_x86_64 -I. -c test1.c
expect_stat direct_cache_hit 3
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 2 '*' secondary # result + manifest
- expect_not_contains test.o.ccache-log secret123
+ expect_not_contains test.o.*.ccache-log secret123
# -------------------------------------------------------------------------
TEST "Basic auth required"
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 0 '*' secondary # result + manifest
- expect_contains test.o.ccache-log "status code: 401"
+ expect_contains test.o.*.ccache-log "status code: 401"
# -------------------------------------------------------------------------
TEST "Basic auth failed"
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_file_count 0 '*' secondary # result + manifest
- expect_not_contains test.o.ccache-log secret123
- expect_contains test.o.ccache-log "status code: 401"
+ expect_not_contains test.o.*.ccache-log secret123
+ expect_contains test.o.*.ccache-log "status code: 401"
# -------------------------------------------------------------------------
TEST "IPv6 address"
expect_stat cache_miss 1
expect_stat files_in_cache 2
expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
- expect_not_contains test.o.ccache-log "${password}"
+ expect_not_contains test.o.*.ccache-log "${password}"
$CCACHE_COMPILE -c test.c
expect_stat direct_cache_hit 1