Depfile::make_paths_relative_in_output_dep(ctx);
}
- const auto obj_stat = Stat::stat(ctx.args_info.output_obj);
- if (!obj_stat) {
- if (ctx.args_info.expect_output_obj) {
- LOG_RAW("Compiler didn't produce an object file (unexpected)");
+ Stat obj_stat;
+ if (!ctx.args_info.expect_output_obj) {
+ // Don't probe for object file when we don't expect one since we otherwise
+ // will be fooled by an already existing object file.
+ LOG_RAW("Compiler not expected to produce an object file");
+ } else {
+ obj_stat = Stat::stat(ctx.args_info.output_obj);
+ if (!obj_stat) {
+ LOG_RAW("Compiler didn't produce an object file");
return nonstd::make_unexpected(Statistic::compiler_produced_no_output);
- } else {
- LOG_RAW("Compiler didn't produce an object file (expected)");
+ } else if (obj_stat.size() == 0) {
+ LOG_RAW("Compiler produced an empty object file");
+ return nonstd::make_unexpected(Statistic::compiler_produced_empty_output);
}
- } else if (obj_stat.size() == 0) {
- LOG_RAW("Compiler produced an empty object file");
- return nonstd::make_unexpected(Statistic::compiler_produced_empty_output);
}
MTR_BEGIN("result", "result_put");
expect_stat files_in_cache 0
expect_stat compiler_produced_no_output 2
+ # -------------------------------------------------------------------------
+ TEST "-fsyntax-only"
+
+ echo existing >test1.o
+ $CCACHE_COMPILE -fsyntax-only test1.c
+ expect_stat preprocessed_cache_hit 0
+ expect_stat cache_miss 1
+ expect_stat files_in_cache 1
+ expect_content test1.o existing
+
+ rm test1.o
+
+ $CCACHE_COMPILE -fsyntax-only test1.c
+ expect_stat preprocessed_cache_hit 1
+ expect_stat cache_miss 1
+ expect_stat files_in_cache 1
+ expect_missing test1.o
+
+ # -------------------------------------------------------------------------
+ TEST "-fsyntax-only /dev/null"
+
+ echo existing >null.o
+ $CCACHE_COMPILE -fsyntax-only -x c /dev/null
+ expect_stat preprocessed_cache_hit 0
+ expect_stat cache_miss 1
+ expect_stat files_in_cache 1
+ expect_content null.o existing
+
+ rm null.o
+
+ $CCACHE_COMPILE -fsyntax-only -x c /dev/null
+ expect_stat preprocessed_cache_hit 1
+ expect_stat cache_miss 1
+ expect_stat files_in_cache 1
+ expect_missing null.o
+
# -------------------------------------------------------------------------
TEST "No object file due to -fsyntax-only"