@@ -9803,7 +9803,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
9803
9803
exit(1);
9804
9804
}
9805
9805
}
9806
- bool is_cache_miss = (buf_len(&digest) == 0);
9806
+ bool is_cache_miss = g->disable_c_depfile || (buf_len(&digest) == 0);
9807
9807
if (is_cache_miss) {
9808
9808
// we can't know the digest until we do the C compiler invocation, so we
9809
9809
// need a tmp filename.
@@ -9822,9 +9822,10 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
9822
9822
args.append("-c");
9823
9823
}
9824
9824
9825
- Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path));
9825
+ Buf *out_dep_path = g->disable_c_depfile ? nullptr : buf_sprintf("%s.d", buf_ptr(out_obj_path));
9826
+ const char *out_dep_path_cstr = (out_dep_path == nullptr) ? nullptr : buf_ptr(out_dep_path);
9826
9827
FileExt ext = classify_file_ext(buf_ptr(c_source_basename), buf_len(c_source_basename));
9827
- add_cc_args(g, args, buf_ptr(out_dep_path) , false, ext);
9828
+ add_cc_args(g, args, out_dep_path_cstr , false, ext);
9828
9829
9829
9830
args.append("-o");
9830
9831
args.append(buf_ptr(out_obj_path));
@@ -9845,22 +9846,24 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
9845
9846
exit(1);
9846
9847
}
9847
9848
9848
- // add the files depended on to the cache system
9849
- if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9850
- // Don't treat the absence of the .d file as a fatal error, the
9851
- // compiler may not produce one eg. when compiling .s files
9849
+ if (out_dep_path != nullptr) {
9850
+ // add the files depended on to the cache system
9851
+ if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9852
+ // Don't treat the absence of the .d file as a fatal error, the
9853
+ // compiler may not produce one eg. when compiling .s files
9854
+ if (err != ErrorFileNotFound) {
9855
+ fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9856
+ exit(1);
9857
+ }
9858
+ }
9852
9859
if (err != ErrorFileNotFound) {
9853
- fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9854
- exit(1);
9860
+ os_delete_file(out_dep_path);
9855
9861
}
9856
- }
9857
- if (err != ErrorFileNotFound) {
9858
- os_delete_file(out_dep_path);
9859
- }
9860
9862
9861
- if ((err = cache_final(cache_hash, &digest))) {
9862
- fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9863
- exit(1);
9863
+ if ((err = cache_final(cache_hash, &digest))) {
9864
+ fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9865
+ exit(1);
9866
+ }
9864
9867
}
9865
9868
artifact_dir = buf_alloc();
9866
9869
os_path_join(o_dir, &digest, artifact_dir);
0 commit comments