authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 17:30:45-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 17:30:45-04:00
log5ee5933ade09c535bd1806d91cb606f49d07acea
treef53711be331f0b2249d8c008aba7b1ca1e22eea9
parent32be6e9b2a9e6de501aadbe271c554a4682a10f8
signaturelock-open Commit is signed but in an unrecognized format.

stage1 caching: zig no longer uses zig-cache


11 files changed, 187 insertions(+), 129 deletions(-)

CMakeLists.txt+1
......@@ -411,6 +411,7 @@ set(ZIG_SOURCES
411411 "${CMAKE_SOURCE_DIR}/src/c_tokenizer.cpp"
412412 "${CMAKE_SOURCE_DIR}/src/cache_hash.cpp"
413413 "${CMAKE_SOURCE_DIR}/src/codegen.cpp"
414 "${CMAKE_SOURCE_DIR}/src/compiler.cpp"
414415 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
415416 "${CMAKE_SOURCE_DIR}/src/error.cpp"
416417 "${CMAKE_SOURCE_DIR}/src/ir.cpp"
src/all_types.hpp-2
......@@ -1671,7 +1671,6 @@ struct CodeGen {
16711671 Buf triple_str;
16721672 Buf global_asm;
16731673 Buf *out_h_path;
1674 Buf cache_dir;
16751674 Buf artifact_dir;
16761675 Buf output_file_path;
16771676 Buf o_file_output_path;
......@@ -1731,7 +1730,6 @@ struct CodeGen {
17311730 ZigList<Buf *> assembly_files;
17321731 ZigList<const char *> lib_dirs;
17331732
1734 Buf *compiler_id;
17351733 size_t version_major;
17361734 size_t version_minor;
17371735 size_t version_patch;
src/cache_hash.cpp+7
......@@ -248,6 +248,12 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) {
248248 int rc = blake2b_final(&ch->blake, bin_digest, 48);
249249 assert(rc == 0);
250250
251 if (ch->files.length == 0) {
252 buf_resize(out_digest, 64);
253 base64_encode(buf_to_slice(out_digest), {bin_digest, 48});
254 return ErrorNone;
255 }
256
251257 Buf b64_digest = BUF_INIT;
252258 buf_resize(&b64_digest, 64);
253259 base64_encode(buf_to_slice(&b64_digest), {bin_digest, 48});
......@@ -458,5 +464,6 @@ Error cache_final(CacheHash *ch, Buf *out_digest) {
458464}
459465
460466void cache_release(CacheHash *ch) {
467 assert(ch->manifest_file_path != nullptr);
461468 os_file_close(ch->manifest_file);
462469}
src/codegen.cpp+75-35
......@@ -8,6 +8,7 @@
88#include "analyze.hpp"
99#include "ast_render.hpp"
1010#include "codegen.hpp"
11#include "compiler.hpp"
1112#include "config.h"
1213#include "errmsg.hpp"
1314#include "error.hpp"
......@@ -87,13 +88,12 @@ static const char *symbols_that_llvm_depends_on[] = {
8788};
8889
8990CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
90 Buf *zig_lib_dir, Buf *compiler_id)
91 Buf *zig_lib_dir)
9192{
9293 CodeGen *g = allocate<CodeGen>(1);
9394
9495 codegen_add_time_event(g, "Initialize");
9596
96 g->compiler_id = compiler_id;
9797 g->zig_lib_dir = zig_lib_dir;
9898
9999 g->zig_std_dir = buf_alloc();
......@@ -243,10 +243,6 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
243243 g->root_out_name = out_name;
244244}
245245
246void codegen_set_cache_dir(CodeGen *g, Buf cache_dir) {
247 g->cache_dir = cache_dir;
248}
249
250246void codegen_set_libc_lib_dir(CodeGen *g, Buf *libc_lib_dir) {
251247 g->libc_lib_dir = libc_lib_dir;
252248}
......@@ -5728,13 +5724,6 @@ static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *na
57285724 return result;
57295725}
57305726
5731static void ensure_cache_dir(CodeGen *g) {
5732 int err;
5733 if ((err = os_make_path(&g->cache_dir))) {
5734 zig_panic("unable to make cache dir: %s", err_str(err));
5735 }
5736}
5737
57385727static void report_errors_and_maybe_exit(CodeGen *g) {
57395728 if (g->errors.length != 0) {
57405729 for (size_t i = 0; i < g->errors.length; i += 1) {
......@@ -6824,36 +6813,84 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
68246813 return contents;
68256814}
68266815
6827static void define_builtin_compile_vars(CodeGen *g) {
6816static Error define_builtin_compile_vars(CodeGen *g) {
68286817 if (g->std_package == nullptr)
6829 return;
6818 return ErrorNone;
6819
6820 Error err;
6821
6822 Buf *manifest_dir = buf_alloc();
6823 os_path_join(get_stage1_cache_path(), buf_create_from_str("builtin"), manifest_dir);
6824
6825 CacheHash cache_hash;
6826 cache_init(&cache_hash, manifest_dir);
6827
6828 Buf *compiler_id;
6829 if ((err = get_compiler_id(&compiler_id)))
6830 return err;
6831
6832 // Only a few things affect builtin.zig
6833 cache_buf(&cache_hash, compiler_id);
6834 cache_int(&cache_hash, g->build_mode);
6835 cache_bool(&cache_hash, g->is_test_build);
6836 cache_int(&cache_hash, g->zig_target.arch.arch);
6837 cache_int(&cache_hash, g->zig_target.arch.sub_arch);
6838 cache_int(&cache_hash, g->zig_target.vendor);
6839 cache_int(&cache_hash, g->zig_target.os);
6840 cache_int(&cache_hash, g->zig_target.env_type);
6841 cache_int(&cache_hash, g->zig_target.oformat);
6842 cache_bool(&cache_hash, g->have_err_ret_tracing);
6843 cache_bool(&cache_hash, g->libc_link_lib != nullptr);
6844
6845 Buf digest = BUF_INIT;
6846 buf_resize(&digest, 0);
6847 if ((err = cache_hit(&cache_hash, &digest)))
6848 return err;
6849
6850 // We should always get a cache hit because there are no
6851 // files in the input hash.
6852 assert(buf_len(&digest) != 0);
6853
6854 Buf *this_dir = buf_alloc();
6855 os_path_join(manifest_dir, &digest, this_dir);
6856
6857 if ((err = os_make_path(this_dir)))
6858 return err;
68306859
68316860 const char *builtin_zig_basename = "builtin.zig";
68326861 Buf *builtin_zig_path = buf_alloc();
6833 os_path_join(&g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
6834
6835 Buf *contents = codegen_generate_builtin_source(g);
6836 ensure_cache_dir(g);
6837 os_write_file(builtin_zig_path, contents);
6862 os_path_join(this_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
68386863
6839 Buf *resolved_path = buf_alloc();
6840 Buf *resolve_paths[] = {builtin_zig_path};
6841 *resolved_path = os_path_resolve(resolve_paths, 1);
6864 bool hit;
6865 if ((err = os_file_exists(builtin_zig_path, &hit)))
6866 return err;
6867 Buf *contents;
6868 if (hit) {
6869 contents = buf_alloc();
6870 if ((err = os_fetch_file_path(builtin_zig_path, contents, false))) {
6871 fprintf(stderr, "Unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err));
6872 exit(1);
6873 }
6874 } else {
6875 contents = codegen_generate_builtin_source(g);
6876 os_write_file(builtin_zig_path, contents);
6877 }
68426878
68436879 assert(g->root_package);
68446880 assert(g->std_package);
6845 g->compile_var_package = new_package(buf_ptr(&g->cache_dir), builtin_zig_basename);
6881 g->compile_var_package = new_package(buf_ptr(this_dir), builtin_zig_basename);
68466882 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
68476883 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
6848 g->compile_var_import = add_source_file(g, g->compile_var_package, resolved_path, contents);
6884 g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents);
68496885 scan_import(g, g->compile_var_import);
6886
6887 return ErrorNone;
68506888}
68516889
68526890static void init(CodeGen *g) {
68536891 if (g->module)
68546892 return;
68556893
6856
68576894 if (g->llvm_argv_len > 0) {
68586895 const char **args = allocate_nonzero<const char *>(g->llvm_argv_len + 2);
68596896 args[0] = "zig (LLVM option parsing)";
......@@ -6960,7 +6997,11 @@ static void init(CodeGen *g) {
69606997 g->have_err_ret_tracing = g->build_mode != BuildModeFastRelease && g->build_mode != BuildModeSmallRelease;
69616998
69626999 define_builtin_fns(g);
6963 define_builtin_compile_vars(g);
7000 Error err;
7001 if ((err = define_builtin_compile_vars(g))) {
7002 fprintf(stderr, "Unable to create builtin.zig: %s\n", err_str(err));
7003 exit(1);
7004 }
69647005}
69657006
69667007void codegen_translate_c(CodeGen *g, Buf *full_path) {
......@@ -7668,6 +7709,10 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, PackageTableEntry *pkg) {
76687709static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
76697710 Error err;
76707711
7712 Buf *compiler_id;
7713 if ((err = get_compiler_id(&compiler_id)))
7714 return err;
7715
76717716 CacheHash *ch = &g->cache_hash;
76727717 cache_init(ch, manifest_dir);
76737718
......@@ -7675,7 +7720,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
76757720 if (g->linker_script != nullptr) {
76767721 cache_file(ch, buf_create_from_str(g->linker_script));
76777722 }
7678 cache_buf(ch, g->compiler_id);
7723 cache_buf(ch, compiler_id);
76797724 cache_buf(ch, g->root_out_name);
76807725 cache_list_of_link_lib(ch, g->link_libs_list.items, g->link_libs_list.length);
76817726 cache_list_of_buf(ch, g->darwin_frameworks.items, g->darwin_frameworks.length);
......@@ -7766,13 +7811,7 @@ void codegen_build_and_link(CodeGen *g) {
77667811
77677812 codegen_add_time_event(g, "Check Cache");
77687813
7769 Buf app_data_dir = BUF_INIT;
7770 if ((err = os_get_app_data_dir(&app_data_dir, "zig"))) {
7771 fprintf(stderr, "Unable to get app data dir: %s\n", err_str(err));
7772 exit(1);
7773 }
7774 Buf *stage1_dir = buf_alloc();
7775 os_path_join(&app_data_dir, buf_create_from_str("stage1"), stage1_dir);
7814 Buf *stage1_dir = get_stage1_cache_path();
77767815
77777816 Buf *manifest_dir = buf_alloc();
77787817 os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir);
......@@ -7820,6 +7859,7 @@ void codegen_build_and_link(CodeGen *g) {
78207859 }
78217860 // TODO hard link output_file_path to wanted_output_file_path
78227861
7862 cache_release(&g->cache_hash);
78237863 codegen_add_time_event(g, "Done");
78247864}
78257865
src/codegen.hpp+1-2
......@@ -15,7 +15,7 @@
1515#include <stdio.h>
1616
1717CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
18 Buf *zig_lib_dir, Buf *compiler_id);
18 Buf *zig_lib_dir);
1919
2020void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
2121void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
......@@ -46,7 +46,6 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script);
4646void codegen_set_test_filter(CodeGen *g, Buf *filter);
4747void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);
4848void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patch);
49void codegen_set_cache_dir(CodeGen *g, Buf cache_dir);
5049void codegen_set_output_h_path(CodeGen *g, Buf *h_path);
5150void codegen_set_output_path(CodeGen *g, Buf *path);
5251void codegen_add_time_event(CodeGen *g, const char *name);
src/compiler.cpp created+66
......@@ -0,0 +1,66 @@
1#include "cache_hash.hpp"
2
3#include <stdio.h>
4
5static Buf saved_compiler_id = BUF_INIT;
6static Buf saved_app_data_dir = BUF_INIT;
7static Buf saved_stage1_path = BUF_INIT;
8
9Buf *get_stage1_cache_path() {
10 if (saved_stage1_path.list.length != 0) {
11 return &saved_stage1_path;
12 }
13 Error err;
14 if ((err = os_get_app_data_dir(&saved_app_data_dir, "zig"))) {
15 fprintf(stderr, "Unable to get app data dir: %s\n", err_str(err));
16 exit(1);
17 }
18 os_path_join(&saved_app_data_dir, buf_create_from_str("stage1"), &saved_stage1_path);
19 return &saved_stage1_path;
20}
21
22Error get_compiler_id(Buf **result) {
23 if (saved_compiler_id.list.length != 0) {
24 *result = &saved_compiler_id;
25 return ErrorNone;
26 }
27
28 Error err;
29 Buf *stage1_dir = get_stage1_cache_path();
30 Buf *manifest_dir = buf_alloc();
31 os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir);
32
33 CacheHash cache_hash;
34 CacheHash *ch = &cache_hash;
35 cache_init(ch, manifest_dir);
36 Buf self_exe_path = BUF_INIT;
37 if ((err = os_self_exe_path(&self_exe_path)))
38 return err;
39
40 cache_file(ch, &self_exe_path);
41
42 buf_resize(&saved_compiler_id, 0);
43 if ((err = cache_hit(ch, &saved_compiler_id)))
44 return err;
45 if (buf_len(&saved_compiler_id) != 0) {
46 cache_release(ch);
47 *result = &saved_compiler_id;
48 return ErrorNone;
49 }
50 ZigList<Buf *> lib_paths = {};
51 if ((err = os_self_exe_shared_libs(lib_paths)))
52 return err;
53 for (size_t i = 0; i < lib_paths.length; i += 1) {
54 Buf *lib_path = lib_paths.at(i);
55 if ((err = cache_add_file(ch, lib_path)))
56 return err;
57 }
58 if ((err = cache_final(ch, &saved_compiler_id)))
59 return err;
60
61 cache_release(ch);
62
63 *result = &saved_compiler_id;
64 return ErrorNone;
65}
66
src/compiler.hpp created+17
......@@ -0,0 +1,17 @@
1/*
2 * Copyright (c) 2018 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_COMPILER_HPP
9#define ZIG_COMPILER_HPP
10
11#include "buffer.hpp"
12#include "error.hpp"
13
14Buf *get_stage1_cache_path();
15Error get_compiler_id(Buf **result);
16
17#endif
src/link.cpp+1-3
......@@ -32,7 +32,7 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) {
3232static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) {
3333 ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target;
3434 CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode,
35 parent_gen->zig_lib_dir, parent_gen->compiler_id);
35 parent_gen->zig_lib_dir);
3636
3737 child_gen->want_h_file = false;
3838 child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
......@@ -42,8 +42,6 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)
4242 child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir;
4343 child_gen->verbose_cimport = parent_gen->verbose_cimport;
4444
45 codegen_set_cache_dir(child_gen, parent_gen->cache_dir);
46
4745 codegen_set_strip(child_gen, parent_gen->strip_debug_symbols);
4846 codegen_set_is_static(child_gen, parent_gen->is_static);
4947
src/main.cpp+4-74
......@@ -8,11 +8,11 @@
88#include "ast_render.hpp"
99#include "buffer.hpp"
1010#include "codegen.hpp"
11#include "compiler.hpp"
1112#include "config.h"
1213#include "error.hpp"
1314#include "os.hpp"
1415#include "target.hpp"
15#include "cache_hash.hpp"
1616
1717#include <stdio.h>
1818
......@@ -257,53 +257,6 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
257257 }
258258}
259259
260static Buf saved_compiler_id = BUF_INIT;
261static Error get_compiler_id(Buf **result) {
262 if (saved_compiler_id.list.length != 0) {
263 *result = &saved_compiler_id;
264 return ErrorNone;
265 }
266
267 Error err;
268 Buf app_data_dir = BUF_INIT;
269 if ((err = os_get_app_data_dir(&app_data_dir, "zig")))
270 return err;
271 Buf *stage1_dir = buf_alloc();
272 os_path_join(&app_data_dir, buf_create_from_str("stage1"), stage1_dir);
273 Buf *manifest_dir = buf_alloc();
274 os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir);
275
276 CacheHash cache_hash;
277 CacheHash *ch = &cache_hash;
278 cache_init(ch, manifest_dir);
279 Buf self_exe_path = BUF_INIT;
280 if ((err = os_self_exe_path(&self_exe_path)))
281 return err;
282
283 cache_file(ch, &self_exe_path);
284
285 buf_resize(&saved_compiler_id, 0);
286 if ((err = cache_hit(ch, &saved_compiler_id)))
287 return err;
288 if (buf_len(&saved_compiler_id) != 0) {
289 *result = &saved_compiler_id;
290 return ErrorNone;
291 }
292 ZigList<Buf *> lib_paths = {};
293 if ((err = os_self_exe_shared_libs(lib_paths)))
294 return err;
295 for (size_t i = 0; i < lib_paths.length; i += 1) {
296 Buf *lib_path = lib_paths.at(i);
297 if ((err = cache_add_file(ch, lib_path)))
298 return err;
299 }
300 if ((err = cache_final(ch, &saved_compiler_id)))
301 return err;
302
303 *result = &saved_compiler_id;
304 return ErrorNone;
305}
306
307260int main(int argc, char **argv) {
308261 if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) {
309262 printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
......@@ -428,14 +381,7 @@ int main(int argc, char **argv) {
428381 Buf *build_runner_path = buf_alloc();
429382 os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path);
430383
431 Buf *compiler_id;
432 if ((err = get_compiler_id(&compiler_id))) {
433 fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
434 return EXIT_FAILURE;
435 }
436
437 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf,
438 compiler_id);
384 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
439385 codegen_set_out_name(g, buf_create_from_str("build"));
440386
441387 Buf *build_file_buf = buf_create_from_str(build_file);
......@@ -452,8 +398,6 @@ int main(int argc, char **argv) {
452398 full_cache_dir = os_path_resolve(&cache_dir_buf, 1);
453399 }
454400
455 codegen_set_cache_dir(g, full_cache_dir);
456
457401 args.items[1] = buf_ptr(&build_file_dirname);
458402 args.items[2] = buf_ptr(&full_cache_dir);
459403
......@@ -795,7 +739,7 @@ int main(int argc, char **argv) {
795739 switch (cmd) {
796740 case CmdBuiltin: {
797741 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
798 CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf, nullptr);
742 CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf);
799743 Buf *builtin_source = codegen_generate_builtin_source(g);
800744 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
801745 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
......@@ -850,30 +794,16 @@ int main(int argc, char **argv) {
850794
851795 Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf;
852796
853 Buf full_cache_dir = BUF_INIT;
854797 if (cmd == CmdRun && buf_out_name == nullptr) {
855798 buf_out_name = buf_create_from_str("run");
856799 }
857 {
858 Buf *resolve_paths = buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir);
859 full_cache_dir = os_path_resolve(&resolve_paths, 1);
860 }
861
862800 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
863801
864 Buf *compiler_id;
865 if ((err = get_compiler_id(&compiler_id))) {
866 fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
867 return EXIT_FAILURE;
868 }
869
870 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf,
871 compiler_id);
802 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf);
872803 codegen_set_out_name(g, buf_out_name);
873804 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
874805 codegen_set_is_test(g, cmd == CmdTest);
875806 codegen_set_linker_script(g, linker_script);
876 codegen_set_cache_dir(g, full_cache_dir);
877807 if (each_lib_rpath)
878808 codegen_set_each_lib_rpath(g, each_lib_rpath);
879809
src/os.cpp+12-10
......@@ -721,7 +721,7 @@ Buf os_path_resolve(Buf **paths_ptr, size_t paths_len) {
721721#endif
722722}
723723
724int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {
724Error os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {
725725 static const ssize_t buf_size = 0x2000;
726726 buf_resize(out_buf, buf_size);
727727 ssize_t actual_buf_len = 0;
......@@ -757,7 +757,7 @@ int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {
757757 if (amt_read != buf_size) {
758758 if (feof(f)) {
759759 buf_resize(out_buf, actual_buf_len);
760 return 0;
760 return ErrorNone;
761761 } else {
762762 return ErrorFileSystem;
763763 }
......@@ -769,13 +769,13 @@ int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {
769769 zig_unreachable();
770770}
771771
772int os_file_exists(Buf *full_path, bool *result) {
772Error os_file_exists(Buf *full_path, bool *result) {
773773#if defined(ZIG_OS_WINDOWS)
774774 *result = GetFileAttributes(buf_ptr(full_path)) != INVALID_FILE_ATTRIBUTES;
775 return 0;
775 return ErrorNone;
776776#else
777777 *result = access(buf_ptr(full_path), F_OK) != -1;
778 return 0;
778 return ErrorNone;
779779#endif
780780}
781781
......@@ -834,13 +834,15 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,
834834
835835 FILE *stdout_f = fdopen(stdout_pipe[0], "rb");
836836 FILE *stderr_f = fdopen(stderr_pipe[0], "rb");
837 os_fetch_file(stdout_f, out_stdout, false);
838 os_fetch_file(stderr_f, out_stderr, false);
837 Error err1 = os_fetch_file(stdout_f, out_stdout, false);
838 Error err2 = os_fetch_file(stderr_f, out_stderr, false);
839839
840840 fclose(stdout_f);
841841 fclose(stderr_f);
842842
843 return 0;
843 if (err1) return err1;
844 if (err2) return err2;
845 return ErrorNone;
844846 }
845847}
846848#endif
......@@ -1064,7 +1066,7 @@ int os_copy_file(Buf *src_path, Buf *dest_path) {
10641066 }
10651067}
10661068
1067int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) {
1069Error os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) {
10681070 FILE *f = fopen(buf_ptr(full_path), "rb");
10691071 if (!f) {
10701072 switch (errno) {
......@@ -1083,7 +1085,7 @@ int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) {
10831085 return ErrorFileSystem;
10841086 }
10851087 }
1086 int result = os_fetch_file(f, out_contents, skip_shebang);
1088 Error result = os_fetch_file(f, out_contents, skip_shebang);
10871089 fclose(f);
10881090 return result;
10891091}
src/os.hpp+3-3
......@@ -111,8 +111,8 @@ void os_file_close(OsFile file);
111111void os_write_file(Buf *full_path, Buf *contents);
112112int os_copy_file(Buf *src_path, Buf *dest_path);
113113
114int os_fetch_file(FILE *file, Buf *out_contents, bool skip_shebang);
115int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang);
114Error ATTRIBUTE_MUST_USE os_fetch_file(FILE *file, Buf *out_contents, bool skip_shebang);
115Error ATTRIBUTE_MUST_USE os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang);
116116
117117int os_get_cwd(Buf *out_cwd);
118118
......@@ -122,7 +122,7 @@ void os_stderr_set_color(TermColor color);
122122int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path);
123123int os_delete_file(Buf *path);
124124
125int os_file_exists(Buf *full_path, bool *result);
125Error ATTRIBUTE_MUST_USE os_file_exists(Buf *full_path, bool *result);
126126
127127int os_rename(Buf *src_path, Buf *dest_path);
128128double os_get_time(void);