From 362c79140fc0638b0f85ed9b2a49f3fead14bb9b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 14 Jun 2019 18:18:43 -0400 Subject: expose builtin.strip_debug_info zig code now can be made aware that it will not have any debug information available at runtime. --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 29c17212cf..9c14ba3250 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -954,6 +954,7 @@ int main(int argc, char **argv) { case CmdBuiltin: { CodeGen *g = codegen_create(main_pkg_path, nullptr, &target, out_type, build_mode, override_lib_dir, override_std_dir, nullptr, nullptr); + codegen_set_strip(g, strip); g->subsystem = subsystem; g->valgrind_support = valgrind_support; g->want_pic = want_pic; -- cgit v1.2.3 From 21dff1c4e280663c7a637f3b014c0d7326efcd3d Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Sun, 16 Jun 2019 21:58:05 -0600 Subject: Remove duplicate exe name with zig run --- src/codegen.cpp | 3 ++- src/libc_installation.cpp | 6 +++-- src/link.cpp | 3 ++- src/main.cpp | 28 ++++++++++-------------- src/os.cpp | 56 +++++++++++++++++++++++------------------------ src/os.hpp | 4 ++-- 6 files changed, 49 insertions(+), 51 deletions(-) (limited to 'src/main.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index cee8c0ec0c..3dd6995c61 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8801,6 +8801,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { Termination term; ZigList args = {}; + args.append(buf_ptr(self_exe_path)); args.append("cc"); 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) { if (g->verbose_cc) { print_zig_cc_cmd("zig", &args); } - os_spawn_process(buf_ptr(self_exe_path), args, &term); + os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nThe following command failed:\n"); print_zig_cc_cmd(buf_ptr(self_exe_path), &args); diff --git a/src/libc_installation.cpp b/src/libc_installation.cpp index d1773b89e7..135941dc40 100644 --- a/src/libc_installation.cpp +++ b/src/libc_installation.cpp @@ -153,6 +153,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b const char *cc_exe = getenv("CC"); cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; ZigList args = {}; + args.append(cc_exe); args.append("-E"); args.append("-Wp,-v"); args.append("-xc"); @@ -166,7 +167,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b Buf *out_stderr = buf_alloc(); Buf *out_stdout = buf_alloc(); Error err; - if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { + if ((err = os_exec_process(args, &term, out_stderr, out_stdout))) { if (verbose) { fprintf(stderr, "unable to determine libc include path: executing '%s': %s\n", cc_exe, err_str(err)); } @@ -277,12 +278,13 @@ Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirnam const char *cc_exe = getenv("CC"); cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; ZigList args = {}; + args.append(cc_exe); args.append(buf_ptr(buf_sprintf("-print-file-name=%s", o_file))); Termination term; Buf *out_stderr = buf_alloc(); Buf *out_stdout = buf_alloc(); Error err; - if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { + if ((err = os_exec_process(args, &term, out_stderr, out_stdout))) { if (err == ErrorFileNotFound) return ErrorNoCCompilerInstalled; if (verbose) { diff --git a/src/link.cpp b/src/link.cpp index 3a437e4eda..277dcbc5c6 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1721,10 +1721,11 @@ void codegen_link(CodeGen *g) { if (g->system_linker_hack && g->zig_target->os == OsMacOSX) { Termination term; ZigList args = {}; + args.append("ld"); for (size_t i = 1; i < lj.args.length; i += 1) { args.append(lj.args.at(i)); } - os_spawn_process("ld", args, &term); + os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { exit(1); } diff --git a/src/main.cpp b/src/main.cpp index 9c14ba3250..9b1892061b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -467,6 +467,7 @@ int main(int argc, char **argv) { init_all_targets(); ZigList args = {0}; + args.append(NULL); // placeholder args.append(zig_exe_path); args.append(NULL); // placeholder args.append(NULL); // placeholder @@ -525,8 +526,8 @@ int main(int argc, char **argv) { g->enable_time_report = timing_info; codegen_set_out_name(g, buf_create_from_str("build")); - args.items[1] = buf_ptr(&build_file_dirname); - args.items[2] = buf_ptr(&full_cache_dir); + args.items[2] = buf_ptr(&build_file_dirname); + args.items[3] = buf_ptr(&full_cache_dir); bool build_file_exists; if ((err = os_file_exists(&build_file_abs, &build_file_exists))) { @@ -580,12 +581,14 @@ int main(int argc, char **argv) { codegen_build_and_link(g); Termination term; - os_spawn_process(buf_ptr(&g->output_file_path), args, &term); + args.items[0] = buf_ptr(&g->output_file_path); + os_spawn_process(args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nBuild failed. The following command failed:\n"); - fprintf(stderr, "%s", buf_ptr(&g->output_file_path)); + const char *prefix = ""; for (size_t i = 0; i < args.length; i += 1) { - fprintf(stderr, " %s", args.at(i)); + fprintf(stderr, "%s%s", prefix, args.at(i)); + prefix = " "; } fprintf(stderr, "\n"); } @@ -1161,7 +1164,7 @@ int main(int argc, char **argv) { args.pop(); Termination term; - os_spawn_process(exec_path, args, &term); + os_spawn_process(args, &term); return term.code; } else if (cmd == CmdBuild) { if (g->enable_cache) { @@ -1213,17 +1216,10 @@ int main(int argc, char **argv) { } Termination term; - if (test_exec_args.length > 0) { - ZigList rest_args = {0}; - for (size_t i = 1; i < test_exec_args.length; i += 1) { - rest_args.append(test_exec_args.at(i)); - } - os_spawn_process(test_exec_args.items[0], rest_args, &term); - } else { - ZigList no_args = {0}; - os_spawn_process(buf_ptr(test_exe_path), no_args, &term); + if (test_exec_args.length == 0) { + test_exec_args.append(buf_ptr(test_exe_path)); } - + os_spawn_process(test_exec_args, &term); if (term.how != TerminationIdClean || term.code != 0) { fprintf(stderr, "\nTests failed. Use the following command to reproduce the failure:\n"); fprintf(stderr, "%s\n", buf_ptr(test_exe_path)); diff --git a/src/os.cpp b/src/os.cpp index e3d223325f..bc28b1e7a6 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -105,16 +105,15 @@ static void populate_termination(Termination *term, int status) { } } -static void os_spawn_process_posix(const char *exe, ZigList &args, Termination *term) { - const char **argv = allocate(args.length + 2); - argv[0] = exe; - argv[args.length + 1] = nullptr; +static void os_spawn_process_posix(ZigList &args, Termination *term) { + const char **argv = allocate(args.length + 1); for (size_t i = 0; i < args.length; i += 1) { - argv[i + 1] = args.at(i); + argv[i] = args.at(i); } + argv[args.length] = nullptr; pid_t pid; - int rc = posix_spawnp(&pid, exe, nullptr, nullptr, const_cast(argv), environ); + int rc = posix_spawnp(&pid, args.at(0), nullptr, nullptr, const_cast(argv), environ); if (rc != 0) { zig_panic("posix_spawn failed: %s", strerror(rc)); } @@ -126,16 +125,14 @@ static void os_spawn_process_posix(const char *exe, ZigList &args, #endif #if defined(ZIG_OS_WINDOWS) -static void os_windows_create_command_line(Buf *command_line, const char *exe, ZigList &args) { - buf_resize(command_line, 0); - - buf_append_char(command_line, '\"'); - buf_append_str(command_line, exe); - buf_append_char(command_line, '\"'); +static void os_windows_create_command_line(Buf *command_line, ZigList &args) { + buf_resize(command_line, 0); + char *prefix = "\""; for (size_t arg_i = 0; arg_i < args.length; arg_i += 1) { - buf_append_str(command_line, " \""); const char *arg = args.at(arg_i); + buf_append_str(command_line, prefix); + prefix = " \""; size_t arg_len = strlen(arg); for (size_t c_i = 0; c_i < arg_len; c_i += 1) { if (arg[c_i] == '\"') { @@ -147,14 +144,15 @@ static void os_windows_create_command_line(Buf *command_line, const char *exe, Z } } -static void os_spawn_process_windows(const char *exe, ZigList &args, Termination *term) { +static void os_spawn_process_windows(ZigList &args, Termination *term) { Buf command_line = BUF_INIT; - os_windows_create_command_line(&command_line, exe, args); + os_windows_create_command_line(&command_line, args); PROCESS_INFORMATION piProcInfo = {0}; STARTUPINFO siStartInfo = {0}; siStartInfo.cb = sizeof(STARTUPINFO); + const char *exe = args.at(0); BOOL success = CreateProcessA(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &siStartInfo, &piProcInfo); @@ -173,11 +171,11 @@ static void os_spawn_process_windows(const char *exe, ZigList &arg } #endif -void os_spawn_process(const char *exe, ZigList &args, Termination *term) { +void os_spawn_process(ZigList &args, Termination *term) { #if defined(ZIG_OS_WINDOWS) - os_spawn_process_windows(exe, args, term); + os_spawn_process_windows(args, term); #elif defined(ZIG_OS_POSIX) - os_spawn_process_posix(exe, args, term); + os_spawn_process_posix(args, term); #else #error "missing os_spawn_process implementation" #endif @@ -785,7 +783,7 @@ Error os_file_exists(Buf *full_path, bool *result) { } #if defined(ZIG_OS_POSIX) -static Error os_exec_process_posix(const char *exe, ZigList &args, +static Error os_exec_process_posix(ZigList &args, Termination *term, Buf *out_stderr, Buf *out_stdout) { int stdin_pipe[2]; @@ -817,13 +815,12 @@ static Error os_exec_process_posix(const char *exe, ZigList &args, if (dup2(stderr_pipe[1], STDERR_FILENO) == -1) zig_panic("dup2 failed"); - const char **argv = allocate(args.length + 2); - argv[0] = exe; - argv[args.length + 1] = nullptr; + const char **argv = allocate(args.length + 1); + argv[args.length] = nullptr; for (size_t i = 0; i < args.length; i += 1) { - argv[i + 1] = args.at(i); + argv[i] = args.at(i); } - execvp(exe, const_cast(argv)); + execvp(argv[0], const_cast(argv)); Error report_err = ErrorUnexpected; if (errno == ENOENT) { report_err = ErrorFileNotFound; @@ -874,11 +871,11 @@ static Error os_exec_process_posix(const char *exe, ZigList &args, // LocalFree(messageBuffer); //} -static Error os_exec_process_windows(const char *exe, ZigList &args, +static Error os_exec_process_windows(ZigList &args, Termination *term, Buf *out_stderr, Buf *out_stdout) { Buf command_line = BUF_INIT; - os_windows_create_command_line(&command_line, exe, args); + os_windows_create_command_line(&command_line, args); HANDLE g_hChildStd_IN_Rd = NULL; HANDLE g_hChildStd_IN_Wr = NULL; @@ -925,6 +922,7 @@ static Error os_exec_process_windows(const char *exe, ZigList &arg siStartInfo.hStdInput = g_hChildStd_IN_Rd; siStartInfo.dwFlags |= STARTF_USESTDHANDLES; + const char *exe = args.at(0); BOOL success = CreateProcess(exe, buf_ptr(&command_line), nullptr, nullptr, TRUE, 0, nullptr, nullptr, &siStartInfo, &piProcInfo); @@ -1005,13 +1003,13 @@ Error os_execv(const char *exe, const char **argv) { #endif } -Error os_exec_process(const char *exe, ZigList &args, +Error os_exec_process(ZigList &args, Termination *term, Buf *out_stderr, Buf *out_stdout) { #if defined(ZIG_OS_WINDOWS) - return os_exec_process_windows(exe, args, term, out_stderr, out_stdout); + return os_exec_process_windows(args, term, out_stderr, out_stdout); #elif defined(ZIG_OS_POSIX) - return os_exec_process_posix(exe, args, term, out_stderr, out_stdout); + return os_exec_process_posix(args, term, out_stderr, out_stdout); #else #error "missing os_exec_process implementation" #endif diff --git a/src/os.hpp b/src/os.hpp index 058bb2020c..c8135e9844 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -100,8 +100,8 @@ struct OsFileAttr { int os_init(void); -void os_spawn_process(const char *exe, ZigList &args, Termination *term); -Error os_exec_process(const char *exe, ZigList &args, +void os_spawn_process(ZigList &args, Termination *term); +Error os_exec_process(ZigList &args, Termination *term, Buf *out_stderr, Buf *out_stdout); Error os_execv(const char *exe, const char **argv); -- cgit v1.2.3