From ee263a15cc8fb52c2ac6053a29168fb15089839b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 11 Sep 2018 22:25:52 -0400 Subject: [PATCH] bring back zig-cache we need somewhere to put .o files and leave them while the user executes their program, so that stack traces on MacOS can find the .o files and get at the DWARF info. if we try to clean up old global tmp dir files, first of all that's a hard and complicated problem, and secondly it's not clear how that is better than dumping the .o file inside zig-cache locally. --- src/all_types.hpp | 1 + src/cache_hash.cpp | 8 -------- src/cache_hash.hpp | 4 ---- src/codegen.cpp | 5 +---- src/main.cpp | 13 +++++-------- 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index f9c50eeaac806619a7b7563ae69ca0d3310fe422..3dfbc6ba7f0520e7bcb46322553e37eabe34bce2 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1682,6 +1682,7 @@ struct CodeGen { Buf output_file_path; Buf o_file_output_path; Buf *wanted_output_file_path; + Buf cache_dir; IrInstruction *invalid_instruction; diff --git a/src/cache_hash.cpp b/src/cache_hash.cpp index 65e3e62ae0c6abcb9529b06e8b47b2484422548c..b302946310c7145b60100290d6f35ceebfbc2be7 100644 --- a/src/cache_hash.cpp +++ b/src/cache_hash.cpp @@ -467,11 +467,3 @@ void cache_release(CacheHash *ch) { assert(ch->manifest_file_path != nullptr); os_file_close(ch->manifest_file); } - -Buf *get_random_basename() { - Buf *result = buf_alloc(); - for (size_t i = 0; i < 16; i += 1) { - buf_append_char(result, base64_fs_alphabet[rand() % 64]); - } - return result; -} diff --git a/src/cache_hash.hpp b/src/cache_hash.hpp index 6acd805be65e89807115666dfa358df0ca18fda0..db1c42ec03f3087c59af45b2b67d2d8c7a79feb4 100644 --- a/src/cache_hash.hpp +++ b/src/cache_hash.hpp @@ -68,8 +68,4 @@ Error ATTRIBUTE_MUST_USE cache_final(CacheHash *ch, Buf *out_b64_digest); void cache_release(CacheHash *ch); - -// Completely independent function. Just returns a random filename safe basename. -Buf *get_random_basename(); - #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index 96e979f9d364019d7aab994fbb7352c2eeb6b8ac..aeb2b6edc4de2fb795fb3c5cc067e1a9c3511bea 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8195,8 +8195,6 @@ void codegen_build_and_link(CodeGen *g) { } os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir); - } else { - os_path_join(stage1_dir, buf_create_from_str("tmp"), artifact_dir); } if (g->enable_cache && buf_len(&digest) != 0) { @@ -8217,8 +8215,7 @@ void codegen_build_and_link(CodeGen *g) { } os_path_join(artifact_dir, &digest, &g->artifact_dir); } else { - Buf *tmp_basename = get_random_basename(); - os_path_join(artifact_dir, tmp_basename, &g->artifact_dir); + buf_init_from_buf(&g->artifact_dir, &g->cache_dir); } if ((err = os_make_path(&g->artifact_dir))) { fprintf(stderr, "Unable to create artifact directory: %s\n", err_str(err)); diff --git a/src/main.cpp b/src/main.cpp index 1751fabfe5400afdcfaf2cc9dd48dbe13215d057..f18dd949b0d799492f71f7ad7441eb7824cd1d76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -353,7 +353,7 @@ int main(int argc, char **argv) { size_t ver_minor = 0; size_t ver_patch = 0; bool timing_info = false; - const char *cache_dir = nullptr; + const char *cache_dir = default_zig_cache_name; CliPkg *cur_pkg = allocate(1); BuildMode build_mode = BuildModeDebug; ZigList test_exec_args = {0}; @@ -402,6 +402,7 @@ int main(int argc, char **argv) { os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path); CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf); + buf_init_from_str(&g->cache_dir, cache_dir); codegen_set_out_name(g, buf_create_from_str("build")); Buf *build_file_buf = buf_create_from_str(build_file); @@ -410,13 +411,8 @@ int main(int argc, char **argv) { Buf build_file_dirname = BUF_INIT; os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename); - Buf full_cache_dir = BUF_INIT; - if (cache_dir == nullptr) { - os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), &full_cache_dir); - } else { - Buf *cache_dir_buf = buf_create_from_str(cache_dir); - full_cache_dir = os_path_resolve(&cache_dir_buf, 1); - } + Buf *cache_dir_buf = buf_create_from_str(cache_dir); + Buf full_cache_dir = os_path_resolve(&cache_dir_buf, 1); args.items[1] = buf_ptr(&build_file_dirname); args.items[2] = buf_ptr(&full_cache_dir); @@ -832,6 +828,7 @@ int main(int argc, char **argv) { Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf); + buf_init_from_str(&g->cache_dir, cache_dir); codegen_set_out_name(g, buf_out_name); codegen_set_lib_version(g, ver_major, ver_minor, ver_patch); codegen_set_is_test(g, cmd == CmdTest); -- 2.54.0