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

os: make chdir() return error

This commit is contained in:
Alexander Medvednikov
2021-08-28 09:35:39 +03:00
parent e85311c2ba
commit 858ba25d55
12 changed files with 25 additions and 26 deletions

View File

@@ -132,7 +132,7 @@ fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string {
// do run `v build-module x` always in main vfolder; x can be a relative path
pwd := os.getwd()
vroot := os.dir(vexe)
os.chdir(vroot)
os.chdir(vroot) or {}
boptions := v.pref.build_options.join(' ')
rebuild_cmd := '$vexe $boptions build-module $imp_path'
vcache.dlog('| Builder.' + @FN, 'vexe: $vexe | imp_path: $imp_path | rebuild_cmd: $rebuild_cmd')
@@ -140,7 +140,7 @@ fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string {
rebuilded_o := v.pref.cache_manager.exists('.o', imp_path) or {
panic('could not rebuild cache module for $imp_path, error: $err.msg')
}
os.chdir(pwd)
os.chdir(pwd) or {}
return rebuilded_o
}
return res
@@ -638,7 +638,7 @@ fn (mut v Builder) cc() {
}
}
//
os.chdir(vdir)
os.chdir(vdir) or {}
tried_compilation_commands << cmd
v.show_cc(cmd, response_file, response_file_content)
// Run
@@ -649,7 +649,7 @@ fn (mut v Builder) cc() {
if v.pref.show_c_output {
v.show_c_compiler_output(res)
}
os.chdir(original_pwd)
os.chdir(original_pwd) or {}
vcache.dlog('| Builder.' + @FN, '> v.pref.use_cache: $v.pref.use_cache | v.pref.retry_compilation: $v.pref.retry_compilation')
vcache.dlog('| Builder.' + @FN, '> cmd res.exit_code: $res.exit_code | cmd: $cmd')
vcache.dlog('| Builder.' + @FN, '> response_file_content:\n$response_file_content')
@@ -957,7 +957,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
//
// prepare for tcc, it needs relative paths to thirdparty/tcc to work:
current_folder := os.getwd()
os.chdir(os.dir(pref.vexe_path()))
os.chdir(os.dir(pref.vexe_path())) or {}
//
mut all_options := []string{}
all_options << v.pref.third_party_option
@@ -970,7 +970,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
println('>>> build_thirdparty_obj_files cmd: $cmd')
}
res := os.execute(cmd)
os.chdir(current_folder)
os.chdir(current_folder) or {}
if res.exit_code != 0 {
eprintln('failed thirdparty object build cmd:\n$cmd')
verror(res.output)

View File

@@ -14,7 +14,7 @@ const diff_cmd = diff.find_working_diff_command() or { '' }
fn test_out_files() ? {
println(term.colorize(term.green, '> testing whether .out files match:'))
os.chdir(vroot)
os.chdir(vroot) or {}
output_path := os.join_path(os.temp_dir(), 'coutput', 'out')
os.mkdir_all(output_path) ?
defer {
@@ -82,7 +82,7 @@ fn test_out_files() ? {
fn test_c_must_have_files() ? {
println(term.colorize(term.green, '> testing whether `.c.must_have` files match:'))
os.chdir(vroot)
os.chdir(vroot) or {}
output_path := os.join_path(os.temp_dir(), 'coutput', 'c_must_have')
os.mkdir_all(output_path) ?
defer {

View File

@@ -4,7 +4,7 @@ import v.pref
import v.ast
fn test_macho() {
os.chdir(os.temp_dir())
os.chdir(os.temp_dir()) or {}
mut g := native.Gen{
pref: &pref.Preferences{}
out_name: 'test.bin'

View File

@@ -13,7 +13,7 @@ fn test_all() {
mut total_errors := 0
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
os.chdir(vroot)
os.chdir(vroot) or {}
diff_cmd := diff.find_working_diff_command() or { '' }
dir := 'vlib/v/tests/inout'
files := os.ls(dir) or { panic(err) }

View File

@@ -10,7 +10,7 @@ fn test_vexe_exists() {
}
fn test_v_profile_works() {
os.chdir(vroot)
os.chdir(vroot) or {}
program_source := os.join_path(vroot, 'vlib/v/tests/profile/profile_test_1.v')
res := os.execute('"$vexe" -profile - run $program_source')
// eprintln('res: $res')

View File

@@ -117,7 +117,7 @@ pub fn new_options() RunnerOptions {
if os.args.len > 1 {
files = os.args[1..]
} else {
os.chdir(os.dir(vexec))
os.chdir(os.dir(vexec)) or {}
wd = os.getwd()
files = os.walk_ext('.', '.repl')
}

View File

@@ -2,7 +2,7 @@ import v.vmod
import os
fn test_from_file() {
os.chdir(os.dir(os.getenv('VEXE')))
os.chdir(os.dir(os.getenv('VEXE'))) or {}
data := vmod.from_file('./v.mod') or { panic(err) }
assert data.name == 'V'
assert data.description == 'The V programming language.'

View File

@@ -95,7 +95,7 @@ fn test_readme_exists_and_is_readable() {
}
fn testsuite_end() {
os.chdir(os.wd_at_startup)
os.chdir(os.wd_at_startup) or {}
os.rmdir_all(vcache_folder) or {}
assert !os.is_dir(vcache_folder)
}