authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-14 17:11:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-14 17:11:51-04:00
loga77386eb9847a121bc15af33e5a40bd62f3a67e5
tree5ad7e2b8a6c673b9836ea6f98aedf715d002eb80
parent4a8e766ef5d0c98b27ffad7907c6ce30c54a1ba8
signaturelock-open Commit is signed but in an unrecognized format.

for build-obj with only 1 C file, name .o file after root_out_name


1 files changed, 22 insertions(+), 10 deletions(-)

src/codegen.cpp+22-10
...@@ -9650,6 +9650,21 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose...@@ -9650,6 +9650,21 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
9650 return ErrorNone;9650 return ErrorNone;
9651}9651}
96529652
9653static bool need_llvm_module(CodeGen *g) {
9654 return buf_len(&g->main_pkg->root_src_path) != 0;
9655}
9656
9657// before gen_c_objects
9658static bool main_output_dir_is_just_one_c_object_pre(CodeGen *g) {
9659 return g->enable_cache && g->c_source_files.length == 1 && !need_llvm_module(g) &&
9660 g->out_type == OutTypeObj && g->link_objects.length == 0;
9661}
9662
9663// after gen_c_objects
9664static bool main_output_dir_is_just_one_c_object_post(CodeGen *g) {
9665 return g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g) && g->out_type == OutTypeObj;
9666}
9667
9653// returns true if it was a cache miss9668// returns true if it was a cache miss
9654static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {9669static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
9655 Error err;9670 Error err;
...@@ -9667,7 +9682,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {...@@ -9667,7 +9682,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
9667 buf_len(c_source_basename), 0);9682 buf_len(c_source_basename), 0);
96689683
9669 Buf *final_o_basename = buf_alloc();9684 Buf *final_o_basename = buf_alloc();
9670 os_path_extname(c_source_basename, final_o_basename, nullptr);9685 // We special case when doing build-obj for just one C file
9686 if (main_output_dir_is_just_one_c_object_pre(g)) {
9687 buf_init_from_buf(final_o_basename, g->root_out_name);
9688 } else {
9689 os_path_extname(c_source_basename, final_o_basename, nullptr);
9690 }
9671 buf_append_str(final_o_basename, target_o_file_ext(g->zig_target));9691 buf_append_str(final_o_basename, target_o_file_ext(g->zig_target));
96729692
9673 CacheHash *cache_hash;9693 CacheHash *cache_hash;
...@@ -10467,10 +10487,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -10467,10 +10487,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10467 return ErrorNone;10487 return ErrorNone;
10468}10488}
1046910489
10470static bool need_llvm_module(CodeGen *g) {
10471 return buf_len(&g->main_pkg->root_src_path) != 0;
10472}
10473
10474static void resolve_out_paths(CodeGen *g) {10490static void resolve_out_paths(CodeGen *g) {
10475 assert(g->output_dir != nullptr);10491 assert(g->output_dir != nullptr);
10476 assert(g->root_out_name != nullptr);10492 assert(g->root_out_name != nullptr);
...@@ -10576,12 +10592,8 @@ static void output_type_information(CodeGen *g) {...@@ -10576,12 +10592,8 @@ static void output_type_information(CodeGen *g) {
10576 }10592 }
10577}10593}
1057810594
10579static 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
10583static void init_output_dir(CodeGen *g, Buf *digest) {10595static void init_output_dir(CodeGen *g, Buf *digest) {
10584 if (main_output_dir_is_just_one_c_object(g)) {10596 if (main_output_dir_is_just_one_c_object_post(g)) {
10585 g->output_dir = buf_alloc();10597 g->output_dir = buf_alloc();
10586 os_path_dirname(g->link_objects.at(0), g->output_dir);10598 os_path_dirname(g->link_objects.at(0), g->output_dir);
10587 } else {10599 } else {