From 10e15e5de7f69f6482a2a802909b394216192245 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 28 Feb 2020 17:04:22 +0200 Subject: [PATCH] make and vself: cleanup make based on the new 'v self' --- .gitignore | 23 +++++++++++++++++------ Makefile | 15 ++++----------- cmd/tools/vself.v | 37 ++++++++++++++++--------------------- cmd/v/simple_tool.v | 11 ++++++++++- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 9748cb1694..e9110b218a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,29 @@ fns.txt *.dSYM *_test + /v /v2 +/v3 /vprod +/v-static +/v_old +/v_g +/v_cg +/v_prod +/v_prod_cg +/v_prod_g +/vjs + /v.c /v.*.c /v.c.out + /cmd/tools/check-md /cmd/tools/performance_compare /cmd/tools/oldv /cmd/tools/vrepl +/cmd/tools/vself /cmd/tools/vtest /cmd/tools/vtest-compiler /cmd/tools/vtest-fmt @@ -22,17 +35,12 @@ fns.txt /cmd/tools/vbuild-examples /cmd/tools/vbuild-tools /cmd/tools/vbuild-vbinaries -/v_g -/v_cg -/v_prod -/v_prod_cg -/v_prod_g + *.exe *.o *.so .*.c *.tmp.c -vjs *.obj *.exp *.ilk @@ -57,5 +65,8 @@ info.log # vim/emacs editor backup files *~ + thirdparty/freetype/ cachegrind.out.* + +.gdb_history diff --git a/Makefile b/Makefile index 216c06e93b..3938dd64e5 100644 --- a/Makefile +++ b/Makefile @@ -46,20 +46,13 @@ endif all: latest_vc latest_tcc ifdef WIN32 $(CC) $(CFLAGS) -std=c99 -municode -w -o v2.exe $(TMPVC)/$(VCFILE) $(LDFLAGS) - ./v2.exe -o v3.exe cmd/v - ./v3.exe -o v.exe -prod cmd/v - rm -f v2.exe v3.exe + ./v.exe self else $(CC) $(CFLAGS) -std=gnu11 -w -o v $(TMPVC)/$(VCFILE) $(LDFLAGS) -lm ifdef ANDROID chmod 755 v endif - @(VC_V=`./v version | cut -f 3 -d " "`; \ - V_V=`git rev-parse --short=7 HEAD`; \ - if [ $$VC_V != $$V_V ]; then \ - echo "Self rebuild ($$VC_V => $$V_V)"; \ - $(MAKE) selfcompile; \ - fi) + ./v self ifndef ANDROID $(MAKE) modules endif @@ -96,10 +89,10 @@ $(TMPVC)/.git/config: $(MAKE) fresh_vc selfcompile: - ./v -cg -o v cmd/v + ./v -keep_c -cg -o v cmd/v selfcompile-static: - ./v -cg -cflags '--static' -o v-static cmd/v + ./v -keep_c -cg -cflags '--static' -o v-static cmd/v modules: module_builtin module_strings module_strconv module_builtin: diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index 0c6aac2716..381041f4e7 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -8,29 +8,24 @@ import ( fn main() { println('V Self Compiling...') - vroot := filepath.dir(pref.vexe_path()) + vexe := pref.vexe_path() + vroot := filepath.dir(vexe) os.chdir(vroot) - - s2 := os.exec('v -o v2 cmd/v') or { + s2 := os.exec('$vexe -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') + if s2.output.len > 0 { + println(s2.output) } + if s2.exit_code != 0 { + exit(1) + } + v_file := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } + v2_file := if os.user_os() == 'windows' { 'v2.exe' } else { 'v2' } + bak_file := if os.user_os() == 'windows' { 'v_old.exe' } else { 'v_old' } + if os.exists(bak_file) { + os.rm(bak_file) + } + os.mv(v_file, bak_file) + os.mv(v2_file, v_file) } diff --git a/cmd/v/simple_tool.v b/cmd/v/simple_tool.v index e69e463d7a..9f4078ab51 100644 --- a/cmd/v/simple_tool.v +++ b/cmd/v/simple_tool.v @@ -39,9 +39,18 @@ fn launch_tool(is_verbose bool, tname string, cmdname string) { // v was recompiled, maybe after v up ... // rebuild the tool too just in case should_compile = true + + if tname == 'vself' || tname == 'vup' { + // The purpose of vself/up is to update and recompile v itself. + // After the first 'v self' execution, v will be modified, so + // then a second 'v self' will detect, that v is newer than the + // vself executable, and try to recompile vself/up again, which + // will slow down the next v recompilation needlessly. + should_compile = false + } } if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(tool_source) { - // the user changed the source code of the tool + // the user changed the source code of the tool, or git updated it: should_compile = true } }