| ... | @@ -10482,10 +10482,6 @@ static void resolve_out_paths(CodeGen *g) { | ... | @@ -10482,10 +10482,6 @@ static void resolve_out_paths(CodeGen *g) { |
| 10482 | case OutTypeUnknown: | 10482 | case OutTypeUnknown: |
| 10483 | zig_unreachable(); | 10483 | zig_unreachable(); |
| 10484 | case OutTypeObj: | 10484 | case OutTypeObj: |
| 10485 | if (g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g)) { | | |
| 10486 | buf_init_from_buf(&g->bin_file_output_path, g->link_objects.at(0)); | | |
| 10487 | return; | | |
| 10488 | } | | |
| 10489 | if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache && | 10485 | if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache && |
| 10490 | buf_eql_buf(o_basename, out_basename)) | 10486 | buf_eql_buf(o_basename, out_basename)) |
| 10491 | { | 10487 | { |
| ... | @@ -10580,6 +10576,20 @@ static void output_type_information(CodeGen *g) { | ... | @@ -10580,6 +10576,20 @@ static void output_type_information(CodeGen *g) { |
| 10580 | } | 10576 | } |
| 10581 | } | 10577 | } |
| 10582 | | 10578 | |
| | 10579 | static bool main_output_dir_is_just_one_c_object(CodeGen *g) { |
| | 10580 | return g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g); |
| | 10581 | } |
| | 10582 | |
| | 10583 | static void init_output_dir(CodeGen *g, Buf *digest) { |
| | 10584 | if (main_output_dir_is_just_one_c_object(g)) { |
| | 10585 | g->output_dir = buf_alloc(); |
| | 10586 | os_path_dirname(g->link_objects.at(0), g->output_dir); |
| | 10587 | } else { |
| | 10588 | g->output_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR OS_SEP "%s", |
| | 10589 | buf_ptr(g->cache_dir), buf_ptr(digest)); |
| | 10590 | } |
| | 10591 | } |
| | 10592 | |
| 10583 | void codegen_build_and_link(CodeGen *g) { | 10593 | void codegen_build_and_link(CodeGen *g) { |
| 10584 | Error err; | 10594 | Error err; |
| 10585 | assert(g->out_type != OutTypeUnknown); | 10595 | assert(g->out_type != OutTypeUnknown); |
| ... | @@ -10622,8 +10632,7 @@ void codegen_build_and_link(CodeGen *g) { | ... | @@ -10622,8 +10632,7 @@ void codegen_build_and_link(CodeGen *g) { |
| 10622 | } | 10632 | } |
| 10623 | | 10633 | |
| 10624 | if (g->enable_cache && buf_len(&digest) != 0) { | 10634 | if (g->enable_cache && buf_len(&digest) != 0) { |
| 10625 | g->output_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR OS_SEP "%s", | 10635 | init_output_dir(g, &digest); |
| 10626 | buf_ptr(g->cache_dir), buf_ptr(&digest)); | | |
| 10627 | resolve_out_paths(g); | 10636 | resolve_out_paths(g); |
| 10628 | } else { | 10637 | } else { |
| 10629 | if (need_llvm_module(g)) { | 10638 | if (need_llvm_module(g)) { |
| ... | @@ -10644,8 +10653,7 @@ void codegen_build_and_link(CodeGen *g) { | ... | @@ -10644,8 +10653,7 @@ void codegen_build_and_link(CodeGen *g) { |
| 10644 | exit(1); | 10653 | exit(1); |
| 10645 | } | 10654 | } |
| 10646 | } | 10655 | } |
| 10647 | g->output_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR OS_SEP "%s", | 10656 | init_output_dir(g, &digest); |
| 10648 | buf_ptr(g->cache_dir), buf_ptr(&digest)); | | |
| 10649 | | 10657 | |
| 10650 | if ((err = os_make_path(g->output_dir))) { | 10658 | if ((err = os_make_path(g->output_dir))) { |
| 10651 | fprintf(stderr, "Unable to create output directory: %s\n", err_str(err)); | 10659 | fprintf(stderr, "Unable to create output directory: %s\n", err_str(err)); |