mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: add os.quoted_path/1, use it consistently for running V itself
This commit is contained in:
@@ -8,7 +8,7 @@ const vroot = @VMODROOT
|
||||
fn get_vdoctor_output(is_verbose bool) string {
|
||||
vexe := os.getenv('VEXE')
|
||||
verbose_flag := if is_verbose { '-v' } else { '' }
|
||||
result := os.execute('$vexe $verbose_flag doctor')
|
||||
result := os.execute('${os.quoted_path(vexe)} $verbose_flag doctor')
|
||||
if result.exit_code != 0 {
|
||||
eprintln('unable to get `v doctor` output: $result.output')
|
||||
return ''
|
||||
@@ -24,7 +24,7 @@ fn get_v_build_output(is_verbose bool, is_yes bool, file_path string) string {
|
||||
os.chdir(vroot) or {}
|
||||
verbose_flag := if is_verbose { '-v' } else { '' }
|
||||
vdbg_path := $if windows { '$vroot/vdbg.exe' } $else { '$vroot/vdbg' }
|
||||
vdbg_compilation_cmd := '"$vexe" $verbose_flag -g -o "$vdbg_path" cmd/v'
|
||||
vdbg_compilation_cmd := '${os.quoted_path(vexe)} $verbose_flag -g -o ${os.quoted_path(vdbg_path)} cmd/v'
|
||||
vdbg_result := os.execute(vdbg_compilation_cmd)
|
||||
os.chdir(wd) or {}
|
||||
if vdbg_result.exit_code == 0 {
|
||||
@@ -33,7 +33,7 @@ fn get_v_build_output(is_verbose bool, is_yes bool, file_path string) string {
|
||||
eprintln('unable to compile V in debug mode: $vdbg_result.output\ncommand: $vdbg_compilation_cmd\n')
|
||||
}
|
||||
//
|
||||
mut result := os.execute('"$vexe" $verbose_flag "$file_path"')
|
||||
mut result := os.execute('${os.quoted_path(vexe)} $verbose_flag ${os.quoted_path(file_path)}')
|
||||
defer {
|
||||
os.rm(vdbg_path) or {
|
||||
if is_verbose {
|
||||
@@ -56,7 +56,7 @@ fn get_v_build_output(is_verbose bool, is_yes bool, file_path string) string {
|
||||
run := is_yes
|
||||
|| ask('It looks like the compilation went well, do you want to run the file?')
|
||||
if run {
|
||||
result = os.execute('"$vexe" $verbose_flag run "$file_path"')
|
||||
result = os.execute('${os.quoted_path(vexe)} $verbose_flag run ${os.quoted_path(file_path)}')
|
||||
if result.exit_code == 0 && !is_yes {
|
||||
confirm_or_exit('It looks like the file ran correctly as well, are you sure you want to continue?')
|
||||
}
|
||||
|
||||
@@ -69,22 +69,19 @@ fn run_individual_test(case BumpTestCase) ? {
|
||||
|
||||
os.rm(test_file) or {}
|
||||
os.write_file(test_file, case.contents) ?
|
||||
//
|
||||
os.execute_or_exit('${os.quoted_path(vexe)} bump --patch ${os.quoted_path(test_file)}')
|
||||
patch_lines := os.read_lines(test_file) ?
|
||||
assert patch_lines[case.line] == case.expected_patch
|
||||
|
||||
{
|
||||
os.execute_or_exit('$vexe bump --patch $test_file')
|
||||
patch_lines := os.read_lines(test_file) ?
|
||||
assert patch_lines[case.line] == case.expected_patch
|
||||
}
|
||||
{
|
||||
os.execute_or_exit('$vexe bump --minor $test_file')
|
||||
minor_lines := os.read_lines(test_file) ?
|
||||
assert minor_lines[case.line] == case.expected_minor
|
||||
}
|
||||
{
|
||||
os.execute_or_exit('$vexe bump --major $test_file')
|
||||
major_lines := os.read_lines(test_file) ?
|
||||
assert major_lines[case.line] == case.expected_major
|
||||
}
|
||||
os.execute_or_exit('${os.quoted_path(vexe)} bump --minor ${os.quoted_path(test_file)}')
|
||||
minor_lines := os.read_lines(test_file) ?
|
||||
assert minor_lines[case.line] == case.expected_minor
|
||||
|
||||
os.execute_or_exit('${os.quoted_path(vexe)} bump --major ${os.quoted_path(test_file)}')
|
||||
major_lines := os.read_lines(test_file) ?
|
||||
assert major_lines[case.line] == case.expected_major
|
||||
//
|
||||
os.rm(test_file) ?
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ import os
|
||||
const test_path = 'vcreate_test'
|
||||
|
||||
fn init_and_check() ? {
|
||||
vexe := @VEXE
|
||||
os.execute_or_exit('$vexe init')
|
||||
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
||||
|
||||
assert os.read_file('vcreate_test.v') ? == [
|
||||
'module main\n',
|
||||
@@ -92,8 +91,7 @@ fn test_v_init_no_overwrite_gitignore() ? {
|
||||
}
|
||||
os.chdir(dir) ?
|
||||
|
||||
vexe := @VEXE
|
||||
os.execute_or_exit('$vexe init')
|
||||
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
||||
|
||||
assert os.read_file('.gitignore') ? == 'blah'
|
||||
}
|
||||
@@ -121,8 +119,7 @@ indent_size = 4
|
||||
}
|
||||
os.chdir(dir) ?
|
||||
|
||||
vexe := @VEXE
|
||||
os.execute_or_exit('$vexe init')
|
||||
os.execute_or_exit('${os.quoted_path(@VEXE)} init')
|
||||
|
||||
assert os.read_file('.gitattributes') ? == git_attributes_content
|
||||
assert os.read_file('.editorconfig') ? == editor_config_content
|
||||
|
||||
@@ -35,7 +35,7 @@ fn check_path(vexe string, dir string, tests []string) int {
|
||||
for path in paths {
|
||||
program := path
|
||||
print(path + ' ')
|
||||
res := os.execute('$vexe doc $program')
|
||||
res := os.execute('${os.quoted_path(vexe)} doc ${os.quoted_path(program)}')
|
||||
if res.exit_code < 0 {
|
||||
panic(res.output)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ fn check_path(vexe string, dir string, tests []string) int {
|
||||
print_compare(expected, found)
|
||||
}
|
||||
|
||||
res_comments := os.execute('$vexe doc -comments $program')
|
||||
res_comments := os.execute('${os.quoted_path(vexe)} doc -comments ${os.quoted_path(program)}')
|
||||
if res_comments.exit_code < 0 {
|
||||
panic(res_comments.output)
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ fn parse_arguments(args []string) Config {
|
||||
fn main() {
|
||||
if os.args.len < 2 || '-h' in os.args || '-help' in os.args || '--help' in os.args
|
||||
|| os.args[1..] == ['doc', 'help'] {
|
||||
os.system('$vexe help doc')
|
||||
os.system('${os.quoted_path(vexe)} help doc')
|
||||
exit(0)
|
||||
}
|
||||
args := os.args[2..].clone()
|
||||
|
||||
@@ -92,7 +92,11 @@ fn main() {
|
||||
exit(0)
|
||||
}
|
||||
mut cli_args_no_files := []string{}
|
||||
for a in os.args {
|
||||
for idx, a in os.args {
|
||||
if idx == 0 {
|
||||
cli_args_no_files << os.quoted_path(a)
|
||||
continue
|
||||
}
|
||||
if a !in files {
|
||||
cli_args_no_files << a
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ fn repl_run_vfile(file string) ?os.Result {
|
||||
$if trace_repl_temp_files ? {
|
||||
eprintln('>> repl_run_vfile file: $file')
|
||||
}
|
||||
s := os.execute('"$vexe" -repl run "$file"')
|
||||
s := os.execute('${os.quoted_path(vexe)} -repl run ${os.quoted_path(file)}')
|
||||
if s.exit_code < 0 {
|
||||
rerror(s.output)
|
||||
return error(s.output)
|
||||
|
||||
@@ -21,7 +21,7 @@ fn main() {
|
||||
jargs := args.join(' ')
|
||||
obinary := cmdline.option(args, '-o', '')
|
||||
sargs := if obinary != '' { jargs } else { '$jargs -o v2' }
|
||||
cmd := '$vexe $sargs cmd/v'
|
||||
cmd := '${os.quoted_path(vexe)} $sargs ${os.quoted_path('cmd/v')}'
|
||||
options := if args.len > 0 { '($sargs)' } else { '' }
|
||||
println('V self compiling ${options}...')
|
||||
compile(vroot, cmd)
|
||||
|
||||
@@ -13,5 +13,5 @@ fn main() {
|
||||
args_str := args.join(' ')
|
||||
options := if args.len > 0 { '($args_str)' } else { '' }
|
||||
println('Compiling a `tracev` executable ${options}...')
|
||||
os.system('"$vexe" -cg -d trace_parser -d trace_checker -d trace_gen -o tracev $args_str cmd/v')
|
||||
os.system('${os.quoted_path(vexe)} -cg -d trace_parser -d trace_checker -d trace_gen -o tracev $args_str cmd/v')
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ fn (app App) update_from_master() {
|
||||
fn (app App) recompile_v() {
|
||||
// NB: app.vexe is more reliable than just v (which may be a symlink)
|
||||
opts := if app.is_prod { '-prod' } else { '' }
|
||||
vself := '"$app.vexe" $opts self'
|
||||
vself := '${os.quoted_path(app.vexe)} $opts self'
|
||||
app.vprintln('> recompiling v itself with `$vself` ...')
|
||||
self_result := os.execute(vself)
|
||||
if self_result.exit_code == 0 {
|
||||
@@ -83,7 +83,7 @@ fn (app App) recompile_v() {
|
||||
}
|
||||
|
||||
fn (app App) recompile_vup() {
|
||||
vup_result := os.execute('"$app.vexe" -g cmd/tools/vup.v')
|
||||
vup_result := os.execute('${os.quoted_path(app.vexe)} -g cmd/tools/vup.v')
|
||||
if vup_result.exit_code != 0 {
|
||||
eprintln('recompiling vup.v failed:')
|
||||
eprintln(vup_result.output)
|
||||
@@ -106,7 +106,7 @@ fn (app App) make(vself string) {
|
||||
}
|
||||
|
||||
fn (app App) show_current_v_version() {
|
||||
vout := os.execute('"$app.vexe" version')
|
||||
vout := os.execute('${os.quoted_path(app.vexe)} version')
|
||||
if vout.exit_code >= 0 {
|
||||
mut vversion := vout.output.trim_space()
|
||||
if vout.exit_code == 0 {
|
||||
@@ -153,7 +153,7 @@ fn (app App) get_git() {
|
||||
eprintln('Unable to install git automatically: please install git manually')
|
||||
panic(res_download.output)
|
||||
}
|
||||
res_git32 := os.execute('$os.getwd()/git32.exe')
|
||||
res_git32 := os.execute(os.quoted_path(os.join_path_single(os.getwd(), 'git32.exe')))
|
||||
if res_git32.exit_code != 0 {
|
||||
eprintln('Unable to install git automatically: please install git manually')
|
||||
panic(res_git32.output)
|
||||
|
||||
@@ -35,7 +35,7 @@ fn check_path(vexe string, dir string, tests []string) int {
|
||||
program := path
|
||||
print(path + ' ')
|
||||
// -force is needed so that `v vet` would not skip the regression files
|
||||
res := os.execute('$vexe vet -force -nocolor $program')
|
||||
res := os.execute('${os.quoted_path(vexe)} vet -force -nocolor ${os.quoted_path(program)}')
|
||||
if res.exit_code < 0 {
|
||||
panic(res.output)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user