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) {
88018801
88028802 Termination term;
88038803 ZigList<const char *> args = {};
8804 args.append(buf_ptr(self_exe_path));
88048805 args.append("cc");
88058806
88068807 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) {
88198820 if (g->verbose_cc) {
88208821 print_zig_cc_cmd("zig", &args);
88218822 }
8822 os_spawn_process(buf_ptr(self_exe_path), args, &term);
8823 os_spawn_process(args, &term);
88238824 if (term.how != TerminationIdClean || term.code != 0) {
88248825 fprintf(stderr, "\nThe following command failed:\n");
88258826 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
153153 const char *cc_exe = getenv("CC");
154154 cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe;
155155 ZigList<const char *> args = {};
156 args.append(cc_exe);
156157 args.append("-E");
157158 args.append("-Wp,-v");
158159 args.append("-xc");
......@@ -166,7 +167,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b
166167 Buf *out_stderr = buf_alloc();
167168 Buf *out_stdout = buf_alloc();
168169 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))) {
170171 if (verbose) {
171172 fprintf(stderr, "unable to determine libc include path: executing '%s': %s\n", cc_exe, err_str(err));
172173 }
......@@ -277,12 +278,13 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam
277278 const char *cc_exe = getenv("CC");
278279 cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe;
279280 ZigList<const char *> args = {};
281 args.append(cc_exe);
280282 args.append(buf_ptr(buf_sprintf("-print-file-name=%s", o_file)));
281283 Termination term;
282284 Buf *out_stderr = buf_alloc();
283285 Buf *out_stdout = buf_alloc();
284286 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))) {
286288 if (err == ErrorFileNotFound)
287289 return ErrorNoCCompilerInstalled;
288290 if (verbose) {
src/link.cpp+2-1
......@@ -1721,10 +1721,11 @@ void codegen_link(CodeGen *g) {
17211721 if (g->system_linker_hack && g->zig_target->os == OsMacOSX) {
17221722 Termination term;
17231723 ZigList<const char *> args = {};
1724 args.append("ld");
17241725 for (size_t i = 1; i < lj.args.length; i += 1) {
17251726 args.append(lj.args.at(i));
17261727 }
1727 os_spawn_process("ld", args, &term);
1728 os_spawn_process(args, &term);
17281729 if (term.how != TerminationIdClean || term.code != 0) {
17291730 exit(1);
17301731 }
src/main.cpp+12-16
......@@ -467,6 +467,7 @@ int main(int argc, char **argv) {
467467 init_all_targets();
468468
469469 ZigList<const char *> args = {0};
470 args.append(NULL); // placeholder
470471 args.append(zig_exe_path);
471472 args.append(NULL); // placeholder
472473 args.append(NULL); // placeholder
......@@ -525,8 +526,8 @@ int main(int argc, char **argv) {
525526 g->enable_time_report = timing_info;
526527 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(&full_cache_dir);
529 args.items[2] = buf_ptr(&build_file_dirname);
530 args.items[3] = buf_ptr(&full_cache_dir);
530531
531532 bool build_file_exists;
532533 if ((err = os_file_exists(&build_file_abs, &build_file_exists))) {
......@@ -580,12 +581,14 @@ int main(int argc, char **argv) {
580581 codegen_build_and_link(g);
581582
582583 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);
584586 if (term.how != TerminationIdClean || term.code != 0) {
585587 fprintf(stderr, "\nBuild failed. The following command failed:\n");
586 fprintf(stderr, "%s", buf_ptr(&g->output_file_path));
588 const char *prefix = "";
587589 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 = " ";
589592 }
590593 fprintf(stderr, "\n");
591594 }
......@@ -1161,7 +1164,7 @@ int main(int argc, char **argv) {
11611164
11621165 args.pop();
11631166 Termination term;
1164 os_spawn_process(exec_path, args, &term);
1167 os_spawn_process(args, &term);
11651168 return term.code;
11661169 } else if (cmd == CmdBuild) {
11671170 if (g->enable_cache) {
......@@ -1213,17 +1216,10 @@ int main(int argc, char **argv) {
12131216 }
12141217
12151218 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));
12251221 }
1226
1222 os_spawn_process(test_exec_args, &term);
12271223 if (term.how != TerminationIdClean || term.code != 0) {
12281224 fprintf(stderr, "\nTests failed. Use the following command to reproduce the failure:\n");
12291225 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) {
105105 }
106106}
107107
108static 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;
108static void os_spawn_process_posix(ZigList<const char *> &args, Termination *term) {
109 const char **argv = allocate<const char *>(args.length + 1);
112110 for (size_t i = 0; i < args.length; i += 1) {
113 argv[i + 1] = args.at(i);
111 argv[i] = args.at(i);
114112 }
113 argv[args.length] = nullptr;
115114
116115 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);
118117 if (rc != 0) {
119118 zig_panic("posix_spawn failed: %s", strerror(rc));
120119 }
......@@ -126,16 +125,14 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args,
126125#endif
127126
128127#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 = "\"";
136132 for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) {
137 buf_append_str(command_line, " \"");
138133 const char *arg = args.at(arg_i);
134 buf_append_str(command_line, prefix);
135 prefix = " \"";
139136 size_t arg_len = strlen(arg);
140137 for (size_t c_i = 0; c_i < arg_len; c_i += 1) {
141138 if (arg[c_i] == '\"') {
......@@ -147,14 +144,15 @@ static void os_windows_create_command_line(Buf *command_line, const char *exe, Z
147144 }
148145}
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) {
151148 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
154151 PROCESS_INFORMATION piProcInfo = {0};
155152 STARTUPINFO siStartInfo = {0};
156153 siStartInfo.cb = sizeof(STARTUPINFO);
157154
155 const char *exe = args.at(0);
158156 BOOL success = CreateProcessA(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr,
159157 &siStartInfo, &piProcInfo);
160158
......@@ -173,11 +171,11 @@ static void os_spawn_process_windows(const char *exe, ZigList<const char *> &arg
173171}
174172#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) {
177175#if defined(ZIG_OS_WINDOWS)
178 os_spawn_process_windows(exe, args, term);
176 os_spawn_process_windows(args, term);
179177#elif defined(ZIG_OS_POSIX)
180 os_spawn_process_posix(exe, args, term);
178 os_spawn_process_posix(args, term);
181179#else
182180#error "missing os_spawn_process implementation"
183181#endif
......@@ -785,7 +783,7 @@ Error os_file_exists(Buf *full_path, bool *result) {
785783}
786784
787785#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,
789787 Termination *term, Buf *out_stderr, Buf *out_stdout)
790788{
791789 int stdin_pipe[2];
......@@ -817,13 +815,12 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args,
817815 if (dup2(stderr_pipe[1], STDERR_FILENO) == -1)
818816 zig_panic("dup2 failed");
819817
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;
823820 for (size_t i = 0; i < args.length; i += 1) {
824 argv[i + 1] = args.at(i);
821 argv[i] = args.at(i);
825822 }
826 execvp(exe, const_cast<char * const *>(argv));
823 execvp(argv[0], const_cast<char * const *>(argv));
827824 Error report_err = ErrorUnexpected;
828825 if (errno == ENOENT) {
829826 report_err = ErrorFileNotFound;
......@@ -874,11 +871,11 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args,
874871// LocalFree(messageBuffer);
875872//}
876873
877static Error os_exec_process_windows(const char *exe, ZigList<const char *> &args,
874static Error os_exec_process_windows(ZigList<const char *> &args,
878875 Termination *term, Buf *out_stderr, Buf *out_stdout)
879876{
880877 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
883880 HANDLE g_hChildStd_IN_Rd = NULL;
884881 HANDLE g_hChildStd_IN_Wr = NULL;
......@@ -925,6 +922,7 @@ static Error os_exec_process_windows(const char *exe, ZigList<const char *> &arg
925922 siStartInfo.hStdInput = g_hChildStd_IN_Rd;
926923 siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
927924
925 const char *exe = args.at(0);
928926 BOOL success = CreateProcess(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr,
929927 &siStartInfo, &piProcInfo);
930928
......@@ -1005,13 +1003,13 @@ Error os_execv(const char *exe, const char **argv) {
10051003#endif
10061004}
10071005
1008Error os_exec_process(const char *exe, ZigList<const char *> &args,
1006Error os_exec_process(ZigList<const char *> &args,
10091007 Termination *term, Buf *out_stderr, Buf *out_stdout)
10101008{
10111009#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);
10131011#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);
10151013#else
10161014#error "missing os_exec_process implementation"
10171015#endif
src/os.hpp+2-2
......@@ -100,8 +100,8 @@ struct OsFileAttr {
100100
101101int os_init(void);
102102
103void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term);
104Error os_exec_process(const char *exe, ZigList<const char *> &args,
103void os_spawn_process(ZigList<const char *> &args, Termination *term);
104Error os_exec_process(ZigList<const char *> &args,
105105 Termination *term, Buf *out_stderr, Buf *out_stdout);
106106Error os_execv(const char *exe, const char **argv);
107107