return {true, found_file, found_file == mangled_form};
}
-static bool
+[[nodiscard]] static bool
write_result(Context& ctx,
const Digest& result_key,
const Stat& obj_stat,
if (!stdout_data.empty()) {
serializer.add_data(core::Result::FileType::stdout_output, stdout_data);
}
- if (obj_stat) {
- serializer.add_file(core::Result::FileType::object,
- ctx.args_info.output_obj);
+ if (obj_stat
+ && !serializer.add_file(core::Result::FileType::object,
+ ctx.args_info.output_obj)) {
+ LOG("Object file {} missing", ctx.args_info.output_obj);
+ return false;
}
- if (ctx.args_info.generating_dependencies) {
- serializer.add_file(core::Result::FileType::dependency,
- ctx.args_info.output_dep);
+ if (ctx.args_info.generating_dependencies
+ && !serializer.add_file(core::Result::FileType::dependency,
+ ctx.args_info.output_dep)) {
+ LOG("Dependency file {} missing", ctx.args_info.output_dep);
+ return false;
}
if (ctx.args_info.generating_coverage) {
const auto coverage_file = find_coverage_file(ctx);
if (!coverage_file.found) {
+ LOG_RAW("Coverage file not found");
+ return false;
+ }
+ if (!serializer.add_file(coverage_file.mangled
+ ? core::Result::FileType::coverage_mangled
+ : core::Result::FileType::coverage_unmangled,
+ coverage_file.path)) {
+ LOG("Coverage file {} missing", coverage_file.path);
return false;
}
- serializer.add_file(coverage_file.mangled
- ? core::Result::FileType::coverage_mangled
- : core::Result::FileType::coverage_unmangled,
- coverage_file.path);
}
- if (ctx.args_info.generating_stackusage) {
- serializer.add_file(core::Result::FileType::stackusage,
- ctx.args_info.output_su);
+ if (ctx.args_info.generating_stackusage
+ && !serializer.add_file(core::Result::FileType::stackusage,
+ ctx.args_info.output_su)) {
+ LOG("Stack usage file {} missing", ctx.args_info.output_su);
+ return false;
}
- if (ctx.args_info.generating_diagnostics) {
- serializer.add_file(core::Result::FileType::diagnostic,
- ctx.args_info.output_dia);
+ if (ctx.args_info.generating_diagnostics
+ && !serializer.add_file(core::Result::FileType::diagnostic,
+ ctx.args_info.output_dia)) {
+ LOG("Diagnostics file {} missing", ctx.args_info.output_dia);
+ return false;
}
- if (ctx.args_info.seen_split_dwarf && Stat::stat(ctx.args_info.output_dwo)) {
- // Only store .dwo file if it was created by the compiler (GCC and Clang
- // behave differently e.g. for "-gsplit-dwarf -g1").
- serializer.add_file(core::Result::FileType::dwarf_object,
- ctx.args_info.output_dwo);
+ if (ctx.args_info.seen_split_dwarf
+ // Only store .dwo file if it was created by the compiler (GCC and Clang
+ // behave differently e.g. for "-gsplit-dwarf -g1").
+ && Stat::stat(ctx.args_info.output_dwo)
+ && !serializer.add_file(core::Result::FileType::dwarf_object,
+ ctx.args_info.output_dwo)) {
+ LOG("Split dwarf file {} missing", ctx.args_info.output_dwo);
+ return false;
}
- if (!ctx.args_info.output_al.empty()) {
- serializer.add_file(core::Result::FileType::assembler_listing,
- ctx.args_info.output_al);
+ if (!ctx.args_info.output_al.empty()
+ && !serializer.add_file(core::Result::FileType::assembler_listing,
+ ctx.args_info.output_al)) {
+ LOG("Assembler listing file {} missing", ctx.args_info.output_al);
+ return false;
}
core::CacheEntry::Header header(ctx.config, core::CacheEntryType::result);
}
MTR_BEGIN("result", "result_put");
- write_result(
- ctx, *result_key, obj_stat, result->stdout_data, result->stderr_data);
+ if (!write_result(
+ ctx, *result_key, obj_stat, result->stdout_data, result->stderr_data)) {
+ return nonstd::make_unexpected(Statistic::compiler_produced_no_output);
+ }
MTR_END("result", "result_put");
// Everything OK.
FIELD(cleanups_performed, nullptr),
FIELD(compile_failed, "Compilation failed", FLAG_UNCACHEABLE),
FIELD(compiler_check_failed, "Compiler check failed", FLAG_ERROR),
+ FIELD(compiler_produced_no_output,
+ "Compiler output file missing",
+ FLAG_UNCACHEABLE),
FIELD(compiler_produced_empty_output,
"Compiler produced empty output",
FLAG_UNCACHEABLE),
- FIELD(compiler_produced_no_output,
- "Compiler produced no output",
- FLAG_UNCACHEABLE),
FIELD(compiler_produced_stdout, "Compiler produced stdout", FLAG_UNCACHEABLE),
FIELD(could_not_find_compiler, "Could not find compiler", FLAG_ERROR),
FIELD(could_not_use_modules, "Could not use modules", FLAG_UNCACHEABLE),
expect_equal_content test.d expected.d
expect_equal_object_files reference_test.o test.o
+ # -------------------------------------------------------------------------
+ TEST "-MD for assembler file with missing dependency file"
+
+ $COMPILER -S test.c
+
+ $CCACHE_COMPILE -c -MD test.s
+ expect_stat direct_cache_hit 0
+ expect_stat preprocessed_cache_hit 0
+ expect_stat cache_miss 1
+
+ $CCACHE_COMPILE -c -MD test.s
+ expect_stat direct_cache_hit 1
+ expect_stat preprocessed_cache_hit 0
+ expect_stat cache_miss 1
+
+ # -------------------------------------------------------------------------
+ TEST "-MD for assembler file with existing dependency file"
+
+ $COMPILER -S test.c
+ echo foo >test.d
+
+ $CCACHE_COMPILE -c -MD test.s
+ expect_stat direct_cache_hit 0
+ expect_stat preprocessed_cache_hit 0
+ expect_stat cache_miss 1
+ rm test.d
+
+ $CCACHE_COMPILE -c -MD test.s
+ expect_stat direct_cache_hit 1
+ expect_stat preprocessed_cache_hit 0
+ expect_stat cache_miss 1
+ expect_missing test.d
+
# -------------------------------------------------------------------------
TEST "-ftest-coverage"