authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2019-06-16 21:58:05-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-17 14:10:10-04:00
log21dff1c4e280663c7a637f3b014c0d7326efcd3d
treee6662c17622f430e758ac5210658dca9765c218a
parentd5d0942a0dd5366e7e9a0843bf40878e6f0e1f2c

Remove duplicate exe name with zig run


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