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

os: merge with filepath

This commit is contained in:
yuyi
2020-03-08 05:26:26 +08:00
committed by GitHub
parent 5e541e1f11
commit 783dee1f48
57 changed files with 249 additions and 361 deletions

View File

@@ -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`')
}

View File

@@ -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

View File

@@ -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() {

View File

@@ -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)
}
}

View File

@@ -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]')

View File

@@ -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) + '"'))
}
// ///////////////////////////////////////////////////////////////////

View File

@@ -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 {

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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('')

View File

@@ -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)

View File

@@ -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') {

View File

@@ -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('')

View File

@@ -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 .')

View File

@@ -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)
}

View File

@@ -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(' ')