tools: improve error diagnostic for `v up` and `v self`. Make `v self` more robust.
							parent
							
								
									8162396783
								
							
						
					
					
						commit
						242d7d0fc0
					
				|  | @ -40,13 +40,18 @@ fn compile(vroot string, cmd string) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn backup_old_version_and_rename_newer() ? { | fn backup_old_version_and_rename_newer() ?bool { | ||||||
|  | 	mut errors := []string{} | ||||||
| 	v_file := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } | 	v_file := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } | ||||||
| 	v2_file := if os.user_os() == 'windows' { 'v2.exe' } else { 'v2' } | 	v2_file := if os.user_os() == 'windows' { 'v2.exe' } else { 'v2' } | ||||||
| 	bak_file := if os.user_os() == 'windows' { 'v_old.exe' } else { 'v_old' } | 	bak_file := if os.user_os() == 'windows' { 'v_old.exe' } else { 'v_old' } | ||||||
| 	if os.exists(bak_file) { | 	if os.exists(bak_file) { | ||||||
| 		os.rm(bak_file) ? | 		os.rm(bak_file) or { errors << 'failed removing $bak_file: $err' } | ||||||
| 	} | 	} | ||||||
| 	os.mv(v_file, bak_file) ? | 	os.mv(v_file, bak_file) or { errors << err } | ||||||
| 	os.mv(v2_file, v_file) ? | 	os.mv(v2_file, v_file) or { errors << err } | ||||||
|  | 	if errors.len > 0 { | ||||||
|  | 		return error('backup errors:\n  >>  ' + errors.join('\n  >>  ')) | ||||||
|  | 	} | ||||||
|  | 	return true | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -43,10 +43,14 @@ fn main() { | ||||||
| 	app.show_current_v_version() | 	app.show_current_v_version() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn (app App) update_from_master() { | fn (app App) vprintln(s string) { | ||||||
| 	if app.is_verbose { | 	if app.is_verbose { | ||||||
| 		println('> updating from master ...') | 		println(s) | ||||||
| 	} | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn (app App) update_from_master() { | ||||||
|  | 	app.vprintln('> updating from master ...') | ||||||
| 	if !os.exists('.git') { | 	if !os.exists('.git') { | ||||||
| 		// initialize as if it had been cloned
 | 		// initialize as if it had been cloned
 | ||||||
| 		app.git_command('init') | 		app.git_command('init') | ||||||
|  | @ -63,16 +67,14 @@ fn (app App) update_from_master() { | ||||||
| fn (app App) recompile_v() { | fn (app App) recompile_v() { | ||||||
| 	// NB: app.vexe is more reliable than just v (which may be a symlink)
 | 	// NB: app.vexe is more reliable than just v (which may be a symlink)
 | ||||||
| 	vself := '"$app.vexe" self' | 	vself := '"$app.vexe" self' | ||||||
| 	if app.is_verbose { | 	app.vprintln('> recompiling v itself with `$vself` ...') | ||||||
| 		println('> recompiling v itself with `$vself` ...') |  | ||||||
| 	} |  | ||||||
| 	if self_result := os.exec(vself) { | 	if self_result := os.exec(vself) { | ||||||
| 		if self_result.exit_code == 0 { | 		if self_result.exit_code == 0 { | ||||||
| 			println(self_result.output.trim_space()) | 			println(self_result.output.trim_space()) | ||||||
| 			return | 			return | ||||||
| 		} else if app.is_verbose { | 		} else { | ||||||
| 			println('`$vself` failed, running `make`...') | 			app.vprintln('`$vself` failed, running `make`...') | ||||||
| 			println(self_result.output.trim_space()) | 			app.vprintln(self_result.output.trim_space()) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	app.make(vself) | 	app.make(vself) | ||||||
|  | @ -84,9 +86,7 @@ fn (app App) make(vself string) { | ||||||
| 		make = 'make.bat' | 		make = 'make.bat' | ||||||
| 	} | 	} | ||||||
| 	make_result := os.exec(make) or { panic(err) } | 	make_result := os.exec(make) or { panic(err) } | ||||||
| 	if app.is_verbose { | 	app.vprintln(make_result.output) | ||||||
| 		println(make_result.output) |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn (app App) show_current_v_version() { | fn (app App) show_current_v_version() { | ||||||
|  | @ -114,17 +114,11 @@ fn (app App) backup(file string) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn (app App) git_command(command string) { | fn (app App) git_command(command string) { | ||||||
|  | 	app.vprintln('git_command: git $command') | ||||||
| 	git_result := os.exec('git $command') or { panic(err) } | 	git_result := os.exec('git $command') or { panic(err) } | ||||||
| 	if git_result.exit_code != 0 { | 	if git_result.exit_code != 0 { | ||||||
| 		if git_result.output.contains('Permission denied') { | 		eprintln(git_result.output) | ||||||
| 			eprintln('No access to `$app.vroot`: Permission denied') |  | ||||||
| 		} else { |  | ||||||
| 			eprintln(git_result.output) |  | ||||||
| 		} |  | ||||||
| 		exit(1) | 		exit(1) | ||||||
| 	} else { |  | ||||||
| 		if app.is_verbose { |  | ||||||
| 			println(git_result.output) |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
|  | 	app.vprintln(git_result.output) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -168,6 +168,14 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { | ||||||
| 			check_module_is_installed(emodule, is_verbose) or { panic(err) } | 			check_module_is_installed(emodule, is_verbose) or { panic(err) } | ||||||
| 		} | 		} | ||||||
| 		mut compilation_command := '"$vexe" ' | 		mut compilation_command := '"$vexe" ' | ||||||
|  | 		if tool_name in ['vself', 'vup', 'vdoctor', 'vsymlink'] { | ||||||
|  | 			// These tools will be called by users in cases where there
 | ||||||
|  | 			// is high chance of there being a problem somewhere. Thus
 | ||||||
|  | 			// it is better to always compile them with -g, so that in
 | ||||||
|  | 			// case these tools do crash/panic, their backtraces will have
 | ||||||
|  | 			// .v line numbers, to ease diagnostic in #bugs and issues.
 | ||||||
|  | 			compilation_command += ' -g ' | ||||||
|  | 		} | ||||||
| 		compilation_command += '"$tool_source"' | 		compilation_command += '"$tool_source"' | ||||||
| 		if is_verbose { | 		if is_verbose { | ||||||
| 			println('Compiling $tool_name with: "$compilation_command"') | 			println('Compiling $tool_name with: "$compilation_command"') | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue