From 783dee1f486dd84c0824cbe989053440d07528a0 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 8 Mar 2020 05:26:26 +0800 Subject: [PATCH] os: merge with filepath --- cmd/tools/fast/fast.v | 5 +- cmd/tools/modules/testing/common.v | 13 ++-- cmd/tools/modules/vgit/vgit.v | 7 +- cmd/tools/oldv.v | 13 ++-- cmd/tools/performance_compare.v | 5 +- cmd/tools/preludes/tests_with_stats.v | 4 +- cmd/tools/vbin2v.v | 3 +- cmd/tools/vbuild-examples.v | 5 +- cmd/tools/vfmt.v | 17 ++--- cmd/tools/vnames.v | 13 ++-- cmd/tools/vpm.v | 15 ++-- cmd/tools/vrepl.v | 5 +- cmd/tools/vself.v | 3 +- cmd/tools/vsetup-freetype.v | 3 +- cmd/tools/vtest-compiler.v | 5 +- cmd/tools/vtest.v | 3 +- cmd/tools/vup.v | 5 +- cmd/v/simple_tool.v | 3 +- examples/sdl/tvintris/tvintris.v | 3 +- vlib/builtin/bare/syscallwrapper_test.v | 3 +- vlib/compiler/aparser.v | 7 +- vlib/compiler/cc.v | 17 ++--- vlib/compiler/cgen.v | 5 +- vlib/compiler/compile_errors.v | 3 +- vlib/compiler/comptime.v | 3 +- vlib/compiler/gen_x64.v | 3 +- vlib/compiler/live.v | 6 +- vlib/compiler/main.v | 43 ++++++----- vlib/compiler/module_header.v | 9 +-- vlib/compiler/modules.v | 11 ++- vlib/compiler/msvc.v | 13 ++-- vlib/compiler/scanner.v | 8 +- vlib/compiler/tests/repl/repl_test.v | 3 +- vlib/compiler/tests/repl/runner/runner.v | 21 +++--- vlib/compiler/v_mod_cache.v | 5 +- vlib/compiler/vtmp.v | 5 +- vlib/filepath/filepath.v | 50 ------------- vlib/filepath/filepath_nix.v | 5 -- vlib/filepath/filepath_test.v | 43 ----------- vlib/filepath/filepath_windows.v | 5 -- vlib/freetype/freetype.v | 3 +- vlib/log/log.v | 8 +- vlib/os/os.v | 78 ++++++++++++-------- vlib/os/os_nix.v | 4 - vlib/os/os_test.v | 55 ++++++++++++-- vlib/os/os_windows.v | 4 - vlib/v/builder/builder.v | 7 +- vlib/v/checker/checker.v | 3 +- vlib/v/doc/doc.v | 9 +-- vlib/v/fmt/fmt_test.v | 7 +- vlib/v/fmt/tests/import_multiple_expected.vv | 2 +- vlib/v/fmt/tests/import_multiple_input.vv | 2 +- vlib/v/gen/cgen_test.v | 3 +- vlib/v/parser/parser.v | 3 +- vlib/v/pref/default.v | 17 ++--- vlib/v/scanner/scanner.v | 4 +- vlib/vweb/vweb.v | 3 +- 57 files changed, 249 insertions(+), 361 deletions(-) delete mode 100644 vlib/filepath/filepath.v delete mode 100644 vlib/filepath/filepath_nix.v delete mode 100644 vlib/filepath/filepath_test.v delete mode 100644 vlib/filepath/filepath_windows.v diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index 5da8741d3c..beaaca7cc6 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -5,13 +5,12 @@ import ( os time - filepath ) fn main() { exe := os.executable() - dir := filepath.dir(exe) - vdir := filepath.dir(filepath.dir(filepath.dir(dir))) + dir := os.dir(exe) + vdir := os.dir(os.dir(os.dir(dir))) if !os.exists('$vdir/v') && !os.is_dir('$vdir/vlib') { println('fast.html generator needs to be located in `v/cmd/tools/fast`') } diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 85885d9d40..6fee1f1734 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -4,7 +4,6 @@ import ( os term benchmark - filepath sync v.pref ) @@ -96,9 +95,9 @@ fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr { file := os.realpath(relative_file) // Ensure that the generated binaries will be stored in the temporary folder. // Remove them after a test passes/fails. - fname := filepath.filename(file) + fname := os.filename(file) generated_binary_fname := if os.user_os() == 'windows' { fname.replace('.v', '.exe') } else { fname.replace('.v', '') } - generated_binary_fpath := filepath.join(tmpd,generated_binary_fname) + generated_binary_fpath := os.join(tmpd,generated_binary_fname) if os.exists(generated_binary_fpath) { os.rm(generated_binary_fpath) } @@ -153,7 +152,7 @@ fn worker_trunner(p mut sync.PoolProcessor, idx int, thread_id int) voidptr { } pub fn vlib_should_be_present(parent_dir string) { - vlib_dir := filepath.join(parent_dir,'vlib') + vlib_dir := os.join(parent_dir,'vlib') if !os.is_dir(vlib_dir) { eprintln('$vlib_dir is missing, it must be next to the V executable') exit(1) @@ -164,13 +163,13 @@ pub fn v_build_failing(zargs string, folder string) bool { main_label := 'Building $folder ...' finish_label := 'building $folder' vexe := pref.vexe_path() - parent_dir := filepath.dir(vexe) + parent_dir := os.dir(vexe) vlib_should_be_present(parent_dir) vargs := zargs.replace(vexe, '') eheader(main_label) eprintln('v compiler args: "$vargs"') mut session := new_test_session(vargs) - files := os.walk_ext(filepath.join(parent_dir,folder), '.v') + files := os.walk_ext(os.join(parent_dir,folder), '.v') mut mains := []string for f in files { if !f.contains('modules') && !f.contains('preludes') { @@ -205,7 +204,7 @@ pub fn building_any_v_binaries_failed() bool { eheader('Building V binaries...') eprintln('VFLAGS is: "' + os.getenv('VFLAGS') + '"') vexe := pref.vexe_path() - parent_dir := filepath.dir(vexe) + parent_dir := os.dir(vexe) testing.vlib_should_be_present(parent_dir) os.chdir(parent_dir) mut failed := false diff --git a/cmd/tools/modules/vgit/vgit.v b/cmd/tools/modules/vgit/vgit.v index bd04c6efe0..8a8658e183 100644 --- a/cmd/tools/modules/vgit/vgit.v +++ b/cmd/tools/modules/vgit/vgit.v @@ -2,7 +2,6 @@ module vgit import os import flag -import filepath import scripting const ( @@ -42,7 +41,7 @@ pub fn line_to_timestamp_and_commit(line string) (int,string) { pub fn normalized_workpath_for_commit(workdir string, commit string) string { nc := 'v_at_' + commit.replace('^', '_').replace('-', '_').replace('/', '_') - return os.realpath(workdir + filepath.separator + nc) + return os.realpath(workdir + os.path_separator + nc) } pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string,string) { @@ -65,7 +64,7 @@ pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string,strin pub fn clone_or_pull( remote_git_url string, local_worktree_path string ) { // NB: after clone_or_pull, the current repo branch is === HEAD === master - if os.is_dir( local_worktree_path ) && os.is_dir(filepath.join(local_worktree_path,'.git')) { + if os.is_dir( local_worktree_path ) && os.is_dir(os.join(local_worktree_path,'.git')) { // Already existing ... Just pulling in this case is faster usually. scripting.run('git -C "$local_worktree_path" checkout --quiet master') scripting.run('git -C "$local_worktree_path" pull --quiet ') @@ -97,7 +96,7 @@ pub mut: pub fn (vgit_context mut VGitContext) compile_oldv_if_needed() { vgit_context.vexename = if os.user_os() == 'windows' { 'v.exe' } else { 'v' } - vgit_context.vexepath = os.realpath( filepath.join(vgit_context.path_v, vgit_context.vexename) ) + vgit_context.vexepath = os.realpath( os.join(vgit_context.path_v, vgit_context.vexename) ) mut command_for_building_v_from_c_source := '' mut command_for_selfbuilding := '' if 'windows' == os.user_os() { diff --git a/cmd/tools/oldv.v b/cmd/tools/oldv.v index 3ea69366e2..87bcb0c114 100644 --- a/cmd/tools/oldv.v +++ b/cmd/tools/oldv.v @@ -1,7 +1,6 @@ import ( os flag - filepath scripting vgit ) @@ -70,16 +69,16 @@ fn main() { scripting.used_tools_must_exist(['git', 'cc']) mut context := Context{} mut fp := flag.new_flag_parser(os.args) - fp.application(filepath.filename(os.executable())) + fp.application(os.filename(os.executable())) fp.version(tool_version) fp.description(tool_description) fp.arguments_description('VCOMMIT') fp.skip_executable() fp.limit_free_args(1, 1) - + context.cleanup = fp.bool('clean', true, 'Clean before running (slower).') context.cmd_to_run = fp.string_('command', `c`, '', 'Command to run in the old V repo.\n') - + commits := vgit.add_common_tool_options(mut context, mut fp) if commits.len > 0 { context.commit_v = commits[0] @@ -102,9 +101,9 @@ fn main() { scripting.rmrf(context.path_v) scripting.rmrf(context.path_vc) } - + context.compile_oldv_if_needed() - + scripting.chdir(context.path_v) println('# v commit hash: $context.commit_v_hash') println('# checkout folder: $context.path_v') @@ -116,5 +115,5 @@ fn main() { println(cmdres.output) exit(cmdres.exit_code) } - + } diff --git a/cmd/tools/performance_compare.v b/cmd/tools/performance_compare.v index a6897b4c2a..a28daebe04 100644 --- a/cmd/tools/performance_compare.v +++ b/cmd/tools/performance_compare.v @@ -1,7 +1,6 @@ import ( os flag - filepath scripting vgit ) @@ -165,7 +164,7 @@ fn (c Context) compare_v_performance(label string, commands []string) string { hyperfine_commands_arguments << " \'cd ${c.a:-34s} ; ./$cmd \' ".replace_each(['@COMPILER@', source_location_a, '@DEBUG@', debug_option_a]) } // ///////////////////////////////////////////////////////////////////////////// - cmd_stats_file := os.realpath([c.workdir, 'v_performance_stats_${label}.json'].join(filepath.separator)) + cmd_stats_file := os.realpath([c.workdir, 'v_performance_stats_${label}.json'].join(os.path_separator)) comparison_cmd := 'hyperfine $c.hyperfineopts ' + '--export-json ${cmd_stats_file} ' + '--time-unit millisecond ' + '--style full --warmup $c.warmups ' + hyperfine_commands_arguments.join(' ') // ///////////////////////////////////////////////////////////////////////////// if c.verbose { @@ -181,7 +180,7 @@ fn main() { scripting.used_tools_must_exist(['cp', 'rm', 'strip', 'make', 'git', 'upx', 'cc', 'wc', 'tail', 'hyperfine']) mut context := new_context() mut fp := flag.new_flag_parser(os.args) - fp.application(filepath.filename(os.executable())) + fp.application(os.filename(os.executable())) fp.version(tool_version) fp.description(tool_description) fp.arguments_description('COMMIT_BEFORE [COMMIT_AFTER]') diff --git a/cmd/tools/preludes/tests_with_stats.v b/cmd/tools/preludes/tests_with_stats.v index 3a3c46ed55..b6aaeedf69 100644 --- a/cmd/tools/preludes/tests_with_stats.v +++ b/cmd/tools/preludes/tests_with_stats.v @@ -8,7 +8,7 @@ module main // / code, instead of in embedded C ... // ///////////////////////////////////////////////////////////////////// import ( - filepath + os benchmark ) @@ -80,7 +80,7 @@ fn (b &BenchedTests) fn_name() string { // Called at the end of the test program produced by `v -stats file_test.v` fn (b mut BenchedTests) end_testing() { b.bench.stop() - println(INNER_INDENT + b.bench.total_message('running V tests in "' + filepath.filename(b.test_suit_file) + '"')) + println(INNER_INDENT + b.bench.total_message('running V tests in "' + os.filename(b.test_suit_file) + '"')) } // /////////////////////////////////////////////////////////////////// diff --git a/cmd/tools/vbin2v.v b/cmd/tools/vbin2v.v index 35dc4b6ece..ce186befd8 100644 --- a/cmd/tools/vbin2v.v +++ b/cmd/tools/vbin2v.v @@ -2,7 +2,6 @@ module main import os import flag -import filepath const ( tool_version = '0.0.3' @@ -42,7 +41,7 @@ fn (context Context) footer() { } fn (context Context) file2v(file string) { - fname := filepath.filename(file) + fname := os.filename(file) fname_no_dots := fname.replace('.', '_') byte_name := '${context.prefix}${fname_no_dots}' fbytes := os.read_bytes(file) or { diff --git a/cmd/tools/vbuild-examples.v b/cmd/tools/vbuild-examples.v index b2a5ac8507..aa61d6cfbd 100644 --- a/cmd/tools/vbuild-examples.v +++ b/cmd/tools/vbuild-examples.v @@ -3,19 +3,18 @@ module main import ( os testing - filepath ) fn main() { args := os.args args_string := args[1..].join(' ') params := args_string.all_before('build-examples') - + if testing.v_build_failing(params, 'examples'){ exit(1) } - if testing.v_build_failing(params + '-live', filepath.join( 'examples', 'hot_reload')){ + if testing.v_build_failing(params + '-live', os.join( 'examples', 'hot_reload')){ exit(1) } diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index 391daaab73..b4db5f9b4a 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -6,7 +6,6 @@ module main import ( os os.cmdline - filepath compiler v.pref v.fmt @@ -40,7 +39,7 @@ const ( fn main() { toolexe := os.executable() - compiler.set_vroot_folder(filepath.dir(filepath.dir(filepath.dir(toolexe)))) + compiler.set_vroot_folder(os.dir(os.dir(os.dir(toolexe)))) args := join_flags_and_argument() foptions := FormatOptions{ is_2: '-2' in args @@ -155,8 +154,8 @@ fn (foptions &FormatOptions) format_file(file string) { table := table.new_table() file_ast := parser.parse_file(file, table, .parse_comments) formatted_content := fmt.fmt(file_ast, table) - file_name := filepath.filename(file) - vfmt_output_path := filepath.join(os.tmpdir(), 'vfmt_' + file_name) + file_name := os.filename(file) + vfmt_output_path := os.join(os.tmpdir(), 'vfmt_' + file_name) os.write_file(vfmt_output_path, formatted_content ) if foptions.is_verbose { eprintln('vfmt2 fmt.fmt worked and ${formatted_content.len} bytes were written to ${vfmt_output_path} .') @@ -180,15 +179,15 @@ fn (foptions &FormatOptions) format_file(file string) { is_test_file := file.ends_with('_test.v') mod_name,is_module_file := file_to_mod_name_and_is_module_file(file) use_tmp_main_program := is_module_file && !is_test_file - mod_folder := filepath.basedir(file) + mod_folder := os.basedir(file) if use_tmp_main_program { // TODO: remove the need for this // This makes a small program that imports the module, // so that the module files will get processed by the // vfmt implementation. - mod_folder_parent = filepath.basedir(mod_folder) + mod_folder_parent = os.basedir(mod_folder) 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 := filepath.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) { os.rm(main_program_file) } @@ -384,7 +383,7 @@ fn get_compile_name_of_potential_v_project(file string) string { // This function get_compile_name_of_potential_v_project returns: // a) the file's folder, if file is part of a v project // b) the file itself, if the file is a standalone v program - pfolder := os.realpath(filepath.dir(file)) + pfolder := os.realpath(os.dir(file)) // a .v project has many 'module main' files in one folder // if there is only one .v file, then it must be a standalone all_files_in_pfolder := os.ls(pfolder) or { @@ -392,7 +391,7 @@ fn get_compile_name_of_potential_v_project(file string) string { } mut vfiles := []string for f in all_files_in_pfolder { - vf := filepath.join(pfolder,f) + vf := os.join(pfolder,f) if f.starts_with('.') || !f.ends_with('.v') || os.is_dir(vf) { continue } diff --git a/cmd/tools/vnames.v b/cmd/tools/vnames.v index 519b2b85de..a66849f033 100644 --- a/cmd/tools/vnames.v +++ b/cmd/tools/vnames.v @@ -4,7 +4,6 @@ import ( os flag strings - filepath compiler v.pref ) @@ -42,7 +41,7 @@ fn analyze_v_file(file string) { for f in v.files { v.parse(f, .decl) } fi := v.get_file_parser_index( file ) or { panic(err) } fmod := v.parsers[fi].mod - + // output: mut fns :=[]string for _, f in v.table.fns { @@ -51,26 +50,26 @@ fn analyze_v_file(file string) { } fns.sort() for f in fns { println(f) } - + } fn main(){ toolexe := os.executable() - compiler.set_vroot_folder(filepath.dir(filepath.dir(filepath.dir(toolexe)))) + compiler.set_vroot_folder(os.dir(os.dir(os.dir(toolexe)))) mut fp := flag.new_flag_parser(os.args) - fp.application(filepath.filename(toolexe)) + fp.application(os.filename(toolexe)) fp.version( tool_version ) fp.description( tool_description ) fp.arguments_description('FILE.v/FOLDER [FILE.v/FOLDER]...') fp.limit_free_args_to_at_least(1) fp.skip_executable() - show_help:=fp.bool_('help', `h`, false, 'Show this help screen\n') + show_help:=fp.bool_('help', `h`, false, 'Show this help screen\n') if( show_help ){ println( fp.usage() ) exit(0) } - + mut files := []string locations := fp.finalize() or { eprintln('Error: ' + err) exit(1) } for xloc in locations { diff --git a/cmd/tools/vpm.v b/cmd/tools/vpm.v index 2ef0a08641..39c0ef9f67 100644 --- a/cmd/tools/vpm.v +++ b/cmd/tools/vpm.v @@ -5,7 +5,6 @@ import ( os os.cmdline json - filepath ) const ( @@ -177,7 +176,7 @@ fn vpm_install(module_names []string) { println('Skipping module "$name", since it uses an unsupported VCS {$vcs} .') continue } - final_module_path := os.realpath(filepath.join(settings.vmodules_path,mod.name.replace('.', filepath.separator))) + final_module_path := os.realpath(os.join(settings.vmodules_path,mod.name.replace('.', os.path_separator))) if os.exists(final_module_path) { vpm_update([name]) continue @@ -278,7 +277,7 @@ fn vpm_remove(module_names []string) { os.rmdir_all(final_module_path) // delete author directory if it is empty author := name.split('.')[0] - author_dir := os.realpath(filepath.join(settings.vmodules_path,author)) + author_dir := os.realpath(os.join(settings.vmodules_path,author)) if os.is_dir_empty(author_dir) { verbose_println('removing author folder $author_dir') os.rmdir(author_dir) @@ -287,7 +286,7 @@ fn vpm_remove(module_names []string) { } fn valid_final_path_of_existing_module(name string) ?string { - name_of_vmodules_folder := filepath.join(settings.vmodules_path,name.replace('.', filepath.separator)) + name_of_vmodules_folder := os.join(settings.vmodules_path,name.replace('.', os.path_separator)) final_module_path := os.realpath(name_of_vmodules_folder) if !os.exists(final_module_path) { println('No module with name "$name" exists at $name_of_vmodules_folder') @@ -326,7 +325,7 @@ fn vpm_help(module_names []string) { fn vcs_used_in_dir(dir string) ?[]string { mut vcs := []string for repo_subfolder in supported_vcs_folders { - checked_folder := os.realpath(filepath.join(dir,repo_subfolder)) + checked_folder := os.realpath(os.join(dir,repo_subfolder)) if os.is_dir(checked_folder) { vcs << repo_subfolder.replace('.', '') } @@ -343,7 +342,7 @@ fn get_installed_modules() []string { } mut modules := []string for dir in dirs { - adir := filepath.join(settings.vmodules_path,dir) + adir := os.join(settings.vmodules_path,dir) if dir in excluded_dirs || !os.is_dir(adir) { continue } @@ -352,7 +351,7 @@ fn get_installed_modules() []string { continue } for m in mods { - vcs_used_in_dir(filepath.join(adir,m)) or { + vcs_used_in_dir(os.join(adir,m)) or { continue } modules << '${author}.$m' @@ -400,7 +399,7 @@ fn get_all_modules() []string { } fn resolve_dependencies(name, module_path string, module_names []string) { - vmod_path := filepath.join(module_path,'v.mod') + vmod_path := os.join(module_path,'v.mod') if !os.exists(vmod_path) { return } diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 5e93edf65d..8be01a858c 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -9,7 +9,6 @@ import ( term readline os.cmdline - filepath ) struct Repl { @@ -78,8 +77,8 @@ pub fn run_repl(workdir string, vrepl_prefix string) []string { println(version) println('Use Ctrl-C or `exit` to exit') - file := filepath.join( workdir, '.${vrepl_prefix}vrepl.v' ) - temp_file := filepath.join( workdir, '.${vrepl_prefix}vrepl_temp.v') + file := os.join( workdir, '.${vrepl_prefix}vrepl.v' ) + temp_file := os.join( workdir, '.${vrepl_prefix}vrepl_temp.v') mut prompt := '>>> ' defer { println('') diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index 381041f4e7..1539e6a1b3 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -2,14 +2,13 @@ module main import ( os - filepath v.pref ) fn main() { println('V Self Compiling...') vexe := pref.vexe_path() - vroot := filepath.dir(vexe) + vroot := os.dir(vexe) os.chdir(vroot) s2 := os.exec('$vexe -o v2 cmd/v') or { panic(err) diff --git a/cmd/tools/vsetup-freetype.v b/cmd/tools/vsetup-freetype.v index 7bed948c47..4e551c78d4 100644 --- a/cmd/tools/vsetup-freetype.v +++ b/cmd/tools/vsetup-freetype.v @@ -2,14 +2,13 @@ module main import ( os - filepath v.pref ) fn main() { $if windows { println('Setup freetype...') - vroot := filepath.dir(pref.vexe_path()) + vroot := os.dir(pref.vexe_path()) os.chdir(vroot) if os.is_dir('./thirdparty/freetype') { diff --git a/cmd/tools/vtest-compiler.v b/cmd/tools/vtest-compiler.v index 8dc22d2002..b066e214b8 100644 --- a/cmd/tools/vtest-compiler.v +++ b/cmd/tools/vtest-compiler.v @@ -4,7 +4,6 @@ import ( os testing benchmark - filepath v.pref ) @@ -20,7 +19,7 @@ fn main() { fn v_test_compiler(vargs string) { vexe := pref.vexe_path() - parent_dir := filepath.dir(vexe) + parent_dir := os.dir(vexe) testing.vlib_should_be_present(parent_dir) // Changing the current directory is needed for some of the compiler tests, // compiler/tests/local_test.v and compiler/tests/repl/repl_test.v @@ -53,7 +52,7 @@ fn v_test_compiler(vargs string) { eprintln('') building_examples_failed := testing.v_build_failing(vargs, 'examples') eprintln('') - building_live_failed := testing.v_build_failing(vargs + '-live', filepath.join('examples','hot_reload')) + building_live_failed := testing.v_build_failing(vargs + '-live', os.join('examples','hot_reload')) eprintln('') v_module_install_cmd := '$vexe install nedpals.args' eprintln('') diff --git a/cmd/tools/vtest.v b/cmd/tools/vtest.v index dee269ad50..33a41597ef 100644 --- a/cmd/tools/vtest.v +++ b/cmd/tools/vtest.v @@ -3,7 +3,6 @@ module main import ( os os.cmdline - filepath testing ) @@ -40,7 +39,7 @@ pub fn main() { } if os.is_dir(targ) { // Fetch all tests from the directory - ts.files << os.walk_ext( targ.trim_right(filepath.separator), '_test.v') + ts.files << os.walk_ext( targ.trim_right(os.path_separator), '_test.v') continue } println('Unrecognized test file $targ .') diff --git a/cmd/tools/vup.v b/cmd/tools/vup.v index d9f06d5f2b..73cc6ba5d2 100644 --- a/cmd/tools/vup.v +++ b/cmd/tools/vup.v @@ -2,13 +2,12 @@ module main import ( os - filepath v.pref ) fn main() { println('Updating V...') - vroot := filepath.dir(pref.vexe_path()) + vroot := os.dir(pref.vexe_path()) os.chdir(vroot) // git pull s := os.exec('git pull --rebase origin master') or { @@ -22,7 +21,7 @@ fn main() { os.rm(v_backup_file) } os.mv('v.exe', v_backup_file) - + s2 := os.exec('make.bat') or { panic(err) } diff --git a/cmd/v/simple_tool.v b/cmd/v/simple_tool.v index fe9e34171e..9df1c68df0 100644 --- a/cmd/v/simple_tool.v +++ b/cmd/v/simple_tool.v @@ -5,14 +5,13 @@ module main import ( compiler - filepath os v.pref ) fn launch_tool(verbosity pref.VerboseLevel, tool_name string) { vexe := pref.vexe_path() - vroot := filepath.dir(vexe) + vroot := os.dir(vexe) compiler.set_vroot_folder(vroot) tool_args := os.args[1..].join(' ') diff --git a/examples/sdl/tvintris/tvintris.v b/examples/sdl/tvintris/tvintris.v index b930936c89..2dc08e601e 100644 --- a/examples/sdl/tvintris/tvintris.v +++ b/examples/sdl/tvintris/tvintris.v @@ -7,7 +7,6 @@ module main -import filepath import rand import time import os @@ -20,7 +19,7 @@ import sdl.ttf as ttf const ( Title = 'tVintris' - BASE = filepath.dir( os.realpath( os.executable() ) ) + BASE = os.dir( os.realpath( os.executable() ) ) FontName = BASE + '/../../assets/fonts/RobotoMono-Regular.ttf' MusicName = BASE + '/sounds/TwintrisThosenine.mod' SndBlockName = BASE + '/sounds/block.wav' diff --git a/vlib/builtin/bare/syscallwrapper_test.v b/vlib/builtin/bare/syscallwrapper_test.v index 4ed8fed8b4..acda48d07a 100644 --- a/vlib/builtin/bare/syscallwrapper_test.v +++ b/vlib/builtin/bare/syscallwrapper_test.v @@ -1,6 +1,5 @@ import ( os - filepath ) fn test_syscallwrappers() { @@ -8,7 +7,7 @@ fn test_syscallwrappers() { $if linux { $if x64 { exe := os.executable() - vdir := filepath.dir(exe) + vdir := os.dir(exe) if vdir.len > 1 { dot_checks := vdir + "/.checks" assert os.is_dir(dot_checks) diff --git a/vlib/compiler/aparser.v b/vlib/compiler/aparser.v index b63ed5f5a6..24135931e1 100644 --- a/vlib/compiler/aparser.v +++ b/vlib/compiler/aparser.v @@ -6,7 +6,6 @@ module compiler import ( os strings - filepath v.pref // compiler.x64 time @@ -177,12 +176,12 @@ fn (v mut V) new_parser_from_file(path string) Parser { } } mut p := v.new_parser(new_scanner_file(path)) - path_dir := os.realpath(filepath.dir(path)) + path_dir := os.realpath(os.dir(path)) p = { p | file_path:path, file_path_dir: path_dir, - file_name:path.all_after(filepath.separator), + file_name:path.all_after(os.path_separator), file_platform:path_platform, file_pcguard:path_pcguard, is_vh:path.ends_with('.vh'), @@ -2487,7 +2486,7 @@ struct IndexConfig { // for debugging only fn (p &Parser) fileis(s string) bool { - return filepath.filename(p.scanner.file_path).contains(s) + return os.filename(p.scanner.file_path).contains(s) } // in and dot have higher priority than `!` diff --git a/vlib/compiler/cc.v b/vlib/compiler/cc.v index 90bfa57fca..f9057e039b 100644 --- a/vlib/compiler/cc.v +++ b/vlib/compiler/cc.v @@ -6,7 +6,6 @@ module compiler import ( os time - filepath v.pref term ) @@ -32,7 +31,7 @@ fn (v mut V) cc() { } v.build_thirdparty_obj_files() vexe := pref.vexe_path() - vdir := filepath.dir(vexe) + vdir := os.dir(vexe) // Just create a C/JavaScript file and exit // for example: `v -o v.c compiler` ends_with_c := v.pref.out_name.ends_with('.c') @@ -153,8 +152,8 @@ fn (v mut V) cc() { } if v.pref.build_mode == .build_module { // Create the modules & out directory if it's not there. - mut out_dir := if v.pref.path.starts_with('vlib') { '$v_modules_path${filepath.separator}cache${filepath.separator}$v.pref.path' } else { '$v_modules_path${filepath.separator}$v.pref.path' } - pdir := out_dir.all_before_last(filepath.separator) + mut out_dir := if v.pref.path.starts_with('vlib') { '$v_modules_path${os.path_separator}cache${os.path_separator}$v.pref.path' } else { '$v_modules_path${os.path_separator}$v.pref.path' } + pdir := out_dir.all_before_last(os.path_separator) if !os.is_dir(pdir) { os.mkdir_all(pdir) } @@ -220,14 +219,14 @@ fn (v mut V) cc() { a << '-c' } else if v.pref.is_cache { - builtin_o_path := filepath.join(v_modules_path,'cache','vlib','builtin.o') + builtin_o_path := os.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.exists(builtin_o_path) { libs = builtin_o_path } else { println('$builtin_o_path not found... building module builtin') - os.system('$vexe build module vlib${filepath.separator}builtin') + os.system('$vexe build module vlib${os.path_separator}builtin') } for imp in v.table.imports { if imp.contains('vweb') { @@ -236,8 +235,8 @@ fn (v mut V) cc() { if imp == 'webview' { continue } - imp_path := imp.replace('.', filepath.separator) - path := '$v_modules_path${filepath.separator}cache${filepath.separator}vlib${filepath.separator}${imp_path}.o' + 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.exists(path) { libs += ' ' + path @@ -254,7 +253,7 @@ fn (v mut V) cc() { } } else { - os.system('$vexe build module vlib${filepath.separator}$imp_path') + os.system('$vexe build module vlib${os.path_separator}$imp_path') } } if path.ends_with('vlib/ui.o') { diff --git a/vlib/compiler/cgen.v b/vlib/compiler/cgen.v index c17d544b4d..37975eeb0d 100644 --- a/vlib/compiler/cgen.v +++ b/vlib/compiler/cgen.v @@ -6,7 +6,6 @@ module compiler import ( os strings - filepath ) struct CGen { @@ -278,14 +277,14 @@ fn (v &V) build_thirdparty_obj_file(path string, moduleflags []CFlag) { return } println('$obj_path not found, building it...') - parent := filepath.dir(obj_path) + parent := os.dir(obj_path) files := os.ls(parent)or{ panic(err) } mut cfiles := '' for file in files { if file.ends_with('.c') { - cfiles += '"' + os.realpath(parent + filepath.separator + file) + '" ' + cfiles += '"' + os.realpath(parent + os.path_separator + file) + '" ' } } btarget := moduleflags.c_options_before_target() diff --git a/vlib/compiler/compile_errors.v b/vlib/compiler/compile_errors.v index ea995a33da..b0af0fd052 100644 --- a/vlib/compiler/compile_errors.v +++ b/vlib/compiler/compile_errors.v @@ -2,7 +2,6 @@ module compiler import ( os - filepath term ) // //////////////////////////////////////////////////////////////////////////////////////////////// @@ -157,7 +156,7 @@ fn (s &Scanner) get_error_filepath() string { else { s.print_rel_paths_on_error}} if use_relative_paths { - workdir := os.getwd() + filepath.separator + workdir := os.getwd() + os.path_separator if s.file_path.starts_with(workdir) { return s.file_path.replace(workdir, '') } diff --git a/vlib/compiler/comptime.v b/vlib/compiler/comptime.v index 16ec766ba5..2c16852db5 100644 --- a/vlib/compiler/comptime.v +++ b/vlib/compiler/comptime.v @@ -7,7 +7,6 @@ import ( vweb.tmpl // for `$vweb_html()` os strings - filepath ) fn (p mut Parser) comp_time() { @@ -198,7 +197,7 @@ fn (p mut Parser) comp_time() { // 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 = filepath.dir(p.scanner.file_path) + '/' + path + path = os.dir(p.scanner.file_path) + '/' + path if !os.exists(path) { p.error('vweb HTML template "$path" not found') } diff --git a/vlib/compiler/gen_x64.v b/vlib/compiler/gen_x64.v index 5c65594aaa..8f0b6f4670 100644 --- a/vlib/compiler/gen_x64.v +++ b/vlib/compiler/gen_x64.v @@ -1,4 +1,3 @@ module compiler -// import filepath +// import os // import compiler.x64 - diff --git a/vlib/compiler/live.v b/vlib/compiler/live.v index 28e1991fb8..b69b5c7c75 100644 --- a/vlib/compiler/live.v +++ b/vlib/compiler/live.v @@ -3,7 +3,6 @@ module compiler import ( os time - filepath ) fn (v &V) generate_hotcode_reloading_compiler_flags() []string { @@ -55,7 +54,7 @@ fn (v &V) generate_hotcode_reloading_main_caller() { // We are in live code reload mode, so start the .so loader in the background mut cgen := v.cgen cgen.genln('') - file_base := filepath.filename(v.pref.path).replace('.v', '') + file_base := os.filename(v.pref.path).replace('.v', '') if v.pref.os != .windows { // unix: so_name := file_base + '.so' @@ -80,7 +79,7 @@ fn (v &V) generate_hot_reload_code() { // Hot code reloading if v.pref.is_live { mut file := os.realpath(v.pref.path) - file_base := filepath.filename(file).replace('.v', '') + file_base := os.filename(file).replace('.v', '') so_name := file_base + '.so' // Need to build .so file before building the live application // The live app needs to load this .so file on initialization. @@ -225,4 +224,3 @@ void reload_so() { cgen.genln(' int load_so(byteptr path) { return 0; }') } } - diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 98ca3d3d20..4783b30828 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -6,7 +6,6 @@ module compiler import ( os strings - filepath v.pref v.builder ) @@ -66,11 +65,11 @@ pub fn new_v(pref &pref.Preferences) &V { mut vgen_buf := strings.new_builder(1000) vgen_buf.writeln('module vgen\nimport strings') - compiled_dir:=if os.is_dir(rdir) { rdir } else { filepath.dir(rdir) } + compiled_dir:=if os.is_dir(rdir) { rdir } else { os.dir(rdir) } return &V{ mod_file_cacher: new_mod_file_cacher() - compiled_dir:compiled_dir// if os.is_dir(rdir) { rdir } else { filepath.dir(rdir) } + compiled_dir:compiled_dir// if os.is_dir(rdir) { rdir } else { os.dir(rdir) } table: new_table(pref.obfuscate) out_name_c: out_name_c cgen: new_cgen(out_name_c) @@ -106,13 +105,13 @@ pub fn (v &V) finalize_compilation() { pub fn (v mut V) add_parser(parser Parser) int { pidx := v.parsers.len v.parsers << parser - file_path := if filepath.is_abs(parser.file_path) { parser.file_path } else { os.realpath(parser.file_path) } + file_path := if os.is_abs(parser.file_path) { parser.file_path } else { os.realpath(parser.file_path) } v.file_parser_idx[file_path] = pidx return pidx } pub fn (v &V) get_file_parser_index(file string) ?int { - file_path := if filepath.is_abs(file) { file } else { os.realpath(file) } + file_path := if os.is_abs(file) { file } else { os.realpath(file) } if file_path in v.file_parser_idx { return v.file_parser_idx[file_path] } @@ -349,7 +348,7 @@ pub fn (v mut V) compile_x64() { println('v -x64 can only generate Linux binaries for now') println('You are not on a Linux system, so you will not ' + 'be able to run the resulting executable') } - //v.files << v.v_files_from_dir(filepath.join(v.pref.vlib_path,'builtin','bare')) + //v.files << v.v_files_from_dir(os.join(v.pref.vlib_path,'builtin','bare')) v.files << v.pref.path v.set_module_lookup_paths() mut b := v.new_v2() @@ -625,7 +624,7 @@ pub fn (v &V) v_files_from_dir(dir string) []string { continue } } - res << filepath.join(dir,file) + res << os.join(dir,file) } return res } @@ -639,7 +638,7 @@ pub fn (v mut V) add_v_files_to_compile() { } // Builtin cache exists? Use it. if v.pref.is_cache { - builtin_vh := filepath.join(v_modules_path,'vlib','builtin.vh') + builtin_vh := os.join(v_modules_path,'vlib','builtin.vh') if os.exists(builtin_vh) { v.cached_mods << 'builtin' builtin_files = [builtin_vh] @@ -690,8 +689,8 @@ pub fn (v mut V) add_v_files_to_compile() { // Cached modules are broken currently /* if v.pref.vpath != '' && v.pref.build_mode != .build_module && !mod.contains('vweb') { - mod_path := mod.replace('.', filepath.separator) - vh_path := '$v_modules_path${filepath.separator}vlib${filepath.separator}${mod_path}.vh' + 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.exists(vh_path) { eprintln('using cached module `$mod`: $vh_path') v.cached_mods << mod @@ -722,16 +721,16 @@ pub fn (v &V) get_builtin_files() []string { // Lookup for built-in folder in lookup path. // Assumption: `builtin/` folder implies usable implementation of builtin for location in v.pref.lookup_path { - if !os.exists(filepath.join(location, 'builtin')) { + if !os.exists(os.join(location, 'builtin')) { continue } if v.pref.is_bare { - return v.v_files_from_dir(filepath.join(location, 'builtin', 'bare')) + return v.v_files_from_dir(os.join(location, 'builtin', 'bare')) } $if js { - return v.v_files_from_dir(filepath.join(location, 'builtin','js')) + return v.v_files_from_dir(os.join(location, 'builtin','js')) } - return v.v_files_from_dir(filepath.join(location, 'builtin')) + return v.v_files_from_dir(os.join(location, 'builtin')) } // Panic. We couldn't find the folder. verror('`builtin/` not included on module lookup path. @@ -748,19 +747,19 @@ pub fn (v &V) get_user_files() []string { mut user_files := []string // See cmd/tools/preludes/README.md for more info about what preludes are - vroot := filepath.dir(pref.vexe_path()) - preludes_path := filepath.join(vroot,'cmd','tools','preludes') + vroot := os.dir(pref.vexe_path()) + preludes_path := os.join(vroot,'cmd','tools','preludes') if v.pref.is_live { - user_files << filepath.join(preludes_path,'live_main.v') + user_files << os.join(preludes_path,'live_main.v') } if v.pref.is_solive { - user_files << filepath.join(preludes_path,'live_shared.v') + user_files << os.join(preludes_path,'live_shared.v') } if v.pref.is_test { - user_files << filepath.join(preludes_path,'tests_assertions.v') + user_files << os.join(preludes_path,'tests_assertions.v') } if v.pref.is_test && v.pref.is_stats { - user_files << filepath.join(preludes_path,'tests_with_stats.v') + user_files << os.join(preludes_path,'tests_with_stats.v') } is_test := dir.ends_with('_test.v') @@ -781,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 .') } user_files << single_test_v_file - dir = filepath.basedir(single_test_v_file) + dir = os.basedir(single_test_v_file) } if dir.ends_with('.v') || dir.ends_with('.vsh') { single_v_file := dir @@ -934,5 +933,5 @@ pub fn set_vroot_folder(vroot_path string) { // VEXE env variable is needed so that compiler.vexe_path() // can return it later to whoever needs it: vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } - os.setenv('VEXE', os.realpath([vroot_path, vname].join(filepath.separator)), true) + os.setenv('VEXE', os.realpath([vroot_path, vname].join(os.path_separator)), true) } diff --git a/vlib/compiler/module_header.v b/vlib/compiler/module_header.v index 44c96e2a42..7c7e338f06 100644 --- a/vlib/compiler/module_header.v +++ b/vlib/compiler/module_header.v @@ -6,7 +6,6 @@ module compiler import ( strings os - filepath v.pref ) /* @@ -29,10 +28,10 @@ mut: fn generate_vh(mod string) { println('\n\n\n\nGenerating a V header file for module `$mod`') vexe := pref.vexe_path() - full_mod_path := filepath.join(filepath.dir(vexe),mod) - dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${filepath.separator}$mod' } else { mod } + full_mod_path := os.join(os.dir(vexe),mod) + dir := if mod.starts_with('vlib') { '$compiler.v_modules_path${os.path_separator}$mod' } else { mod } path := dir + '.vh' - pdir := dir.all_before_last(filepath.separator) + pdir := dir.all_before_last(os.path_separator) if !os.is_dir(pdir) { os.mkdir_all(pdir) // os.mkdir(os.realpath(dir)) or { panic(err) } @@ -50,7 +49,7 @@ fn generate_vh(mod string) { // mut vfiles := os.ls(full_mod_path) or { // exit(1) // } - filtered := vfiles.filter(it.ends_with('.v') && !it.ends_with('test.v') && !it.ends_with('_windows.v') && !it.ends_with('_win.v') && !it.ends_with('_lin.v') && !it.contains('${filepath.separator}examples') && !it.contains('_js.v') && !it.contains('_bare.v') && !it.contains('${filepath.separator}js')) // TODO merge once filter allows it + filtered := vfiles.filter(it.ends_with('.v') && !it.ends_with('test.v') && !it.ends_with('_windows.v') && !it.ends_with('_win.v') && !it.ends_with('_lin.v') && !it.contains('${os.path_separator}examples') && !it.contains('_js.v') && !it.contains('_bare.v') && !it.contains('${os.path_separator}js')) // TODO merge once filter allows it // println('f:') // println(filtered) mut pref := &pref.Preferences { diff --git a/vlib/compiler/modules.v b/vlib/compiler/modules.v index d4b02fe54f..c00e59a786 100644 --- a/vlib/compiler/modules.v +++ b/vlib/compiler/modules.v @@ -4,7 +4,6 @@ module compiler import ( - filepath os v.pref ) @@ -25,7 +24,7 @@ fn (table &Table) qualify_module(mod string, file_path string) string { for m in table.imports { if m.contains('.') && m.contains(mod) { m_parts := m.split('.') - m_path := m_parts.join(filepath.separator) + m_path := m_parts.join(os.path_separator) if mod == m_parts[m_parts.len - 1] && file_path.contains(m_path) { return m } @@ -147,7 +146,7 @@ pub fn (graph &DepGraph) imports() []string { [inline] fn (v &V) module_path(mod string) string { // submodule support - return mod.replace('.', filepath.separator) + return mod.replace('.', os.path_separator) } // 'strings' => 'VROOT/vlib/strings' @@ -168,10 +167,10 @@ fn (v mut V) set_module_lookup_paths() { // 3.2) search in ~/.vmodules/ (i.e. modules installed with vpm) v.module_lookup_paths = [] if v.pref.is_test { - v.module_lookup_paths << filepath.basedir(v.compiled_dir) // pdir of _test.v + v.module_lookup_paths << os.basedir(v.compiled_dir) // pdir of _test.v } v.module_lookup_paths << v.compiled_dir - v.module_lookup_paths << filepath.join(v.compiled_dir,'modules') + v.module_lookup_paths << os.join(v.compiled_dir,'modules') v.module_lookup_paths << v.pref.lookup_path if v.pref.verbosity.is_higher_or_equal(.level_two) { v.log('v.module_lookup_paths: $v.module_lookup_paths') @@ -190,7 +189,7 @@ fn (p mut Parser) find_module_path(mod string) ?string { mod_path := p.v.module_path(mod) for lookup_path in module_lookup_paths { - try_path := filepath.join(lookup_path,mod_path) + try_path := os.join(lookup_path,mod_path) if p.v.pref.verbosity.is_higher_or_equal(.level_three) { println(' >> trying to find $mod in $try_path ...') } diff --git a/vlib/compiler/msvc.v b/vlib/compiler/msvc.v index 5bce7fee7f..eac27859fc 100644 --- a/vlib/compiler/msvc.v +++ b/vlib/compiler/msvc.v @@ -1,9 +1,6 @@ module compiler -import ( - os - filepath -) +import os #flag windows -l shell32 #flag windows -l dbghelp @@ -165,7 +162,7 @@ fn find_msvc() ?MsvcResult { return error('Unable to find visual studio') } return MsvcResult{ - full_cl_exe_path: os.realpath(vs.exe_path + filepath.separator + 'cl.exe') + full_cl_exe_path: os.realpath(vs.exe_path + os.path_separator + 'cl.exe') exe_path: vs.exe_path um_lib_path: wk.um_lib_path ucrt_lib_path: wk.ucrt_lib_path @@ -316,14 +313,14 @@ fn build_thirdparty_obj_file_with_msvc(path string, moduleflags []CFlag) { return } println('$obj_path not found, building it (with msvc)...') - parent := filepath.dir(obj_path) + parent := os.dir(obj_path) files := os.ls(parent)or{ panic(err) } mut cfiles := '' for file in files { if file.ends_with('.c') { - cfiles += '"' + os.realpath(parent + filepath.separator + file) + '" ' + cfiles += '"' + os.realpath(parent + os.path_separator + file) + '" ' } } include_string := '-I "$msvc.ucrt_include_path" -I "$msvc.vs_include_path" -I "$msvc.um_include_path" -I "$msvc.shared_include_path"' @@ -378,7 +375,7 @@ fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags { } else if flag.name == '-L' { lib_paths << flag.value - lib_paths << flag.value + filepath.separator + 'msvc' + lib_paths << flag.value + os.path_separator + 'msvc' // The above allows putting msvc specific .lib files in a subfolder msvc/ , // where gcc will NOT find them, but cl will do... // NB: gcc is smart enough to not need .lib files at all in most cases, the .dll is enough. diff --git a/vlib/compiler/scanner.v b/vlib/compiler/scanner.v index c20597797d..bdb1cea5ac 100644 --- a/vlib/compiler/scanner.v +++ b/vlib/compiler/scanner.v @@ -3,11 +3,7 @@ // that can be found in the LICENSE file. module compiler -import ( - os - filepath - // strings -) +import os const ( single_quote = `\'` @@ -919,7 +915,7 @@ fn (s mut Scanner) debug_tokens() { s.pos = 0 s.started = false s.debug = true - fname := s.file_path.all_after(filepath.separator) + fname := s.file_path.all_after(os.path_separator) println('\n===DEBUG TOKENS $fname===') for { res := s.scan() diff --git a/vlib/compiler/tests/repl/repl_test.v b/vlib/compiler/tests/repl/repl_test.v index 6893095dea..1bfa5ae827 100644 --- a/vlib/compiler/tests/repl/repl_test.v +++ b/vlib/compiler/tests/repl/repl_test.v @@ -4,7 +4,6 @@ import os import compiler.tests.repl.runner import benchmark import sync -import filepath fn test_the_v_compiler_can_be_invoked() { vexec := runner.full_path_to_v(5) @@ -64,7 +63,7 @@ fn worker_repl(p mut sync.PoolProcessor, idx int, thread_id int) voidptr { p.set_thread_context(idx, tls_bench) } tls_bench.cstep = idx - tfolder := filepath.join(cdir,'vrepl_tests_$idx') + tfolder := os.join(cdir,'vrepl_tests_$idx') if os.is_dir(tfolder) { os.rmdir_all(tfolder) } diff --git a/vlib/compiler/tests/repl/runner/runner.v b/vlib/compiler/tests/repl/runner/runner.v index 19f6d3d688..1d2ef1efcb 100644 --- a/vlib/compiler/tests/repl/runner/runner.v +++ b/vlib/compiler/tests/repl/runner/runner.v @@ -1,9 +1,6 @@ module runner -import ( - os - filepath -) +import os pub struct RunnerOptions { pub: @@ -20,9 +17,9 @@ pub fn full_path_to_v(dirs_in int) string { vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } mut path := os.executable() for i := 0; i < dirs_in; i++ { - path = filepath.dir(path) + path = os.dir(path) } - vexec := filepath.join( path, vname ) + vexec := os.join( path, vname ) /* args := os.args vreal := os.realpath('v') @@ -51,17 +48,17 @@ fn diff_files( file_result, file_expected string ) string { } pub fn run_repl_file(wd string, vexec string, file string) ?string { - vexec_folder := filepath.dir(vexec) + filepath.separator + vexec_folder := os.dir(vexec) + os.path_separator fcontent := os.read_file(file) or { return error('Could not read file ${file}') } content := fcontent.replace('\r', '') input := content.all_before('===output===\n') output := content.all_after('===output===\n') - fname := filepath.filename( file ) + fname := os.filename( file ) - input_temporary_filename := os.realpath(filepath.join( wd, 'input_temporary_filename.txt')) + input_temporary_filename := os.realpath(os.join( wd, 'input_temporary_filename.txt')) os.write_file(input_temporary_filename, input) - os.write_file( os.realpath(filepath.join( wd, 'original.txt' ) ), fcontent ) + os.write_file( os.realpath(os.join( wd, 'original.txt' ) ), fcontent ) rcmd := '"$vexec" repl -replfolder "$wd" -replprefix "${fname}." < $input_temporary_filename' r := os.exec(rcmd) or { os.rm(input_temporary_filename) @@ -74,7 +71,7 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string { .replace('>>>', '') .replace('... ', '') .all_after('Use Ctrl-C or `exit` to exit\n') - .replace(wd + filepath.separator, '' ) + .replace(wd + os.path_separator, '' ) .replace(vexec_folder, '') .replace('\\', '/') @@ -137,7 +134,7 @@ pub fn new_options() RunnerOptions { if os.args.len > 1 { files = os.args[1..] } else { - os.chdir( filepath.dir(vexec) ) + os.chdir( os.dir(vexec) ) wd = os.getwd() files = os.walk_ext('.', '.repl') } diff --git a/vlib/compiler/v_mod_cache.v b/vlib/compiler/v_mod_cache.v index f30e63a871..679b756be8 100644 --- a/vlib/compiler/v_mod_cache.v +++ b/vlib/compiler/v_mod_cache.v @@ -1,7 +1,6 @@ module compiler import os -import filepath // This file provides a caching mechanism for seeking quickly whether a @@ -98,13 +97,13 @@ fn (mcache mut ModFileCacher) traverse(mfolder string) ([]string, ModFileAndFold if 'v.mod' in files { // TODO: actually read the v.mod file and parse its contents to see // if its source folder is different - res := ModFileAndFolder{ vmod_file: filepath.join( cfolder, 'v.mod'), vmod_folder: cfolder } + res := ModFileAndFolder{ vmod_file: os.join( cfolder, 'v.mod'), vmod_folder: cfolder } return folders_so_far, res } if mcache.check_for_stop( cfolder, files ) { break } - cfolder = filepath.basedir( cfolder ) + cfolder = os.basedir( cfolder ) folders_so_far << cfolder levels++ } diff --git a/vlib/compiler/vtmp.v b/vlib/compiler/vtmp.v index 79939acc30..ba89b41f67 100644 --- a/vlib/compiler/vtmp.v +++ b/vlib/compiler/vtmp.v @@ -4,10 +4,9 @@ module compiler import os -import filepath fn get_vtmp_folder() string { - vtmp := filepath.join(os.tmpdir(),'v') + vtmp := os.join(os.tmpdir(),'v') if !os.is_dir(vtmp) { os.mkdir(vtmp)or{ panic(err) @@ -18,5 +17,5 @@ fn get_vtmp_folder() string { fn get_vtmp_filename(base_file_name string, postfix string) string { vtmp := get_vtmp_folder() - return os.realpath(filepath.join(vtmp,filepath.filename(os.realpath(base_file_name)) + postfix)) + return os.realpath(os.join(vtmp,os.filename(os.realpath(base_file_name)) + postfix)) } diff --git a/vlib/filepath/filepath.v b/vlib/filepath/filepath.v deleted file mode 100644 index dc9c467797..0000000000 --- a/vlib/filepath/filepath.v +++ /dev/null @@ -1,50 +0,0 @@ -module filepath - -// ext returns the extension in the file `path`. -pub fn ext(path string) string { - pos := path.last_index('.') or { - return '' - } - return path[pos..] -} - -// is_abs returns true if `path` is absolute. -pub fn is_abs(path string) bool { - $if windows { - return path[0] == `/` || // incase we're in MingGW bash - (path[0].is_letter() && path[1] == `:`) - } - return path[0] == `/` -} - -// join returns path as string from string parameter(s). -pub fn join(base string, dirs ...string) string { - mut result := []string - result << base.trim_right('\\/') - for d in dirs { - result << d - } - return result.join(separator) -} - -// dir returns all but the last element of path, typically the path's directory. -pub fn dir(path string) string { - pos := path.last_index(separator) or { - return '.' - } - return path[..pos] -} - -// basedir returns a directory name from path -pub fn basedir(path string) string { - pos := path.last_index(separator) or { - return path - } - // NB: *without* terminating / - return path[..pos] -} - -// filename returns a file name from path -pub fn filename(path string) string { - return path.all_after(separator) -} diff --git a/vlib/filepath/filepath_nix.v b/vlib/filepath/filepath_nix.v deleted file mode 100644 index 29df92856f..0000000000 --- a/vlib/filepath/filepath_nix.v +++ /dev/null @@ -1,5 +0,0 @@ -module filepath - -pub const ( - separator = '/' -) diff --git a/vlib/filepath/filepath_test.v b/vlib/filepath/filepath_test.v deleted file mode 100644 index b4183254f3..0000000000 --- a/vlib/filepath/filepath_test.v +++ /dev/null @@ -1,43 +0,0 @@ -import filepath - -fn test_ext() { - assert filepath.ext('file.v') == '.v' - assert filepath.ext('file') == '' -} - -fn test_is_abs() { - assert filepath.is_abs('/home/user') == true - assert filepath.is_abs('v/vlib') == false - - $if windows { - assert filepath.is_abs('C:\\Windows\\') == true - } -} - -fn test_join() { - $if windows { - assert filepath.join('v', 'vlib', 'filepath') == 'v\\vlib\\filepath' - } $else { - assert filepath.join('v', 'vlib', 'filepath') == 'v/vlib/filepath' - } -} - -fn test_dir() { - $if windows { - assert filepath.dir('C:\\a\\b\\c') == 'C:\\a\\b' - } $else { - assert filepath.dir('/var/tmp/foo') == '/var/tmp' - } - - assert filepath.dir('filepath') == '.' -} - -fn test_basedir() { - $if windows { - assert filepath.basedir('v\\vlib\\filepath') == 'v\\vlib' - } $else { - assert filepath.basedir('v/vlib/filepath') == 'v/vlib' - } - - assert filepath.basedir('filename') == 'filename' -} diff --git a/vlib/filepath/filepath_windows.v b/vlib/filepath/filepath_windows.v deleted file mode 100644 index 997704667e..0000000000 --- a/vlib/filepath/filepath_windows.v +++ /dev/null @@ -1,5 +0,0 @@ -module filepath - -pub const ( - separator = '\\' -) diff --git a/vlib/freetype/freetype.v b/vlib/freetype/freetype.v index 026ab39027..2b3b3961e3 100644 --- a/vlib/freetype/freetype.v +++ b/vlib/freetype/freetype.v @@ -10,7 +10,6 @@ import ( gg glm gl - filepath ) #flag windows -I @VROOT/thirdparty/freetype/include @@ -205,7 +204,7 @@ pub fn new_context(cfg gg.Cfg) &FreeType { } if !os.exists(font_path) { exe_path := os.executable() - exe_dir := filepath.basedir(exe_path) + exe_dir := os.basedir(exe_path) font_path = '$exe_dir/$font_path' } if !os.exists(font_path) { diff --git a/vlib/log/log.v b/vlib/log/log.v index 07a05a31cd..5ee32919d7 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -4,7 +4,6 @@ import ( os time term - filepath ) pub enum LogLevel { @@ -69,8 +68,8 @@ pub fn (l mut Log) set_output_level(level LogLevel) { pub fn (l mut Log) set_full_logpath(full_log_path string) { rlog_file := os.realpath( full_log_path ) - l.set_output_label( filepath.filename( rlog_file ) ) - l.set_output_path( filepath.basedir( rlog_file ) ) + l.set_output_label( os.filename( rlog_file ) ) + l.set_output_path( os.basedir( rlog_file ) ) } pub fn (l mut Log) set_output_label(label string){ @@ -80,7 +79,7 @@ pub fn (l mut Log) set_output_label(label string){ pub fn (l mut Log) set_output_path(output_file_path string) { if l.ofile.is_opened() { l.ofile.close() } l.output_to_file = true - l.output_file_name = filepath.join( os.realpath( output_file_path ) , l.output_label ) + l.output_file_name = os.join( os.realpath( output_file_path ) , l.output_label ) ofile := os.open_append( l.output_file_name ) or { panic('error while opening log file ${l.output_file_name} for appending') } @@ -137,4 +136,3 @@ pub fn (l mut Log) debug(s string) { if l.level < .debug { return } l.send_output(s, .debug) } - diff --git a/vlib/os/os.v b/vlib/os/os.v index 569e1620f1..822b2bb465 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -3,8 +3,6 @@ // that can be found in the LICENSE file. module os -import filepath - #include // #include #include @@ -183,7 +181,7 @@ pub fn cp_all(osource_path, odest_path string, overwrite bool) ?bool { } // single file copy if !os.is_dir(source_path) { - adjasted_path := if os.is_dir(dest_path) { filepath.join(dest_path,filepath.filename(source_path)) } else { dest_path } + adjasted_path := if os.is_dir(dest_path) { os.join(dest_path,os.filename(source_path)) } else { dest_path } if os.exists(adjasted_path) { if overwrite { os.rm(adjasted_path) @@ -204,8 +202,8 @@ pub fn cp_all(osource_path, odest_path string, overwrite bool) ?bool { return error(err) } for file in files { - sp := filepath.join(source_path,file) - dp := filepath.join(dest_path,file) + sp := os.join(source_path,file) + dp := os.join(dest_path,file) if os.is_dir(sp) { os.mkdir(dp) or { panic(err) @@ -634,10 +632,10 @@ pub fn rmdir_all(path string) { return } for item in items { - if os.is_dir(filepath.join(path,item)) { - rmdir_all(filepath.join(path,item)) + if os.is_dir(os.join(path,item)) { + rmdir_all(os.join(path,item)) } - os.rm(filepath.join(path,item)) + os.rm(os.join(path,item)) } os.rmdir(path) } @@ -655,24 +653,30 @@ fn print_c_errno() { println('errno=$e err=$se') } -[deprecated] pub fn ext(path string) string { - panic('Use `filepath.ext` instead of `os.ext`') + pos := path.last_index('.') or { + return '' + } + return path[pos..] } -[deprecated] pub fn dir(path string) string { - panic('Use `filepath.dir` instead of `os.dir`') + pos := path.last_index(path_separator) or { + return '.' + } + return path[..pos] } -[deprecated] pub fn basedir(path string) string { - panic('Use `filepath.basedir` instead of `os.basedir`') + pos := path.last_index(path_separator) or { + return path + } + // NB: *without* terminating / + return path[..pos] } -[deprecated] pub fn filename(path string) string { - panic('Use `filepath.filename` instead of `os.filename`') + return path.all_after(path_separator) } // get_line returns a one-line string from stdin @@ -792,9 +796,9 @@ pub fn user_os() string { // home_dir returns path to user's home directory. pub fn home_dir() string { $if windows { - return os.getenv('USERPROFILE') + filepath.separator + return os.getenv('USERPROFILE') + os.path_separator } $else { - return os.getenv('HOME') + filepath.separator + return os.getenv('HOME') + os.path_separator } } @@ -988,6 +992,25 @@ pub fn realpath(fpath string) string { return string(fullpath) } +// is_abs returns true if `path` is absolute. +pub fn is_abs(path string) bool { + $if windows { + return path[0] == `/` || // incase we're in MingGW bash + (path[0].is_letter() && path[1] == `:`) + } + return path[0] == `/` +} + +// join returns path as string from string parameter(s). +pub fn join(base string, dirs ...string) string { + mut result := []string + result << base.trim_right('\\/') + for d in dirs { + result << d + } + return result.join(path_separator) +} + // walk_ext returns a recursive list of all file paths ending with `ext`. pub fn walk_ext(path, ext string) []string { if !os.is_dir(path) { @@ -997,7 +1020,7 @@ pub fn walk_ext(path, ext string) []string { return [] } mut res := []string - separator := if path.ends_with(filepath.separator) { '' } else { filepath.separator } + separator := if path.ends_with(os.path_separator) { '' } else { os.path_separator } for i, file in files { if file.starts_with('.') { continue @@ -1023,7 +1046,7 @@ pub fn walk(path string, f fn(path string)) { return } for file in files { - p := path + filepath.separator + file + p := path + os.path_separator + file if os.is_dir(p) && !os.is_link(p) { walk(p, f) } @@ -1089,9 +1112,9 @@ pub fn flush() { } pub fn mkdir_all(path string) { - mut p := if path.starts_with(filepath.separator) { filepath.separator } else { '' } - for subdir in path.split(filepath.separator) { - p += subdir + filepath.separator + mut p := if path.starts_with(os.path_separator) { os.path_separator } else { '' } + for subdir in path.split(os.path_separator) { + p += subdir + os.path_separator if !os.is_dir(p) { os.mkdir(p) or { panic(err) @@ -1100,11 +1123,6 @@ pub fn mkdir_all(path string) { } } -[deprecated] -pub fn join(base string, dirs ...string) string { - panic('Use `filepath.join` instead of `os.join`') -} - // cachedir returns the path to a *writable* user specific folder, suitable for writing non-essential data. pub fn cachedir() string { // See: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html @@ -1169,10 +1187,10 @@ pub const ( // It gives a convenient way to access program resources like images, fonts, sounds and so on, // *no matter* how the program was started, and what is the current working directory. pub fn resource_abs_path(path string) string { - mut base_path := os.realpath(filepath.dir(os.executable())) + mut base_path := os.realpath(os.dir(os.executable())) vresource := os.getenv('V_RESOURCE_PATH') if vresource.len != 0 { base_path = vresource } - return os.realpath( filepath.join( base_path, path ) ) + return os.realpath( os.join( base_path, path ) ) } diff --git a/vlib/os/os_nix.v b/vlib/os/os_nix.v index aa75b3959b..0047d51834 100644 --- a/vlib/os/os_nix.v +++ b/vlib/os/os_nix.v @@ -7,10 +7,6 @@ import strings #include pub const ( - /** - * This constant is deprecated. Use `filepath.separator` instead. - * FIXME Remove this separator, as it a part of `filepath` module. - */ path_separator = '/' ) diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 545de2ab8b..e589b6d9bb 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -1,7 +1,4 @@ -import ( - os - filepath -) +import os fn testsuite_begin() { cleanup_leftovers() @@ -134,14 +131,14 @@ fn walk_callback(file string) { if file == '.' || file == '..' { return } - assert file == 'test_walk' + filepath.separator + 'test1' + assert file == 'test_walk' + os.path_separator + 'test1' } fn test_walk() { folder := 'test_walk' os.mkdir(folder) or { panic(err) } - file1 := folder + filepath.separator + 'test1' + file1 := folder + os.path_separator + 'test1' os.write_file(file1,'test-1') @@ -190,7 +187,7 @@ fn test_tmpdir(){ assert t.len > 0 assert os.is_dir(t) - tfile := t + filepath.separator + 'tmpfile.txt' + tfile := t + os.path_separator + 'tmpfile.txt' os.rm(tfile) // just in case @@ -269,7 +266,7 @@ fn test_symlink() { } fn test_is_executable_writable_readable() { - file_name := os.tmpdir() + filepath.separator + 'rwxfile.exe' + file_name := os.tmpdir() + os.path_separator + 'rwxfile.exe' mut f := os.create(file_name) or { eprintln('failed to create file $file_name') @@ -294,6 +291,48 @@ fn test_is_executable_writable_readable() { os.rm(file_name) } +fn test_ext() { + assert os.ext('file.v') == '.v' + assert os.ext('file') == '' +} + +fn test_is_abs() { + assert os.is_abs('/home/user') == true + assert os.is_abs('v/vlib') == false + + $if windows { + assert os.is_abs('C:\\Windows\\') == true + } +} + +fn test_join() { + $if windows { + assert os.join('v', 'vlib', 'os') == 'v\\vlib\\os' + } $else { + assert os.join('v', 'vlib', 'os') == 'v/vlib/os' + } +} + +fn test_dir() { + $if windows { + assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b' + } $else { + assert os.dir('/var/tmp/foo') == '/var/tmp' + } + + assert os.dir('os') == '.' +} + +fn test_basedir() { + $if windows { + assert os.basedir('v\\vlib\\os') == 'v\\vlib' + } $else { + assert os.basedir('v/vlib/os') == 'v/vlib' + } + + assert os.basedir('filename') == 'filename' +} + // this function is called by both test_aaa_setup & test_zzz_cleanup // it ensures that os tests do not polute the filesystem with leftover // files so that they can be run several times in a row. diff --git a/vlib/os/os_windows.v b/vlib/os/os_windows.v index 9a834e637b..c6d1fcc047 100644 --- a/vlib/os/os_windows.v +++ b/vlib/os/os_windows.v @@ -6,10 +6,6 @@ import strings #include pub const ( - /** - * This constant is deprecated. Use `filepath.separator` instead. - * FIXME Remove this separator, as it a part of `filepath` module. - */ path_separator = '\\' ) diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 5087a2e7ab..2231cce68e 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -3,7 +3,6 @@ module builder import ( os time - filepath v.ast v.table v.pref @@ -183,7 +182,7 @@ pub fn (b &Builder) v_files_from_dir(dir string) []string { } */ - res << filepath.join(dir,file) + res << os.join(dir,file) } return res } @@ -201,13 +200,13 @@ pub fn (b &Builder) log(s string) { [inline] fn module_path(mod string) string { // submodule support - return mod.replace('.', filepath.separator) + return mod.replace('.', os.path_separator) } pub fn (b &Builder) find_module_path(mod string) ?string { mod_path := module_path(mod) for search_path in b.module_search_paths { - try_path := filepath.join(search_path,mod_path) + try_path := os.join(search_path,mod_path) if b.pref.verbosity.is_higher_or_equal(.level_three) { println(' >> trying to find $mod in $try_path ..') } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index ff4b8ab591..9ccd8d9752 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -8,7 +8,6 @@ import ( v.table v.token os - filepath ) const ( @@ -920,7 +919,7 @@ pub fn (c mut Checker) error(s string, pos token.Position) { print_backtrace() mut path := c.file.path // Get relative path - workdir := os.getwd() + filepath.separator + workdir := os.getwd() + os.path_separator if path.starts_with(workdir) { path = path.replace(workdir, '') } diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 4bcdd87043..8e42879b3b 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -8,7 +8,6 @@ import ( v.parser v.ast os - filepath ) struct Doc { @@ -27,9 +26,9 @@ pub fn doc(mod string, table &table.Table) string { table: table mod: mod } - vlib_path := filepath.dir(pref.vexe_path()) + '/vlib' - mod_path := mod.replace('.', filepath.separator) - path := filepath.join(vlib_path, mod_path) + vlib_path := os.dir(pref.vexe_path()) + '/vlib' + mod_path := mod.replace('.', os.path_separator) + path := os.join(vlib_path, mod_path) if !os.exists(path) { println('module "$mod" not found') println(path) @@ -46,7 +45,7 @@ pub fn doc(mod string, table &table.Table) string { if file.ends_with('_test.v') || file.ends_with('_windows.v') || file.ends_with('_macos.v') { continue } - file_ast := parser.parse_file(filepath.join(path,file), table, .skip_comments) + file_ast := parser.parse_file(os.join(path,file), table, .skip_comments) d.stmts << file_ast.stmts } d.print_fns() diff --git a/vlib/v/fmt/fmt_test.v b/vlib/v/fmt/fmt_test.v index 36ef0842eb..2292e5cac8 100644 --- a/vlib/v/fmt/fmt_test.v +++ b/vlib/v/fmt/fmt_test.v @@ -2,7 +2,6 @@ import ( os term benchmark - filepath v.fmt v.parser v.table @@ -21,7 +20,7 @@ fn test_fmt() { eprintln('VEXE must be set') exit(error_missing_vexe) } - vroot := filepath.dir(vexe) + vroot := os.dir(vexe) tmpfolder := os.tmpdir() diff_cmd := find_working_diff_command() or { '' @@ -33,7 +32,7 @@ fn test_fmt() { for istep, ipath in input_files { fmt_bench.cstep = istep fmt_bench.step() - ifilename := filepath.filename(ipath) + ifilename := os.filename(ipath) opath := ipath.replace('_input.vv', '_expected.vv') if !os.exists(opath) { fmt_bench.fail() @@ -55,7 +54,7 @@ fn test_fmt() { eprintln('>> sorry, but no working "diff" CLI command can be found') continue } - vfmt_result_file := filepath.join(tmpfolder,'vfmt_run_over_${ifilename}') + vfmt_result_file := os.join(tmpfolder,'vfmt_run_over_${ifilename}') os.write_file(vfmt_result_file, result_ocontent) os.system('$diff_cmd --minimal --text --unified=2 --show-function-line="fn " "$opath" "$vfmt_result_file"') continue diff --git a/vlib/v/fmt/tests/import_multiple_expected.vv b/vlib/v/fmt/tests/import_multiple_expected.vv index be52fff831..aa054cfc47 100644 --- a/vlib/v/fmt/tests/import_multiple_expected.vv +++ b/vlib/v/fmt/tests/import_multiple_expected.vv @@ -1,4 +1,4 @@ import ( - filepath + math os ) diff --git a/vlib/v/fmt/tests/import_multiple_input.vv b/vlib/v/fmt/tests/import_multiple_input.vv index d5b4542a86..5911b4e04f 100644 --- a/vlib/v/fmt/tests/import_multiple_input.vv +++ b/vlib/v/fmt/tests/import_multiple_input.vv @@ -1,2 +1,2 @@ -import filepath +import math import os diff --git a/vlib/v/gen/cgen_test.v b/vlib/v/gen/cgen_test.v index 290408848d..860a320190 100644 --- a/vlib/v/gen/cgen_test.v +++ b/vlib/v/gen/cgen_test.v @@ -1,6 +1,5 @@ import ( os - filepath v.pref v.builder term @@ -13,7 +12,7 @@ const ( fn test_c_files() { println('Running V => C tests') vexe := os.getenv('VEXE') - vroot := filepath.dir(vexe) + vroot := os.dir(vexe) term_ok := term.ok_message('OK') term_fail := term.fail_message('FAIL') for i in 1 .. (nr_tests + 1) { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index ab452f0491..54c2b29957 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -11,7 +11,6 @@ import ( v.pref term os - filepath ) const ( @@ -414,7 +413,7 @@ pub fn (p &Parser) error(s string) { print_backtrace() mut path := p.file_name // Get relative path - workdir := os.getwd() + filepath.separator + workdir := os.getwd() + os.path_separator if path.starts_with(workdir) { path = path.replace(workdir, '') } diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index e02ac281ca..98727c5225 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -3,10 +3,7 @@ // that can be found in the LICENSE file. module pref -import ( - filepath - os -) +import os pub const ( default_module_path = os.home_dir() + '.vmodules' @@ -15,9 +12,9 @@ pub const ( pub fn (p mut Preferences) fill_with_defaults() { if p.vroot == '' { // Location of all vlib files - p.vroot = filepath.dir(vexe_path()) + p.vroot = os.dir(vexe_path()) } - vlib_path := filepath.join(p.vroot, 'vlib') + vlib_path := os.join(p.vroot, 'vlib') if p.lookup_path.len == 0 { p.lookup_path = ['@vlib', '@vmodules'] } @@ -26,14 +23,14 @@ pub fn (p mut Preferences) fill_with_defaults() { } rpath := os.realpath(p.path) if p.out_name == ''{ - filename := filepath.filename(rpath).trim_space() + filename := os.filename(rpath).trim_space() mut base := filename.all_before_last('.') if base == '' { // The file name is just `.v` or `.vsh` or `.*` base = filename } - target_dir := if os.is_dir(rpath) { rpath } else { filepath.dir(rpath) } - p.out_name = filepath.join(target_dir, base) + target_dir := if os.is_dir(rpath) { rpath } else { os.dir(rpath) } + p.out_name = os.join(target_dir, base) if rpath == '$p.vroot/cmd/v' && os.is_dir('vlib/compiler') { // Building V? Use v2, since we can't overwrite a running @@ -44,7 +41,7 @@ pub fn (p mut Preferences) fill_with_defaults() { p.out_name = 'v2' } } - rpath_name := filepath.filename(rpath) + rpath_name := os.filename(rpath) p.building_v = !p.is_repl && (rpath_name == 'v' || rpath_name == 'vfmt.v') if p.os == ._auto { // No OS specifed? Use current system diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 96cf70d92e..9a43f2f144 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -5,9 +5,7 @@ module scanner import ( os - filepath v.token - // strings ) const ( @@ -929,7 +927,7 @@ fn (s mut Scanner) debug_tokens() { s.pos = 0 s.started = false s.debug = true - fname := s.file_path.all_after(filepath.separator) + fname := s.file_path.all_after(os.path_separator) println('\n===DEBUG TOKENS $fname===') for { tok := s.scan() diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index dcb7c11d07..3b67d8e083 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -10,7 +10,6 @@ import ( net.http net.urllib strings - filepath ) pub const ( @@ -331,7 +330,7 @@ fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) { if os.is_dir(file) { ctx.scan_static_directory(directory_path + '/' + file, mount_path + '/' + file) } else if file.contains('.') && ! file.starts_with('.') && ! file.ends_with('.') { - ext := filepath.ext(file) + ext := os.ext(file) // Rudimentary guard against adding files not in mime_types. // Use serve_static directly to add non-standard mime types.