1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: add execute_or_exit(cmd), use it consistently instead of execute_or_panic(cmd)

This commit is contained in:
Delyan Angelov 2021-07-20 14:04:35 +03:00
parent 850a715c79
commit 5098334e65
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
12 changed files with 25 additions and 14 deletions

View File

@ -107,7 +107,7 @@ fn main() {
}
fn exec(s string) string {
e := os.execute_or_panic(s)
e := os.execute_or_exit(s)
return e.output.trim_right('\r\n')
}
@ -137,7 +137,7 @@ fn measure(cmd string, description string) int {
}
fn measure_steps(vdir string) (int, int, int, int, int) {
resp := os.execute_or_panic('$vdir/vprod $voptions -o v.c cmd/v')
resp := os.execute_or_exit('$vdir/vprod $voptions -o v.c cmd/v')
mut scan, mut parse, mut check, mut cgen, mut vlines := 0, 0, 0, 0, 0
lines := resp.output.split_into_lines()

View File

@ -32,7 +32,7 @@ fn main() {
println('resp != 0, skipping')
} else {
os.chdir('website')
os.execute_or_panic('git checkout gh-pages')
os.execute_or_exit('git checkout gh-pages')
os.cp('../index.html', 'index.html') ?
os.system('git commit -am "update benchmark"')
os.system('git push origin gh-pages')

View File

@ -165,7 +165,7 @@ fn main() {
scripting.cprintln('# v commit hash: $shorter_hash | folder: $context.path_v')
if context.cmd_to_run.len > 0 {
scripting.cprintln_strong('# command: ${context.cmd_to_run:-34s}')
cmdres := os.execute_or_panic(context.cmd_to_run)
cmdres := os.execute_or_exit(context.cmd_to_run)
if cmdres.exit_code != 0 {
scripting.cprintln_strong('# exit code: ${cmdres.exit_code:-4d}')
}

View File

@ -4,7 +4,7 @@ const test_path = 'vcreate_test'
fn init_and_check() ? {
vexe := @VEXE
os.execute_or_panic('$vexe init')
os.execute_or_exit('$vexe init')
assert os.read_file('vcreate_test.v') ? == [
'module main\n',
@ -58,7 +58,7 @@ fn test_v_init_in_git_dir() ? {
os.rmdir_all(dir) or {}
}
os.chdir(dir)
os.execute_or_panic('git init .')
os.execute_or_exit('git init .')
init_and_check() ?
}
@ -73,7 +73,7 @@ fn test_v_init_no_overwrite_gitignore() ? {
os.chdir(dir)
vexe := @VEXE
os.execute_or_panic('$vexe init')
os.execute_or_exit('$vexe init')
assert os.read_file('.gitignore') ? == 'blah'
}

View File

@ -32,7 +32,7 @@ fn main() {
}
fn compile(vroot string, cmd string) {
result := os.execute_or_panic(cmd)
result := os.execute_or_exit(cmd)
if result.exit_code != 0 {
eprintln('cannot compile to `$vroot`: \n$result.output')
exit(1)

View File

@ -135,7 +135,7 @@ fn (app App) git_command(command string) {
if git_result.exit_code < 0 {
app.get_git()
// Try it again with (maybe) git installed
os.execute_or_panic('git $command')
os.execute_or_exit('git $command')
}
if git_result.exit_code != 0 {
eprintln(git_result.output)

View File

@ -49,7 +49,7 @@ fn test_can_compile_and_use_library_with_skip_unused() {
fn v_compile(vopts string) os.Result {
cmd := '"$vexe" -showcc $vopts'
// dump(cmd)
res := os.execute_or_panic(cmd)
res := os.execute_or_exit(cmd)
// dump(res)
assert res.exit_code == 0
return res

View File

@ -15,7 +15,7 @@ fn test_syscallwrappers() {
os.chdir(dot_checks)
checks_v := 'checks.v'
assert os.exists(checks_v)
rc := os.execute_or_panic('v run $checks_v')
rc := os.execute_or_exit('v run $checks_v')
assert rc.exit_code == 0
assert !rc.output.contains('V panic: An assertion failed.')
assert !rc.output.contains('failed')

View File

@ -622,6 +622,17 @@ pub fn execute_or_panic(cmd string) Result {
return res
}
pub fn execute_or_exit(cmd string) Result {
res := execute(cmd)
if res.exit_code != 0 {
eprintln('failed cmd: $cmd')
eprintln('failed code: $res.exit_code')
eprintln(res.output)
exit(1)
}
return res
}
// is_atty returns 1 if the `fd` file descriptor is open and refers to a terminal
pub fn is_atty(fd int) int {
$if windows {

View File

@ -524,7 +524,7 @@ fn (mut v Builder) cc() {
mut ccompiler := v.pref.ccompiler
if v.pref.os == .ios {
ios_sdk := if v.pref.is_ios_simulator { 'iphonesimulator' } else { 'iphoneos' }
ios_sdk_path_res := os.execute_or_panic('xcrun --sdk $ios_sdk --show-sdk-path')
ios_sdk_path_res := os.execute_or_exit('xcrun --sdk $ios_sdk --show-sdk-path')
mut isysroot := ios_sdk_path_res.output.replace('\n', '')
arch := if v.pref.is_ios_simulator {
'-arch x86_64'

View File

@ -12,7 +12,7 @@ fn test_the_v_compiler_can_be_invoked() {
println('vexecutable: $vexec')
assert vexec != ''
vcmd := '"$vexec" -version'
r := os.execute_or_panic(vcmd)
r := os.execute_or_exit(vcmd)
assert r.exit_code == 0
// println('"$vcmd" exit_code: $r.exit_code | output: $r.output')
vcmd_error := '"$vexec" nonexisting.v'

View File

@ -248,7 +248,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) {
if is_verbose {
println('Compiling $tool_name with: "$compilation_command"')
}
tool_compilation := os.execute_or_panic(compilation_command)
tool_compilation := os.execute_or_exit(compilation_command)
if tool_compilation.exit_code != 0 {
eprintln('cannot compile `$tool_source`: \n$tool_compilation.output')
exit(1)