authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-11 22:25:52-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-11 22:25:52-04:00
logee263a15cc8fb52c2ac6053a29168fb15089839b
tree54f95fe907951f15648a157a03ad2c3835b6f0c6
parent25466ffb71d653e3353bf6d86ef55bc2a4da1d59
signaturelock-open Commit is signed but in an unrecognized format.

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.

5 files changed, 7 insertions(+), 24 deletions(-)

src/all_types.hpp+1
......@@ -1682,6 +1682,7 @@ struct CodeGen {
16821682 Buf output_file_path;
16831683 Buf o_file_output_path;
16841684 Buf *wanted_output_file_path;
1685 Buf cache_dir;
16851686
16861687 IrInstruction *invalid_instruction;
16871688
src/cache_hash.cpp-8
......@@ -467,11 +467,3 @@ void cache_release(CacheHash *ch) {
467467 assert(ch->manifest_file_path != nullptr);
468468 os_file_close(ch->manifest_file);
469469}
470
471Buf *get_random_basename() {
472 Buf *result = buf_alloc();
473 for (size_t i = 0; i < 16; i += 1) {
474 buf_append_char(result, base64_fs_alphabet[rand() % 64]);
475 }
476 return result;
477}
src/cache_hash.hpp-4
......@@ -68,8 +68,4 @@ Error ATTRIBUTE_MUST_USE cache_final(CacheHash *ch, Buf *out_b64_digest);
6868void cache_release(CacheHash *ch);
6969
7070
71
72// Completely independent function. Just returns a random filename safe basename.
73Buf *get_random_basename();
74
7571#endif
src/codegen.cpp+1-4
......@@ -8195,8 +8195,6 @@ void codegen_build_and_link(CodeGen *g) {
81958195 }
81968196
81978197 os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir);
8198 } else {
8199 os_path_join(stage1_dir, buf_create_from_str("tmp"), artifact_dir);
82008198 }
82018199
82028200 if (g->enable_cache && buf_len(&digest) != 0) {
......@@ -8217,8 +8215,7 @@ void codegen_build_and_link(CodeGen *g) {
82178215 }
82188216 os_path_join(artifact_dir, &digest, &g->artifact_dir);
82198217 } else {
8220 Buf *tmp_basename = get_random_basename();
8221 os_path_join(artifact_dir, tmp_basename, &g->artifact_dir);
8218 buf_init_from_buf(&g->artifact_dir, &g->cache_dir);
82228219 }
82238220 if ((err = os_make_path(&g->artifact_dir))) {
82248221 fprintf(stderr, "Unable to create artifact directory: %s\n", err_str(err));
src/main.cpp+5-8
......@@ -353,7 +353,7 @@ int main(int argc, char **argv) {
353353 size_t ver_minor = 0;
354354 size_t ver_patch = 0;
355355 bool timing_info = false;
356 const char *cache_dir = nullptr;
356 const char *cache_dir = default_zig_cache_name;
357357 CliPkg *cur_pkg = allocate<CliPkg>(1);
358358 BuildMode build_mode = BuildModeDebug;
359359 ZigList<const char *> test_exec_args = {0};
......@@ -402,6 +402,7 @@ int main(int argc, char **argv) {
402402 os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path);
403403
404404 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
405 buf_init_from_str(&g->cache_dir, cache_dir);
405406 codegen_set_out_name(g, buf_create_from_str("build"));
406407
407408 Buf *build_file_buf = buf_create_from_str(build_file);
......@@ -410,13 +411,8 @@ int main(int argc, char **argv) {
410411 Buf build_file_dirname = BUF_INIT;
411412 os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename);
412413
413 Buf full_cache_dir = BUF_INIT;
414 if (cache_dir == nullptr) {
415 os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), &full_cache_dir);
416 } else {
417 Buf *cache_dir_buf = buf_create_from_str(cache_dir);
418 full_cache_dir = os_path_resolve(&cache_dir_buf, 1);
419 }
414 Buf *cache_dir_buf = buf_create_from_str(cache_dir);
415 Buf full_cache_dir = os_path_resolve(&cache_dir_buf, 1);
420416
421417 args.items[1] = buf_ptr(&build_file_dirname);
422418 args.items[2] = buf_ptr(&full_cache_dir);
......@@ -832,6 +828,7 @@ int main(int argc, char **argv) {
832828 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
833829
834830 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf);
831 buf_init_from_str(&g->cache_dir, cache_dir);
835832 codegen_set_out_name(g, buf_out_name);
836833 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
837834 codegen_set_is_test(g, cmd == CmdTest);