From 62c3ad495324f768c774d2d2fe7d2553d7fba6dc Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 22 Jan 2022 21:56:01 +0200 Subject: [PATCH] use os.quoted_path more --- cmd/tools/modules/testing/common.v | 4 ++-- cmd/tools/vcheck-md.v | 14 +++++++------- cmd/tools/vdoctor.v | 8 ++++++-- cmd/tools/vgret.v | 6 +++--- cmd/tools/vshader.v | 4 +++- cmd/tools/vtest-all.v | 6 ++++-- cmd/tools/vtest-cleancode.v | 9 +++++++-- cmd/tools/vtest-parser.v | 2 +- examples/dynamic_library_loading/use_test.v | 2 +- vlib/v/builder/rebuilding.v | 2 +- vlib/v/util/diff/diff.v | 2 +- vlib/v/util/util.v | 12 ++++++------ 12 files changed, 42 insertions(+), 29 deletions(-) diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 046466f491..84add27d3d 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -330,9 +330,9 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { } if !ts.vargs.contains('fmt') { - cmd_options << ' -o "$generated_binary_fpath"' + cmd_options << ' -o ${os.quoted_path(generated_binary_fpath)}' } - cmd := '"$ts.vexe" ' + cmd_options.join(' ') + ' "$file"' + cmd := '${os.quoted_path(ts.vexe)} ' + cmd_options.join(' ') + ' ${os.quoted_path(file)}' ts.benchmark.step() tls_bench.step() if relative_file.replace('\\', '/') in ts.skip_files { diff --git a/cmd/tools/vcheck-md.v b/cmd/tools/vcheck-md.v index e74640453e..07cf02df1f 100644 --- a/cmd/tools/vcheck-md.v +++ b/cmd/tools/vcheck-md.v @@ -410,7 +410,7 @@ fn silent_cmdexecute(cmd string) int { } fn get_fmt_exit_code(vfile string, vexe string) int { - return silent_cmdexecute('"$vexe" fmt -verify $vfile') + return silent_cmdexecute('${os.quoted_path(vexe)} fmt -verify ${os.quoted_path(vfile)}') } fn (mut f MDFile) check_examples() CheckResult { @@ -438,7 +438,7 @@ fn (mut f MDFile) check_examples() CheckResult { fmt_res := if nofmt { 0 } else { get_fmt_exit_code(vfile, vexe) } match command { 'compile' { - res := cmdexecute('"$vexe" -w -Wfatal-errors -o x.c $vfile') + res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o x.c ${os.quoted_path(vfile)}') os.rm('x.c') or {} if res != 0 || fmt_res != 0 { if res != 0 { @@ -455,7 +455,7 @@ fn (mut f MDFile) check_examples() CheckResult { oks++ } 'globals' { - res := cmdexecute('"$vexe" -w -Wfatal-errors -enable-globals -o x.c $vfile') + res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -enable-globals -o x.c ${os.quoted_path(vfile)}') os.rm('x.c') or {} if res != 0 || fmt_res != 0 { if res != 0 { @@ -472,7 +472,7 @@ fn (mut f MDFile) check_examples() CheckResult { oks++ } 'live' { - res := cmdexecute('"$vexe" -w -Wfatal-errors -live -o x.c $vfile') + res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -live -o x.c ${os.quoted_path(vfile)}') if res != 0 || fmt_res != 0 { if res != 0 { eprintln(eline(f.path, e.sline, 0, 'example failed to compile with -live')) @@ -488,7 +488,7 @@ fn (mut f MDFile) check_examples() CheckResult { oks++ } 'failcompile' { - res := silent_cmdexecute('"$vexe" -w -Wfatal-errors -o x.c $vfile') + res := silent_cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -o x.c ${os.quoted_path(vfile)}') os.rm('x.c') or {} if res == 0 || fmt_res != 0 { if res == 0 { @@ -505,7 +505,7 @@ fn (mut f MDFile) check_examples() CheckResult { oks++ } 'oksyntax' { - res := cmdexecute('"$vexe" -w -Wfatal-errors -check-syntax $vfile') + res := cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -check-syntax ${os.quoted_path(vfile)}') if res != 0 || fmt_res != 0 { if res != 0 { eprintln(eline(f.path, e.sline, 0, '`oksyntax` example with invalid syntax')) @@ -521,7 +521,7 @@ fn (mut f MDFile) check_examples() CheckResult { oks++ } 'badsyntax' { - res := silent_cmdexecute('"$vexe" -w -Wfatal-errors -check-syntax $vfile') + res := silent_cmdexecute('${os.quoted_path(vexe)} -w -Wfatal-errors -check-syntax ${os.quoted_path(vfile)}') if res == 0 { eprintln(eline(f.path, e.sline, 0, '`badsyntax` example can be parsed fine')) eprintln(vcontent) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 05ebfb3e88..a0f963b783 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -241,8 +241,12 @@ fn (mut a App) report_tcc_version(tccfolder string) { a.line(tccfolder, 'N/A') return } - tcc_branch_name := a.cmd(command: 'git -C $tccfolder rev-parse --abbrev-ref HEAD') - tcc_commit := a.cmd(command: 'git -C $tccfolder describe --abbrev=8 --dirty --always --tags') + tcc_branch_name := a.cmd( + command: 'git -C ${os.quoted_path(tccfolder)} rev-parse --abbrev-ref HEAD' + ) + tcc_commit := a.cmd( + command: 'git -C ${os.quoted_path(tccfolder)} describe --abbrev=8 --dirty --always --tags' + ) a.line('$tccfolder status', '$tcc_branch_name $tcc_commit') } diff --git a/cmd/tools/vgret.v b/cmd/tools/vgret.v index 9d8f9bdf98..c74f8e955c 100644 --- a/cmd/tools/vgret.v +++ b/cmd/tools/vgret.v @@ -187,7 +187,7 @@ fn generate_screenshots(mut opt Options, output_path string) ? { if opt.verbose { eprintln('Compiling shaders (if needed) for `$file`') } - sh_result := os.execute('$v_exe shader "$app_path"') + sh_result := os.execute('${os.quoted_path(v_exe)} shader ${os.quoted_path(app_path)}') if sh_result.exit_code != 0 { if opt.verbose { eprintln('Skipping shader compile for `$file` v shader failed with:\n$sh_result.output') @@ -241,7 +241,7 @@ fn compare_screenshots(opt Options, output_path string, target_path string) ? { diff_file := os.join_path(os.temp_dir(), os.file_name(src).all_before_last('.') + '.diff.tif') flags := app_config.compare.flags.join(' ') - diff_cmd := '$idiff_exe $flags -abs -od -o "$diff_file" -abs "$src" "$target"' + diff_cmd := '${os.quoted_path(idiff_exe)} $flags -abs -od -o ${os.quoted_path(diff_file)} -abs ${os.quoted_path(src)} ${os.quoted_path(target)}' if opt.verbose { eprintln('Running: $diff_cmd') } @@ -309,7 +309,7 @@ fn take_screenshots(opt Options, app AppConfig) ?[]string { } mut flags := app.capture.flags.join(' ') - v_cmd := '$v_exe $flags -d gg_record run "$app.abs_path"' + v_cmd := '${os.quoted_path(v_exe)} $flags -d gg_record run ${os.quoted_path(app.abs_path)}' if opt.verbose { eprintln('Running `$v_cmd`') } diff --git a/cmd/tools/vshader.v b/cmd/tools/vshader.v index e9a504b198..aabb82cd99 100644 --- a/cmd/tools/vshader.v +++ b/cmd/tools/vshader.v @@ -193,7 +193,9 @@ fn compile_shader(opt CompileOptions, shader_file string) ? { eprintln('$tool_name generating shader code for $slangs in header "$header_name" in "$path" from $shader_file') } - cmd := '$shdc --input "$shader_file" --output "$out_file" --slang "' + slangs.join(':') + '"' + cmd := + '${os.quoted_path(shdc)} --input ${os.quoted_path(shader_file)} --output ${os.quoted_path(out_file)} --slang ' + + os.quoted_path(slangs.join(':')) if opt.verbose { eprintln('$tool_name executing:\n$cmd') } diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index 6ea72a6d66..77c46ffaf7 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -4,9 +4,11 @@ import os import term import time -const vexe = os.getenv('VEXE') +const vexe_path = os.getenv('VEXE') -const vroot = os.dir(vexe) +const vroot = os.dir(vexe_path) + +const vexe = os.quoted_path(vexe_path) const args_string = os.args[1..].join(' ') diff --git a/cmd/tools/vtest-cleancode.v b/cmd/tools/vtest-cleancode.v index 0ed2995d62..c2fd460b93 100644 --- a/cmd/tools/vtest-cleancode.v +++ b/cmd/tools/vtest-cleancode.v @@ -75,9 +75,14 @@ fn tsession(vargs string, tool_source string, tool_cmd string, tool_args string, fn v_test_vetting(vargs string) { expanded_vet_list := util.find_all_v_files(vet_folders) or { return } - vet_session := tsession(vargs, 'vvet', 'v vet', 'vet', expanded_vet_list, vet_known_failing_exceptions) + vet_session := tsession(vargs, 'vvet', '${os.quoted_path(vexe)} vet', 'vet', expanded_vet_list, + vet_known_failing_exceptions) // - fmt_cmd, fmt_args := if is_fix { 'v fmt -w', 'fmt -w' } else { 'v fmt -verify', 'fmt -verify' } + fmt_cmd, fmt_args := if is_fix { + '${os.quoted_path(vexe)} fmt -w', 'fmt -w' + } else { + '${os.quoted_path(vexe)} fmt -verify', 'fmt -verify' + } vfmt_list := util.find_all_v_files(vfmt_verify_list) or { return } exceptions := util.find_all_v_files(vfmt_known_failing_exceptions) or { return } verify_session := tsession(vargs, 'vfmt.v', fmt_cmd, fmt_args, vfmt_list, exceptions) diff --git a/cmd/tools/vtest-parser.v b/cmd/tools/vtest-parser.v index 2743d2dabf..3559461727 100644 --- a/cmd/tools/vtest-parser.v +++ b/cmd/tools/vtest-parser.v @@ -212,7 +212,7 @@ fn (mut context Context) process_whole_file_in_worker(path string) (int, int) { for i in 0 .. len { verbosity := if context.is_verbose { '-v' } else { '' } context.cut_index = i // needed for the progress bar - cmd := '"$context.myself" $verbosity --worker --timeout_ms ${context.timeout_ms:5} --cut_index ${i:5} --path "$path" ' + cmd := '${os.quoted_path(context.myself)} $verbosity --worker --timeout_ms ${context.timeout_ms:5} --cut_index ${i:5} --path ${os.quoted_path(path)} ' context.log(cmd) mut res := os.execute(cmd) context.log('worker exit_code: $res.exit_code | worker output:\n$res.output') diff --git a/examples/dynamic_library_loading/use_test.v b/examples/dynamic_library_loading/use_test.v index a224b2adaf..d7042f1bdc 100644 --- a/examples/dynamic_library_loading/use_test.v +++ b/examples/dynamic_library_loading/use_test.v @@ -47,7 +47,7 @@ fn test_can_compile_and_use_library_with_skip_unused() { } fn v_compile(vopts string) os.Result { - cmd := '"$vexe" -showcc $vopts' + cmd := '${os.quoted_path(vexe)} -showcc $vopts' // dump(cmd) res := os.execute_or_exit(cmd) // dump(res) diff --git a/vlib/v/builder/rebuilding.v b/vlib/v/builder/rebuilding.v index 3a98d2365f..3a06e170dd 100644 --- a/vlib/v/builder/rebuilding.v +++ b/vlib/v/builder/rebuilding.v @@ -166,7 +166,7 @@ fn (mut b Builder) v_build_module(vexe string, imp_path string) { vroot := os.dir(vexe) os.chdir(vroot) or {} boptions := b.pref.build_options.join(' ') - rebuild_cmd := '$vexe $boptions build-module $imp_path' + rebuild_cmd := '${os.quoted_path(vexe)} $boptions build-module ${os.quoted_path(imp_path)}' vcache.dlog('| Builder.' + @FN, 'vexe: $vexe | imp_path: $imp_path | rebuild_cmd: $rebuild_cmd') $if trace_v_build_module ? { eprintln('> Builder.v_build_module: $rebuild_cmd') diff --git a/vlib/v/util/diff/diff.v b/vlib/v/util/diff/diff.v index 4a0b6e437c..8d12c0c45f 100644 --- a/vlib/v/util/diff/diff.v +++ b/vlib/v/util/diff/diff.v @@ -61,7 +61,7 @@ fn opendiff_exists() bool { pub fn color_compare_files(diff_cmd string, file1 string, file2 string) string { if diff_cmd != '' { - full_cmd := '$diff_cmd --minimal --text --unified=2 --show-function-line="fn " "$file1" "$file2" ' + full_cmd := '$diff_cmd --minimal --text --unified=2 --show-function-line="fn " ${os.quoted_path(file1)} ${os.quoted_path(file2)} ' x := os.execute(full_cmd) if x.exit_code < 0 { return 'comparison command: `$full_cmd` not found' diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index c47942b0ad..68972033f0 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -155,7 +155,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { for emodule in emodules { check_module_is_installed(emodule, is_verbose) or { panic(err) } } - mut compilation_command := "'$vexe' -skip-unused " + mut compilation_command := '${os.quoted_path(vexe)} -skip-unused ' 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 @@ -164,7 +164,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { // .v line numbers, to ease diagnostic in #bugs and issues. compilation_command += ' -g ' } - compilation_command += "'$tool_source'" + compilation_command += os.quoted_path(tool_source) if is_verbose { println('Compiling $tool_name with: "$compilation_command"') } @@ -175,10 +175,10 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { } } $if windows { - exit(os.system('"$tool_exe" $tool_args')) + exit(os.system('${os.quoted_path(tool_exe)} $tool_args')) } $else $if js { // no way to implement os.execvp in JS backend - exit(os.system('\'$tool_exe\' $tool_args')) + exit(os.system('${os.quote_path(tool_exe)} $tool_args')) } $else { os.execvp(tool_exe, args) or { panic(err) } } @@ -348,7 +348,7 @@ pub fn check_module_is_installed(modulename string, is_verbose bool) ?bool { } if os.exists(mod_v_file) { vexe := pref.vexe_path() - update_cmd := "'$vexe' update '$modulename'" + update_cmd := "${os.quoted_path(vexe)} update '$modulename'" if is_verbose { eprintln('check_module_is_installed: updating with $update_cmd ...') } @@ -448,7 +448,7 @@ pub fn prepare_tool_when_needed(source_name string) { } pub fn recompile_file(vexe string, file string) { - cmd := "'$vexe' '$file'" + cmd := '${os.quoted_path(vexe)} ${os.quoted_path(file)}' $if trace_recompilation ? { println('recompilation command: $cmd') }