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
signature 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
96509650 return ErrorNone;
96519651}
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
96539668// returns true if it was a cache miss
96549669static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
96559670 Error err;
......@@ -9667,7 +9682,12 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
96679682 buf_len(c_source_basename), 0);
96689683
96699684 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 }
96719691 buf_append_str(final_o_basename, target_o_file_ext(g->zig_target));
96729692
96739693 CacheHash *cache_hash;
......@@ -10467,10 +10487,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1046710487 return ErrorNone;
1046810488}
1046910489
10470static bool need_llvm_module(CodeGen *g) {
10471 return buf_len(&g->main_pkg->root_src_path) != 0;
10472}
10473
1047410490static void resolve_out_paths(CodeGen *g) {
1047510491 assert(g->output_dir != nullptr);
1047610492 assert(g->root_out_name != nullptr);
......@@ -10576,12 +10592,8 @@ static void output_type_information(CodeGen *g) {
1057610592 }
1057710593}
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
1058310595static 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)) {
1058510597 g->output_dir = buf_alloc();
1058610598 os_path_dirname(g->link_objects.at(0), g->output_dir);
1058710599 } else {