aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-04-26 20:41:37 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-04-26 20:46:28 -0400
commit2d6520d5d4cd912cdd20db6cfa155e871efc6f59 (patch)
tree583e47f4af61d3950b34333d48e738733b5e107a /src/main.cpp
parentac3946620cebfc706255a86103a14c6cb08cff97 (diff)
downloadzig-2d6520d5d4cd912cdd20db6cfa155e871efc6f59.tar.gz
zig-2d6520d5d4cd912cdd20db6cfa155e871efc6f59.zip
zig fmt is built directly into stage1 rather than child process
Previously, `zig fmt` on the stage1 compiler (which is what we currently ship) would perform what equates to `zig run std/special/fmt_runner.zig` Now, `zig fmt` is implemented with the hybrid zig/C++ strategy outlined by #1964. This means Zig no longer has to ship some of the stage2 .zig files, and there is no longer a delay when running `zig fmt` for the first time.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp32
1 files changed, 1 insertions, 31 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 2b65999e3b..c803dfa17c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -588,37 +588,7 @@ int main(int argc, char **argv) {
}
return (term.how == TerminationIdClean) ? term.code : -1;
} else if (argc >= 2 && strcmp(argv[1], "fmt") == 0) {
- init_all_targets();
- ZigTarget target;
- get_native_target(&target);
- Buf *zig_lib_dir = (override_lib_dir == nullptr) ? get_zig_lib_dir() : override_lib_dir;
- Buf *fmt_runner_path = buf_alloc();
- os_path_join(get_zig_special_dir(zig_lib_dir), buf_create_from_str("fmt_runner.zig"), fmt_runner_path);
- Buf *cache_dir_buf = buf_create_from_str(cache_dir ? cache_dir : default_zig_cache_name);
- CodeGen *g = codegen_create(main_pkg_path, fmt_runner_path, &target, OutTypeExe,
- BuildModeDebug, zig_lib_dir, nullptr, nullptr, cache_dir_buf);
- g->valgrind_support = valgrind_support;
- g->want_single_threaded = true;
- codegen_set_out_name(g, buf_create_from_str("fmt"));
- g->enable_cache = true;
-
- codegen_build_and_link(g);
-
- // TODO standardize os.cpp so that the args are supposed to have the exe
- ZigList<const char*> args_with_exe = {0};
- ZigList<const char*> args_without_exe = {0};
- const char *exec_path = buf_ptr(&g->output_file_path);
- args_with_exe.append(exec_path);
- for (int i = 2; i < argc; i += 1) {
- args_with_exe.append(argv[i]);
- args_without_exe.append(argv[i]);
- }
- args_with_exe.append(nullptr);
- os_execv(exec_path, args_with_exe.items);
-
- Termination term;
- os_spawn_process(exec_path, args_without_exe, &term);
- return term.code;
+ return stage2_fmt(argc, argv);
}
for (int i = 1; i < argc; i += 1) {