From 8c43644301c859988117d2471bfc6a55d5a42a45 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 28 Feb 2020 20:02:56 +0800 Subject: [PATCH] tools: v self compiler --- cmd/tools/vself.v | 36 ++++++++++++++++++++++++++++++++++ cmd/v/internal/help/doc_help.v | 2 ++ cmd/v/v.v | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 cmd/tools/vself.v diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v new file mode 100644 index 0000000000..0c6aac2716 --- /dev/null +++ b/cmd/tools/vself.v @@ -0,0 +1,36 @@ +module main + +import ( + os + filepath + v.pref +) + +fn main() { + println('V Self Compiling...') + vroot := filepath.dir(pref.vexe_path()) + os.chdir(vroot) + + s2 := os.exec('v -o v2 cmd/v') or { + panic(err) + } + println(s2.output) + + $if windows { + bak_file := 'v_old.exe' + if os.exists(bak_file) { + os.rm(bak_file) + } + os.mv('v.exe', bak_file) + os.mv('v2.exe', 'v.exe') + + + } $else { + bak_file := 'v_old' + if os.exists(bak_file) { + os.rm(bak_file) + } + os.mv('v', bak_file) + os.mv('v2', 'v') + } +} diff --git a/cmd/v/internal/help/doc_help.v b/cmd/v/internal/help/doc_help.v index b660315386..f734d3ec10 100644 --- a/cmd/v/internal/help/doc_help.v +++ b/cmd/v/internal/help/doc_help.v @@ -20,6 +20,7 @@ The commands are: symlink create a symbolic link for V translate translate C code to V (coming soon in 0.3) up run the V self-updater + self run the V self-compiler version prints the version text and exits install installs a module from VPM @@ -110,6 +111,7 @@ Commands: up Update V. Run `v up` at least once per day, since V development is rapid and features/bugfixes are added constantly. run Build and execute the V program in file.v. You can add arguments for the V program *after* the file name. build Compile a module into an object file. + self Self-compile V from local source files. repl Run the V REPL. If V is running in a tty terminal, the REPL is interactive, otherwise it just reads from stdin. symlink Useful on Unix systems. Symlinks the current V executable to /usr/local/bin/v, so that V is globally available. test-compiler Run all V test files, and compile all V examples. diff --git a/cmd/v/v.v b/cmd/v/v.v index c9f1a1094e..b416a14613 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -13,7 +13,7 @@ import ( const ( simple_cmd = ['fmt', - 'up', + 'up', 'self', 'create', 'test', 'test-fmt', 'test-compiler', 'bin2v',