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.
This commit is contained in:
Andrew Kelley 2018-09-11 22:25:52 -04:00
parent 25466ffb71
commit ee263a15cc
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
5 changed files with 7 additions and 24 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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));

View File

@ -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<CliPkg>(1);
BuildMode build_mode = BuildModeDebug;
ZigList<const char *> 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);