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

os api: basedir => base_dir

This commit is contained in:
yuyi 2020-03-08 22:43:56 +08:00 committed by GitHub
parent 2bed0d1bb5
commit 23b11c84b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 11 deletions

View File

@ -179,13 +179,13 @@ fn (foptions &FormatOptions) format_file(file string) {
is_test_file := file.ends_with('_test.v') is_test_file := file.ends_with('_test.v')
mod_name,is_module_file := file_to_mod_name_and_is_module_file(file) mod_name,is_module_file := file_to_mod_name_and_is_module_file(file)
use_tmp_main_program := is_module_file && !is_test_file use_tmp_main_program := is_module_file && !is_test_file
mod_folder := os.basedir(file) mod_folder := os.base_dir(file)
if use_tmp_main_program { if use_tmp_main_program {
// TODO: remove the need for this // TODO: remove the need for this
// This makes a small program that imports the module, // This makes a small program that imports the module,
// so that the module files will get processed by the // so that the module files will get processed by the
// vfmt implementation. // vfmt implementation.
mod_folder_parent = os.basedir(mod_folder) mod_folder_parent = os.base_dir(mod_folder)
mut main_program_content := if mod_name == 'builtin' || mod_name == 'main' { 'fn main(){}\n' } else { 'import ${mod_name}\n' + 'fn main(){}\n' } mut main_program_content := if mod_name == 'builtin' || mod_name == 'main' { 'fn main(){}\n' } else { 'import ${mod_name}\n' + 'fn main(){}\n' }
main_program_file := os.join(tmpfolder,'vfmt_tmp_${mod_name}_program.v') main_program_file := os.join(tmpfolder,'vfmt_tmp_${mod_name}_program.v')
if os.exists(main_program_file) { if os.exists(main_program_file) {

View File

@ -780,7 +780,7 @@ pub fn (v &V) get_user_files() []string {
v.log('> That brings in all other ordinary .v files in the same module too .') v.log('> That brings in all other ordinary .v files in the same module too .')
} }
user_files << single_test_v_file user_files << single_test_v_file
dir = os.basedir(single_test_v_file) dir = os.base_dir(single_test_v_file)
} }
if dir.ends_with('.v') || dir.ends_with('.vsh') { if dir.ends_with('.v') || dir.ends_with('.vsh') {
single_v_file := dir single_v_file := dir

View File

@ -167,7 +167,7 @@ fn (v mut V) set_module_lookup_paths() {
// 3.2) search in ~/.vmodules/ (i.e. modules installed with vpm) // 3.2) search in ~/.vmodules/ (i.e. modules installed with vpm)
v.module_lookup_paths = [] v.module_lookup_paths = []
if v.pref.is_test { if v.pref.is_test {
v.module_lookup_paths << os.basedir(v.compiled_dir) // pdir of _test.v v.module_lookup_paths << os.base_dir(v.compiled_dir) // pdir of _test.v
} }
v.module_lookup_paths << v.compiled_dir v.module_lookup_paths << v.compiled_dir
v.module_lookup_paths << os.join(v.compiled_dir,'modules') v.module_lookup_paths << os.join(v.compiled_dir,'modules')

View File

@ -103,7 +103,7 @@ fn (mcache mut ModFileCacher) traverse(mfolder string) ([]string, ModFileAndFold
if mcache.check_for_stop( cfolder, files ) { if mcache.check_for_stop( cfolder, files ) {
break break
} }
cfolder = os.basedir( cfolder ) cfolder = os.base_dir( cfolder )
folders_so_far << cfolder folders_so_far << cfolder
levels++ levels++
} }

View File

@ -204,7 +204,7 @@ pub fn new_context(cfg gg.Cfg) &FreeType {
} }
if !os.exists(font_path) { if !os.exists(font_path) {
exe_path := os.executable() exe_path := os.executable()
exe_dir := os.basedir(exe_path) exe_dir := os.base_dir(exe_path)
font_path = '$exe_dir/$font_path' font_path = '$exe_dir/$font_path'
} }
if !os.exists(font_path) { if !os.exists(font_path) {

View File

@ -69,7 +69,7 @@ pub fn (l mut Log) set_output_level(level LogLevel) {
pub fn (l mut Log) set_full_logpath(full_log_path string) { pub fn (l mut Log) set_full_logpath(full_log_path string) {
rlog_file := os.realpath( full_log_path ) rlog_file := os.realpath( full_log_path )
l.set_output_label( os.filename( rlog_file ) ) l.set_output_label( os.filename( rlog_file ) )
l.set_output_path( os.basedir( rlog_file ) ) l.set_output_path( os.base_dir( rlog_file ) )
} }
pub fn (l mut Log) set_output_label(label string){ pub fn (l mut Log) set_output_label(label string){

View File

@ -667,7 +667,7 @@ pub fn dir(path string) string {
return path[..pos] return path[..pos]
} }
pub fn basedir(path string) string { pub fn base_dir(path string) string {
pos := path.last_index(path_separator) or { pos := path.last_index(path_separator) or {
return path return path
} }

View File

@ -325,12 +325,12 @@ fn test_dir() {
fn test_basedir() { fn test_basedir() {
$if windows { $if windows {
assert os.basedir('v\\vlib\\os') == 'v\\vlib' assert os.base_dir('v\\vlib\\os') == 'v\\vlib'
} $else { } $else {
assert os.basedir('v/vlib/os') == 'v/vlib' assert os.base_dir('v/vlib/os') == 'v/vlib'
} }
assert os.basedir('filename') == 'filename' assert os.base_dir('filename') == 'filename'
} }
// this function is called by both test_aaa_setup & test_zzz_cleanup // this function is called by both test_aaa_setup & test_zzz_cleanup