mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: replace dir_exists with is_dir; file_exists() => exists()
This commit is contained in:
@ -38,7 +38,7 @@ fn (v mut V) cc() {
|
||||
$if !js {
|
||||
if v.out_name.ends_with('.js') {
|
||||
vjs_path := vexe + 'js'
|
||||
if !os.file_exists(vjs_path) {
|
||||
if !os.exists(vjs_path) {
|
||||
println('V.js compiler not found, building...')
|
||||
// Build V.js. Specifying `-os js` makes V include
|
||||
// only _js.v files and ignore _c.v files.
|
||||
@ -98,7 +98,7 @@ fn (v mut V) cc() {
|
||||
tcc_3rd := '$vdir/thirdparty/tcc/bin/tcc'
|
||||
//println('tcc third "$tcc_3rd"')
|
||||
tcc_path := '/var/tmp/tcc/bin/tcc'
|
||||
if os.file_exists(tcc_3rd) && !os.file_exists(tcc_path) {
|
||||
if os.exists(tcc_3rd) && !os.exists(tcc_path) {
|
||||
//println('moving tcc')
|
||||
// if there's tcc in thirdparty/, that means this is
|
||||
// a prebuilt V_linux.zip.
|
||||
@ -106,7 +106,7 @@ fn (v mut V) cc() {
|
||||
// it to /var/tmp/
|
||||
os.system('mv $vdir/thirdparty/tcc /var/tmp/')
|
||||
}
|
||||
if v.pref.ccompiler == 'cc' && os.file_exists(tcc_path) {
|
||||
if v.pref.ccompiler == 'cc' && os.exists(tcc_path) {
|
||||
// TODO tcc bug, needs an empty libtcc1.a fila
|
||||
//os.mkdir('/var/tmp/tcc/lib/tcc/') or { panic(err) }
|
||||
//os.create('/var/tmp/tcc/lib/tcc/libtcc1.a')
|
||||
@ -136,7 +136,7 @@ fn (v mut V) cc() {
|
||||
'$v_modules_path${os.path_separator}$v.dir'
|
||||
}
|
||||
pdir := out_dir.all_before_last(os.path_separator)
|
||||
if !os.dir_exists(pdir) {
|
||||
if !os.is_dir(pdir) {
|
||||
os.mkdir_all(pdir)
|
||||
}
|
||||
v.out_name = '${out_dir}.o' //v.out_name
|
||||
@ -202,7 +202,7 @@ fn (v mut V) cc() {
|
||||
else if v.pref.is_cache {
|
||||
builtin_o_path := filepath.join(v_modules_path, 'cache', 'vlib', 'builtin.o')
|
||||
a << builtin_o_path.replace('builtin.o', 'strconv.o') // TODO hack no idea why this is needed
|
||||
if os.file_exists(builtin_o_path) {
|
||||
if os.exists(builtin_o_path) {
|
||||
libs = builtin_o_path
|
||||
} else {
|
||||
println('$builtin_o_path not found... building module builtin')
|
||||
@ -215,7 +215,7 @@ fn (v mut V) cc() {
|
||||
imp_path := imp.replace('.', os.path_separator)
|
||||
path := '$v_modules_path${os.path_separator}cache${os.path_separator}vlib${os.path_separator}${imp_path}.o'
|
||||
//println('adding ${imp_path}.o')
|
||||
if os.file_exists(path) {
|
||||
if os.exists(path) {
|
||||
libs += ' ' + path
|
||||
} else {
|
||||
println('$path not found... building module $imp')
|
||||
@ -253,7 +253,7 @@ fn (v mut V) cc() {
|
||||
//
|
||||
// Output executable name
|
||||
a << '-o "$v.out_name"'
|
||||
if os.dir_exists(v.out_name) {
|
||||
if os.is_dir(v.out_name) {
|
||||
verror('\'$v.out_name\' is a directory')
|
||||
}
|
||||
// macOS code can include objective C TODO remove once objective C is replaced with C
|
||||
@ -426,7 +426,7 @@ fn (c mut V) cc_windows_cross() {
|
||||
mut libs := ''
|
||||
if c.pref.build_mode == .default_mode {
|
||||
libs = '"$v_modules_path/vlib/builtin.o"'
|
||||
if !os.file_exists(libs) {
|
||||
if !os.exists(libs) {
|
||||
println('`$libs` not found')
|
||||
exit(1)
|
||||
}
|
||||
@ -442,7 +442,7 @@ fn (c mut V) cc_windows_cross() {
|
||||
}
|
||||
println('Cross compiling for Windows...')
|
||||
winroot := '$v_modules_path/winroot'
|
||||
if !os.dir_exists(winroot) {
|
||||
if !os.is_dir(winroot) {
|
||||
winroot_url := 'https://github.com/vlang/v/releases/download/v0.1.10/winroot.zip'
|
||||
println('"$winroot" not found.')
|
||||
println('Download it from $winroot_url and save it in $v_modules_path')
|
||||
@ -502,7 +502,7 @@ fn find_c_compiler() string {
|
||||
|
||||
fn find_c_compiler_default() string {
|
||||
//fast_clang := '/usr/local/Cellar/llvm/8.0.0/bin/clang'
|
||||
//if os.file_exists(fast_clang) {
|
||||
//if os.exists(fast_clang) {
|
||||
// return fast_clang
|
||||
//}
|
||||
// TODO fix $if after 'string'
|
||||
|
@ -255,7 +255,7 @@ fn (g mut CGen) add_to_main(s string) {
|
||||
|
||||
fn build_thirdparty_obj_file(path string, moduleflags []CFlag) {
|
||||
obj_path := os.realpath(path)
|
||||
if os.file_exists(obj_path) {
|
||||
if os.exists(obj_path) {
|
||||
return
|
||||
}
|
||||
println('$obj_path not found, building it...')
|
||||
|
@ -153,12 +153,12 @@ fn (p mut Parser) comp_time() {
|
||||
if p.pref.is_debug {
|
||||
println('compiling tmpl $path')
|
||||
}
|
||||
if !os.file_exists(path) {
|
||||
if !os.exists(path) {
|
||||
// Can't find the template file in current directory,
|
||||
// try looking next to the vweb program, in case it's run with
|
||||
// v path/to/vweb_app.v
|
||||
path = os.dir(p.scanner.file_path) + '/' + path
|
||||
if !os.file_exists(path) {
|
||||
if !os.exists(path) {
|
||||
p.error('vweb HTML template "$path" not found')
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ void reload_so() {
|
||||
sprintf(compile_cmd, "$vexe $msvc -o %s -shared $file", new_so_base);
|
||||
os__system(tos2(compile_cmd));
|
||||
|
||||
if( !os__file_exists(tos2(new_so_name)) ) {
|
||||
if( !os__exists(tos2(new_so_name)) ) {
|
||||
fprintf(stderr, "Errors while compiling $file\\n");
|
||||
continue;
|
||||
}
|
||||
|
@ -587,13 +587,13 @@ pub fn (v V) run_compiled_executable_and_exit() {
|
||||
|
||||
pub fn (v &V) v_files_from_dir(dir string) []string {
|
||||
mut res := []string
|
||||
if !os.file_exists(dir) {
|
||||
if dir == 'compiler' && os.dir_exists('vlib') {
|
||||
if !os.exists(dir) {
|
||||
if dir == 'compiler' && os.is_dir('vlib') {
|
||||
println('looks like you are trying to build V with an old command')
|
||||
println('use `v -o v v.v` instead of `v -o v compiler`')
|
||||
}
|
||||
verror("$dir doesn't exist")
|
||||
} else if !os.dir_exists(dir) {
|
||||
} else if !os.is_dir(dir) {
|
||||
verror("$dir isn't a directory")
|
||||
}
|
||||
mut files := os.ls(dir) or { panic(err) }
|
||||
@ -639,7 +639,7 @@ pub fn (v mut V) add_v_files_to_compile() {
|
||||
}
|
||||
// Builtin cache exists? Use it.
|
||||
builtin_vh := '${v.pref.vlib_path}${os.path_separator}builtin.vh'
|
||||
if v.pref.is_cache && os.file_exists(builtin_vh) {
|
||||
if v.pref.is_cache && os.exists(builtin_vh) {
|
||||
v.cached_mods << 'builtin'
|
||||
builtin_files = [builtin_vh]
|
||||
}
|
||||
@ -685,7 +685,7 @@ pub fn (v mut V) add_v_files_to_compile() {
|
||||
if v.pref.vpath != '' && v.pref.build_mode != .build_module && !mod.contains('vweb') {
|
||||
mod_path := mod.replace('.', os.path_separator)
|
||||
vh_path := '$v_modules_path${os.path_separator}vlib${os.path_separator}${mod_path}.vh'
|
||||
if v.pref.is_cache && os.file_exists(vh_path) {
|
||||
if v.pref.is_cache && os.exists(vh_path) {
|
||||
eprintln('using cached module `$mod`: $vh_path')
|
||||
v.cached_mods << mod
|
||||
v.files << vh_path
|
||||
@ -850,7 +850,7 @@ pub fn (v &V) log(s string) {
|
||||
|
||||
pub fn new_v(args[]string) &V {
|
||||
// Create modules dirs if they are missing
|
||||
if !os.dir_exists(v_modules_path) {
|
||||
if !os.is_dir(v_modules_path) {
|
||||
os.mkdir(v_modules_path) or { panic(err) }
|
||||
os.mkdir('$v_modules_path${os.path_separator}cache') or { panic(err) }
|
||||
}
|
||||
@ -923,7 +923,7 @@ pub fn new_v(args[]string) &V {
|
||||
}
|
||||
is_test := dir.ends_with('_test.v')
|
||||
is_script := dir.ends_with('.v') || dir.ends_with('.vsh')
|
||||
if is_script && !os.file_exists(dir) {
|
||||
if is_script && !os.exists(dir) {
|
||||
println('`$dir` does not exist')
|
||||
exit(1)
|
||||
}
|
||||
@ -933,7 +933,7 @@ pub fn new_v(args[]string) &V {
|
||||
// Building V? Use v2, since we can't overwrite a running
|
||||
// executable on Windows + the precompiled V is more
|
||||
// optimized.
|
||||
if out_name == 'v' && os.dir_exists('vlib/compiler') {
|
||||
if out_name == 'v' && os.is_dir('vlib/compiler') {
|
||||
println('Saving the resulting V executable in `./v2`')
|
||||
println('Use `v -o v v.v` if you want to replace current '+
|
||||
'V executable.')
|
||||
@ -948,7 +948,7 @@ pub fn new_v(args[]string) &V {
|
||||
// `v -o dir/exec`, create "dir/" if it doesn't exist
|
||||
if out_name.contains(os.path_separator) {
|
||||
d := out_name.all_before_last(os.path_separator)
|
||||
if !os.dir_exists(d) {
|
||||
if !os.is_dir(d) {
|
||||
println('creating a new directory "$d"')
|
||||
os.mkdir(d) or { panic(err) }
|
||||
}
|
||||
@ -989,7 +989,7 @@ pub fn new_v(args[]string) &V {
|
||||
}
|
||||
//println('VROOT=$vroot')
|
||||
// v.exe's parent directory should contain vlib
|
||||
if !os.dir_exists(vlib_path) || !os.dir_exists(vlib_path + os.path_separator + 'builtin') {
|
||||
if !os.is_dir(vlib_path) || !os.is_dir(vlib_path + os.path_separator + 'builtin') {
|
||||
//println('vlib not found, downloading it...')
|
||||
/*
|
||||
ret := os.system('git clone --depth=1 https://github.com/vlang/v .')
|
||||
@ -1104,7 +1104,7 @@ pub fn env_vflags_and_os_args() []string {
|
||||
pub fn vfmt(args[]string) {
|
||||
println('running vfmt...')
|
||||
file := args.last()
|
||||
if !os.file_exists(file) {
|
||||
if !os.exists(file) {
|
||||
println('"$file" does not exist')
|
||||
exit(1)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ fn generate_vh(mod string) {
|
||||
dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${os.path_separator}$mod' } else { mod }
|
||||
path := dir + '.vh'
|
||||
pdir := dir.all_before_last(os.path_separator)
|
||||
if !os.dir_exists(pdir) {
|
||||
if !os.is_dir(pdir) {
|
||||
os.mkdir_all(pdir)
|
||||
// os.mkdir(os.realpath(dir)) or { panic(err) }
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ fn (v &V) find_module_path(mod string) ?string {
|
||||
}
|
||||
for try_path in tried_paths {
|
||||
if v.pref.is_verbose { println(' >> trying to find $mod in $try_path ...') }
|
||||
if os.dir_exists(try_path) {
|
||||
if os.is_dir(try_path) {
|
||||
return try_path
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ fn find_vs(vswhere_dir string, host_arch string) ?VsInstallation {
|
||||
lib_path := '$res.output\\VC\\Tools\\MSVC\\$v\\lib\\$host_arch'
|
||||
include_path := '$res.output\\VC\\Tools\\MSVC\\$v\\include'
|
||||
|
||||
if os.file_exists('$lib_path\\vcruntime.lib') {
|
||||
if os.exists('$lib_path\\vcruntime.lib') {
|
||||
p := '$res.output\\VC\\Tools\\MSVC\\$v\\bin\\Host$host_arch\\$host_arch'
|
||||
|
||||
// println('$lib_path $include_path')
|
||||
@ -274,7 +274,7 @@ pub fn (v mut V) cc_msvc() {
|
||||
/*
|
||||
b := os.realpath( '$v_modules_path/vlib/builtin.obj' )
|
||||
alibs << '"$b"'
|
||||
if !os.file_exists(b) {
|
||||
if !os.exists(b) {
|
||||
println('`builtin.obj` not found')
|
||||
exit(1)
|
||||
}
|
||||
@ -390,7 +390,7 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) {
|
||||
|
||||
obj_path = os.realpath(obj_path)
|
||||
|
||||
if os.file_exists(obj_path) {
|
||||
if os.exists(obj_path) {
|
||||
println('$obj_path already build.')
|
||||
return
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ mut:
|
||||
|
||||
// new scanner from file.
|
||||
fn new_scanner_file(file_path string) &Scanner {
|
||||
if !os.file_exists(file_path) {
|
||||
if !os.exists(file_path) {
|
||||
verror("$file_path doesn't exist")
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import filepath
|
||||
|
||||
pub fn get_vtmp_folder() string {
|
||||
vtmp := filepath.join(os.tmpdir(),'v')
|
||||
if !os.dir_exists( vtmp ) {
|
||||
if !os.is_dir( vtmp ) {
|
||||
os.mkdir(vtmp) or { panic(err) }
|
||||
}
|
||||
return vtmp
|
||||
|
@ -15,7 +15,7 @@ pub fn launch_tool(tname string){
|
||||
//println('Launching: "$tool_command" ...')
|
||||
|
||||
mut tool_should_be_recompiled := false
|
||||
if !os.file_exists( tool_exe ) {
|
||||
if !os.exists( tool_exe ) {
|
||||
// fresh checkout
|
||||
tool_should_be_recompiled = true
|
||||
}else{
|
||||
|
Reference in New Issue
Block a user