| author | |
| committer | |
| log | 21dff1c4e280663c7a637f3b014c0d7326efcd3d |
| tree | e6662c17622f430e758ac5210658dca9765c218a |
| parent | d5d0942a0dd5366e7e9a0843bf40878e6f0e1f2c |
6 files changed, 49 insertions(+), 51 deletions(-)
src/codegen.cpp+2-1| ... | ... | @@ -8801,6 +8801,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 8801 | 8801 | |
| 8802 | 8802 | Termination term; |
| 8803 | 8803 | ZigList<const char *> args = {}; |
| 8804 | args.append(buf_ptr(self_exe_path)); | |
| 8804 | 8805 | args.append("cc"); |
| 8805 | 8806 | |
| 8806 | 8807 | Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); |
| ... | ... | @@ -8819,7 +8820,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 8819 | 8820 | if (g->verbose_cc) { |
| 8820 | 8821 | print_zig_cc_cmd("zig", &args); |
| 8821 | 8822 | } |
| 8822 | os_spawn_process(buf_ptr(self_exe_path), args, &term); | |
| 8823 | os_spawn_process(args, &term); | |
| 8823 | 8824 | if (term.how != TerminationIdClean || term.code != 0) { |
| 8824 | 8825 | fprintf(stderr, "\nThe following command failed:\n"); |
| 8825 | 8826 | print_zig_cc_cmd(buf_ptr(self_exe_path), &args); |
src/libc_installation.cpp+4-2| ... | ... | @@ -153,6 +153,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b |
| 153 | 153 | const char *cc_exe = getenv("CC"); |
| 154 | 154 | cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; |
| 155 | 155 | ZigList<const char *> args = {}; |
| 156 | args.append(cc_exe); | |
| 156 | 157 | args.append("-E"); |
| 157 | 158 | args.append("-Wp,-v"); |
| 158 | 159 | args.append("-xc"); |
| ... | ... | @@ -166,7 +167,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b |
| 166 | 167 | Buf *out_stderr = buf_alloc(); |
| 167 | 168 | Buf *out_stdout = buf_alloc(); |
| 168 | 169 | Error err; |
| 169 | if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { | |
| 170 | if ((err = os_exec_process(args, &term, out_stderr, out_stdout))) { | |
| 170 | 171 | if (verbose) { |
| 171 | 172 | fprintf(stderr, "unable to determine libc include path: executing '%s': %s\n", cc_exe, err_str(err)); |
| 172 | 173 | } |
| ... | ... | @@ -277,12 +278,13 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam |
| 277 | 278 | const char *cc_exe = getenv("CC"); |
| 278 | 279 | cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; |
| 279 | 280 | ZigList<const char *> args = {}; |
| 281 | args.append(cc_exe); | |
| 280 | 282 | args.append(buf_ptr(buf_sprintf("-print-file-name=%s", o_file))); |
| 281 | 283 | Termination term; |
| 282 | 284 | Buf *out_stderr = buf_alloc(); |
| 283 | 285 | Buf *out_stdout = buf_alloc(); |
| 284 | 286 | Error err; |
| 285 | if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { | |
| 287 | if ((err = os_exec_process(args, &term, out_stderr, out_stdout))) { | |
| 286 | 288 | if (err == ErrorFileNotFound) |
| 287 | 289 | return ErrorNoCCompilerInstalled; |
| 288 | 290 | if (verbose) { |
src/link.cpp+2-1| ... | ... | @@ -1721,10 +1721,11 @@ void codegen_link(CodeGen *g) { |
| 1721 | 1721 | if (g->system_linker_hack && g->zig_target->os == OsMacOSX) { |
| 1722 | 1722 | Termination term; |
| 1723 | 1723 | ZigList<const char *> args = {}; |
| 1724 | args.append("ld"); | |
| 1724 | 1725 | for (size_t i = 1; i < lj.args.length; i += 1) { |
| 1725 | 1726 | args.append(lj.args.at(i)); |
| 1726 | 1727 | } |
| 1727 | os_spawn_process("ld", args, &term); | |
| 1728 | os_spawn_process(args, &term); | |
| 1728 | 1729 | if (term.how != TerminationIdClean || term.code != 0) { |
| 1729 | 1730 | exit(1); |
| 1730 | 1731 | } |
src/main.cpp+12-16| ... | ... | @@ -467,6 +467,7 @@ int main(int argc, char **argv) { |
| 467 | 467 | init_all_targets(); |
| 468 | 468 | |
| 469 | 469 | ZigList<const char *> args = {0}; |
| 470 | args.append(NULL); // placeholder | |
| 470 | 471 | args.append(zig_exe_path); |
| 471 | 472 | args.append(NULL); // placeholder |
| 472 | 473 | args.append(NULL); // placeholder |
| ... | ... | @@ -525,8 +526,8 @@ int main(int argc, char **argv) { |
| 525 | 526 | g->enable_time_report = timing_info; |
| 526 | 527 | codegen_set_out_name(g, buf_create_from_str("build")); |
| 527 | 528 | |
| 528 | args.items[1] = buf_ptr(&build_file_dirname); | |
| 529 | args.items[2] = buf_ptr(&full_cache_dir); | |
| 529 | args.items[2] = buf_ptr(&build_file_dirname); | |
| 530 | args.items[3] = buf_ptr(&full_cache_dir); | |
| 530 | 531 | |
| 531 | 532 | bool build_file_exists; |
| 532 | 533 | if ((err = os_file_exists(&build_file_abs, &build_file_exists))) { |
| ... | ... | @@ -580,12 +581,14 @@ int main(int argc, char **argv) { |
| 580 | 581 | codegen_build_and_link(g); |
| 581 | 582 | |
| 582 | 583 | Termination term; |
| 583 | os_spawn_process(buf_ptr(&g->output_file_path), args, &term); | |
| 584 | args.items[0] = buf_ptr(&g->output_file_path); | |
| 585 | os_spawn_process(args, &term); | |
| 584 | 586 | if (term.how != TerminationIdClean || term.code != 0) { |
| 585 | 587 | fprintf(stderr, "\nBuild failed. The following command failed:\n"); |
| 586 | fprintf(stderr, "%s", buf_ptr(&g->output_file_path)); | |
| 588 | const char *prefix = ""; | |
| 587 | 589 | for (size_t i = 0; i < args.length; i += 1) { |
| 588 | fprintf(stderr, " %s", args.at(i)); | |
| 590 | fprintf(stderr, "%s%s", prefix, args.at(i)); | |
| 591 | prefix = " "; | |
| 589 | 592 | } |
| 590 | 593 | fprintf(stderr, "\n"); |
| 591 | 594 | } |
| ... | ... | @@ -1161,7 +1164,7 @@ int main(int argc, char **argv) { |
| 1161 | 1164 | |
| 1162 | 1165 | args.pop(); |
| 1163 | 1166 | Termination term; |
| 1164 | os_spawn_process(exec_path, args, &term); | |
| 1167 | os_spawn_process(args, &term); | |
| 1165 | 1168 | return term.code; |
| 1166 | 1169 | } else if (cmd == CmdBuild) { |
| 1167 | 1170 | if (g->enable_cache) { |
| ... | ... | @@ -1213,17 +1216,10 @@ int main(int argc, char **argv) { |
| 1213 | 1216 | } |
| 1214 | 1217 | |
| 1215 | 1218 | Termination term; |
| 1216 | if (test_exec_args.length > 0) { | |
| 1217 | ZigList<const char *> rest_args = {0}; | |
| 1218 | for (size_t i = 1; i < test_exec_args.length; i += 1) { | |
| 1219 | rest_args.append(test_exec_args.at(i)); | |
| 1220 | } | |
| 1221 | os_spawn_process(test_exec_args.items[0], rest_args, &term); | |
| 1222 | } else { | |
| 1223 | ZigList<const char *> no_args = {0}; | |
| 1224 | os_spawn_process(buf_ptr(test_exe_path), no_args, &term); | |
| 1219 | if (test_exec_args.length == 0) { | |
| 1220 | test_exec_args.append(buf_ptr(test_exe_path)); | |
| 1225 | 1221 | } |
| 1226 | ||
| 1222 | os_spawn_process(test_exec_args, &term); | |
| 1227 | 1223 | if (term.how != TerminationIdClean || term.code != 0) { |
| 1228 | 1224 | fprintf(stderr, "\nTests failed. Use the following command to reproduce the failure:\n"); |
| 1229 | 1225 | fprintf(stderr, "%s\n", buf_ptr(test_exe_path)); |
src/os.cpp+27-29| ... | ... | @@ -105,16 +105,15 @@ static void populate_termination(Termination *term, int status) { |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, Termination *term) { | |
| 109 | const char **argv = allocate<const char *>(args.length + 2); | |
| 110 | argv[0] = exe; | |
| 111 | argv[args.length + 1] = nullptr; | |
| 108 | static void os_spawn_process_posix(ZigList<const char *> &args, Termination *term) { | |
| 109 | const char **argv = allocate<const char *>(args.length + 1); | |
| 112 | 110 | for (size_t i = 0; i < args.length; i += 1) { |
| 113 | argv[i + 1] = args.at(i); | |
| 111 | argv[i] = args.at(i); | |
| 114 | 112 | } |
| 113 | argv[args.length] = nullptr; | |
| 115 | 114 | |
| 116 | 115 | pid_t pid; |
| 117 | int rc = posix_spawnp(&pid, exe, nullptr, nullptr, const_cast<char *const*>(argv), environ); | |
| 116 | int rc = posix_spawnp(&pid, args.at(0), nullptr, nullptr, const_cast<char *const*>(argv), environ); | |
| 118 | 117 | if (rc != 0) { |
| 119 | 118 | zig_panic("posix_spawn failed: %s", strerror(rc)); |
| 120 | 119 | } |
| ... | ... | @@ -126,16 +125,14 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, |
| 126 | 125 | #endif |
| 127 | 126 | |
| 128 | 127 | #if defined(ZIG_OS_WINDOWS) |
| 129 | static void os_windows_create_command_line(Buf *command_line, const char *exe, ZigList<const char *> &args) { | |
| 130 | buf_resize(command_line, 0); | |
| 131 | ||
| 132 | buf_append_char(command_line, '\"'); | |
| 133 | buf_append_str(command_line, exe); | |
| 134 | buf_append_char(command_line, '\"'); | |
| 135 | 128 | |
| 129 | static void os_windows_create_command_line(Buf *command_line, ZigList<const char *> &args) { | |
| 130 | buf_resize(command_line, 0); | |
| 131 | char *prefix = "\""; | |
| 136 | 132 | for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) { |
| 137 | buf_append_str(command_line, " \""); | |
| 138 | 133 | const char *arg = args.at(arg_i); |
| 134 | buf_append_str(command_line, prefix); | |
| 135 | prefix = " \""; | |
| 139 | 136 | size_t arg_len = strlen(arg); |
| 140 | 137 | for (size_t c_i = 0; c_i < arg_len; c_i += 1) { |
| 141 | 138 | if (arg[c_i] == '\"') { |
| ... | ... | @@ -147,14 +144,15 @@ static void os_windows_create_command_line(Buf *command_line, const char *exe, Z |
| 147 | 144 | } |
| 148 | 145 | } |
| 149 | 146 | |
| 150 | static void os_spawn_process_windows(const char *exe, ZigList<const char *> &args, Termination *term) { | |
| 147 | static void os_spawn_process_windows(ZigList<const char *> &args, Termination *term) { | |
| 151 | 148 | Buf command_line = BUF_INIT; |
| 152 | os_windows_create_command_line(&command_line, exe, args); | |
| 149 | os_windows_create_command_line(&command_line, args); | |
| 153 | 150 | |
| 154 | 151 | PROCESS_INFORMATION piProcInfo = {0}; |
| 155 | 152 | STARTUPINFO siStartInfo = {0}; |
| 156 | 153 | siStartInfo.cb = sizeof(STARTUPINFO); |
| 157 | 154 | |
| 155 | const char *exe = args.at(0); | |
| 158 | 156 | BOOL success = CreateProcessA(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, |
| 159 | 157 | &siStartInfo, &piProcInfo); |
| 160 | 158 | |
| ... | ... | @@ -173,11 +171,11 @@ static void os_spawn_process_windows(const char *exe, ZigList<const char *> &arg |
| 173 | 171 | } |
| 174 | 172 | #endif |
| 175 | 173 | |
| 176 | void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term) { | |
| 174 | void os_spawn_process(ZigList<const char *> &args, Termination *term) { | |
| 177 | 175 | #if defined(ZIG_OS_WINDOWS) |
| 178 | os_spawn_process_windows(exe, args, term); | |
| 176 | os_spawn_process_windows(args, term); | |
| 179 | 177 | #elif defined(ZIG_OS_POSIX) |
| 180 | os_spawn_process_posix(exe, args, term); | |
| 178 | os_spawn_process_posix(args, term); | |
| 181 | 179 | #else |
| 182 | 180 | #error "missing os_spawn_process implementation" |
| 183 | 181 | #endif |
| ... | ... | @@ -785,7 +783,7 @@ Error os_file_exists(Buf *full_path, bool *result) { |
| 785 | 783 | } |
| 786 | 784 | |
| 787 | 785 | #if defined(ZIG_OS_POSIX) |
| 788 | static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, | |
| 786 | static Error os_exec_process_posix(ZigList<const char *> &args, | |
| 789 | 787 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 790 | 788 | { |
| 791 | 789 | int stdin_pipe[2]; |
| ... | ... | @@ -817,13 +815,12 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, |
| 817 | 815 | if (dup2(stderr_pipe[1], STDERR_FILENO) == -1) |
| 818 | 816 | zig_panic("dup2 failed"); |
| 819 | 817 | |
| 820 | const char **argv = allocate<const char *>(args.length + 2); | |
| 821 | argv[0] = exe; | |
| 822 | argv[args.length + 1] = nullptr; | |
| 818 | const char **argv = allocate<const char *>(args.length + 1); | |
| 819 | argv[args.length] = nullptr; | |
| 823 | 820 | for (size_t i = 0; i < args.length; i += 1) { |
| 824 | argv[i + 1] = args.at(i); | |
| 821 | argv[i] = args.at(i); | |
| 825 | 822 | } |
| 826 | execvp(exe, const_cast<char * const *>(argv)); | |
| 823 | execvp(argv[0], const_cast<char * const *>(argv)); | |
| 827 | 824 | Error report_err = ErrorUnexpected; |
| 828 | 825 | if (errno == ENOENT) { |
| 829 | 826 | report_err = ErrorFileNotFound; |
| ... | ... | @@ -874,11 +871,11 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, |
| 874 | 871 | // LocalFree(messageBuffer); |
| 875 | 872 | //} |
| 876 | 873 | |
| 877 | static Error os_exec_process_windows(const char *exe, ZigList<const char *> &args, | |
| 874 | static Error os_exec_process_windows(ZigList<const char *> &args, | |
| 878 | 875 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 879 | 876 | { |
| 880 | 877 | Buf command_line = BUF_INIT; |
| 881 | os_windows_create_command_line(&command_line, exe, args); | |
| 878 | os_windows_create_command_line(&command_line, args); | |
| 882 | 879 | |
| 883 | 880 | HANDLE g_hChildStd_IN_Rd = NULL; |
| 884 | 881 | HANDLE g_hChildStd_IN_Wr = NULL; |
| ... | ... | @@ -925,6 +922,7 @@ static Error os_exec_process_windows(const char *exe, ZigList<const char *> &arg |
| 925 | 922 | siStartInfo.hStdInput = g_hChildStd_IN_Rd; |
| 926 | 923 | siStartInfo.dwFlags |= STARTF_USESTDHANDLES; |
| 927 | 924 | |
| 925 | const char *exe = args.at(0); | |
| 928 | 926 | BOOL success = CreateProcess(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, |
| 929 | 927 | &siStartInfo, &piProcInfo); |
| 930 | 928 | |
| ... | ... | @@ -1005,13 +1003,13 @@ Error os_execv(const char *exe, const char **argv) { |
| 1005 | 1003 | #endif |
| 1006 | 1004 | } |
| 1007 | 1005 | |
| 1008 | Error os_exec_process(const char *exe, ZigList<const char *> &args, | |
| 1006 | Error os_exec_process(ZigList<const char *> &args, | |
| 1009 | 1007 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 1010 | 1008 | { |
| 1011 | 1009 | #if defined(ZIG_OS_WINDOWS) |
| 1012 | return os_exec_process_windows(exe, args, term, out_stderr, out_stdout); | |
| 1010 | return os_exec_process_windows(args, term, out_stderr, out_stdout); | |
| 1013 | 1011 | #elif defined(ZIG_OS_POSIX) |
| 1014 | return os_exec_process_posix(exe, args, term, out_stderr, out_stdout); | |
| 1012 | return os_exec_process_posix(args, term, out_stderr, out_stdout); | |
| 1015 | 1013 | #else |
| 1016 | 1014 | #error "missing os_exec_process implementation" |
| 1017 | 1015 | #endif |
src/os.hpp+2-2| ... | ... | @@ -100,8 +100,8 @@ struct OsFileAttr { |
| 100 | 100 | |
| 101 | 101 | int os_init(void); |
| 102 | 102 | |
| 103 | void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term); | |
| 104 | Error os_exec_process(const char *exe, ZigList<const char *> &args, | |
| 103 | void os_spawn_process(ZigList<const char *> &args, Termination *term); | |
| 104 | Error os_exec_process(ZigList<const char *> &args, | |
| 105 | 105 | Termination *term, Buf *out_stderr, Buf *out_stdout); |
| 106 | 106 | Error os_execv(const char *exe, const char **argv); |
| 107 | 107 |