mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
filepath: path separator (#3756)
This commit is contained in:
@@ -42,7 +42,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 + os.path_separator + nc)
|
||||
return os.realpath(workdir + filepath.separator + nc)
|
||||
}
|
||||
|
||||
pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string,string) {
|
||||
@@ -73,7 +73,7 @@ pub fn clone_or_pull( remote_git_url string, local_worktree_path string ) {
|
||||
// Clone a fresh
|
||||
scripting.run('git clone --quiet "$remote_git_url" "$local_worktree_path" ')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -111,7 +111,7 @@ pub fn (vgit_context mut VGitContext) compile_oldv_if_needed() {
|
||||
scripting.chdir(vgit_context.workdir)
|
||||
clone_or_pull( vgit_context.v_repo_url, vgit_context.path_v )
|
||||
clone_or_pull( vgit_context.vc_repo_url, vgit_context.path_vc )
|
||||
|
||||
|
||||
scripting.chdir(vgit_context.path_v)
|
||||
scripting.run('git checkout $vgit_context.commit_v')
|
||||
v_commithash,vccommit_before := vgit.prepare_vc_source(vgit_context.path_vc, vgit_context.path_v, vgit_context.commit_v)
|
||||
@@ -131,7 +131,7 @@ pub fn (vgit_context mut VGitContext) compile_oldv_if_needed() {
|
||||
scripting.run(command_for_building_v_from_c_source)
|
||||
build_cmd := command_for_selfbuilding.replace('{SOURCE}', vgit_context.vvlocation)
|
||||
scripting.run(build_cmd)
|
||||
|
||||
|
||||
// At this point, there exists a file vgit_context.vexepath
|
||||
// which should be a valid working V executable.
|
||||
}
|
||||
@@ -141,8 +141,8 @@ pub fn add_common_tool_options<T>(context mut T, fp mut flag.FlagParser) []strin
|
||||
context.workdir = os.realpath(fp.string_('workdir', `w`, tdir, 'A writable base folder. Default: $tdir'))
|
||||
context.v_repo_url = fp.string('vrepo', vgit.remote_v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.')
|
||||
context.vc_repo_url = fp.string('vcrepo', vgit.remote_vc_repo_url, 'The url of the vc repository. You can clone it
|
||||
${flag.SPACE}beforehand, and then just give the local folder
|
||||
${flag.SPACE}path here. That will eliminate the network ops
|
||||
${flag.SPACE}beforehand, and then just give the local folder
|
||||
${flag.SPACE}path here. That will eliminate the network ops
|
||||
${flag.SPACE}done by this tool, which is useful, if you want
|
||||
${flag.SPACE}to script it/run it in a restrictive vps/docker.
|
||||
')
|
||||
@@ -157,11 +157,11 @@ ${flag.SPACE}to script it/run it in a restrictive vps/docker.
|
||||
if context.verbose {
|
||||
scripting.set_verbose(true)
|
||||
}
|
||||
|
||||
|
||||
if os.is_dir(context.v_repo_url) {
|
||||
context.v_repo_url = os.realpath( context.v_repo_url )
|
||||
}
|
||||
|
||||
|
||||
if os.is_dir(context.vc_repo_url) {
|
||||
context.vc_repo_url = os.realpath( context.vc_repo_url )
|
||||
}
|
||||
@@ -173,6 +173,6 @@ ${flag.SPACE}to script it/run it in a restrictive vps/docker.
|
||||
for commit in commits {
|
||||
vgit.validate_commit_exists(commit)
|
||||
}
|
||||
|
||||
|
||||
return commits
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ fn new_context() Context {
|
||||
fn (c Context) compare_versions() {
|
||||
// Input is validated at this point...
|
||||
// Cleanup artifacts from previous runs of this tool:
|
||||
scripting.chdir(c.workdir)
|
||||
scripting.chdir(c.workdir)
|
||||
scripting.run('rm -rf "$c.a" "$c.b" "$c.vc" ')
|
||||
// clone the VC source *just once per comparison*, and reuse it:
|
||||
scripting.run('git clone --quiet "$c.vc_repo_url" "$c.vc" ')
|
||||
@@ -55,7 +55,7 @@ fn (c Context) compare_versions() {
|
||||
if c.vflags.len > 0 {
|
||||
os.setenv('VFLAGS', c.vflags, true)
|
||||
}
|
||||
|
||||
|
||||
// The first is the baseline, against which all the others will be compared.
|
||||
// It is the fastest, since hello_world.v has only a single println in it,
|
||||
mut perf_files := []string
|
||||
@@ -65,7 +65,7 @@ fn (c Context) compare_versions() {
|
||||
'v @DEBUG@ -o source.c examples/hello_world.v',
|
||||
'v -o source.c examples/hello_world.v',
|
||||
])
|
||||
|
||||
|
||||
perf_files << c.compare_v_performance('source_v', [
|
||||
'vprod @DEBUG@ -o source.c @COMPILER@',
|
||||
'vprod -o source.c @COMPILER@',
|
||||
@@ -77,7 +77,7 @@ fn (c Context) compare_versions() {
|
||||
'vprod -o hello examples/hello_world.v',
|
||||
'v -o hello examples/hello_world.v',
|
||||
])
|
||||
|
||||
|
||||
perf_files << c.compare_v_performance('binary_v', [
|
||||
'vprod -o binary @COMPILER@',
|
||||
'v -o binary @COMPILER@',
|
||||
@@ -124,7 +124,7 @@ fn (c &Context) prepare_v(cdir string, commit string) {
|
||||
scripting.show_sizes_of_files(['$cdir/v', '$cdir/v_stripped', '$cdir/v_stripped_upxed'])
|
||||
scripting.show_sizes_of_files(['$cdir/vprod', '$cdir/vprod_stripped', '$cdir/vprod_stripped_upxed'])
|
||||
vversion := scripting.run('$cdir/v --version')
|
||||
vcommit := scripting.run('git rev-parse --short --verify HEAD')
|
||||
vcommit := scripting.run('git rev-parse --short --verify HEAD')
|
||||
println('V version is: ${vversion} , local source commit: ${vcommit}')
|
||||
if vgit_context.vvlocation == 'cmd/v' {
|
||||
println('Source lines of the compiler: ' + scripting.run('wc cmd/v/*.v vlib/compiler/*.v | tail -n -1'))
|
||||
@@ -165,7 +165,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(os.path_separator))
|
||||
cmd_stats_file := os.realpath([c.workdir, 'v_performance_stats_${label}.json'].join(filepath.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 {
|
||||
@@ -207,6 +207,6 @@ ${flag.SPACE}--hyperfine_options "--prepare \'sync; echo 3 | sudo tee /proc/sys/
|
||||
eprintln(msg)
|
||||
exit(2)
|
||||
}
|
||||
|
||||
|
||||
context.compare_versions()
|
||||
}
|
||||
|
||||
@@ -177,7 +177,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('.', os.path_separator)))
|
||||
final_module_path := os.realpath(filepath.join(settings.vmodules_path,mod.name.replace('.', filepath.separator)))
|
||||
if os.exists(final_module_path) {
|
||||
vpm_update([name])
|
||||
continue
|
||||
@@ -287,7 +287,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('.', os.path_separator))
|
||||
name_of_vmodules_folder := filepath.join(settings.vmodules_path,name.replace('.', filepath.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')
|
||||
|
||||
@@ -3,6 +3,7 @@ module main
|
||||
import (
|
||||
os
|
||||
os.cmdline
|
||||
filepath
|
||||
testing
|
||||
)
|
||||
|
||||
@@ -39,7 +40,7 @@ pub fn main() {
|
||||
}
|
||||
if os.is_dir(targ) {
|
||||
// Fetch all tests from the directory
|
||||
ts.files << os.walk_ext( targ.trim_right(os.path_separator), '_test.v')
|
||||
ts.files << os.walk_ext( targ.trim_right(filepath.separator), '_test.v')
|
||||
continue
|
||||
}
|
||||
println('Unrecognized test file $targ .')
|
||||
|
||||
@@ -20,7 +20,7 @@ pub fn new_v(args []string) &compiler.V {
|
||||
os.mkdir(compiler.v_modules_path)or{
|
||||
panic(err)
|
||||
}
|
||||
os.mkdir('$compiler.v_modules_path${os.path_separator}cache')or{
|
||||
os.mkdir('$compiler.v_modules_path${filepath.separator}cache')or{
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -47,10 +47,10 @@ pub fn new_v(args []string) &compiler.V {
|
||||
println('use `v -o v cmd/v` instead of `v -o v v.v`')
|
||||
exit(1)
|
||||
}
|
||||
if dir.ends_with(os.path_separator) {
|
||||
dir = dir.all_before_last(os.path_separator)
|
||||
if dir.ends_with(filepath.separator) {
|
||||
dir = dir.all_before_last(filepath.separator)
|
||||
}
|
||||
if dir.starts_with('.$os.path_separator') {
|
||||
if dir.starts_with('.$filepath.separator') {
|
||||
dir = dir[2..]
|
||||
}
|
||||
if args.len < 2 {
|
||||
@@ -65,8 +65,8 @@ pub fn new_v(args []string) &compiler.V {
|
||||
build_mode = .build_module
|
||||
os.chdir(vroot)
|
||||
// v build module ~/v/os => os.o
|
||||
mod_path := if dir.contains('vlib') { dir.all_after('vlib' + os.path_separator) } else if dir.starts_with('.\\') || dir.starts_with('./') { dir[2..] } else if dir.starts_with(os.path_separator) { dir.all_after(os.path_separator) } else { dir }
|
||||
mod = mod_path.replace(os.path_separator, '.')
|
||||
mod_path := if dir.contains('vlib') { dir.all_after('vlib' + filepath.separator) } else if dir.starts_with('.\\') || dir.starts_with('./') { dir[2..] } else if dir.starts_with(filepath.separator) { dir.all_after(filepath.separator) } else { dir }
|
||||
mod = mod_path.replace(filepath.separator, '.')
|
||||
println('Building module "${mod}" (dir="$dir")...')
|
||||
// out_name = '$TmpPath/vlib/${base}.o'
|
||||
if !out_name.ends_with('.c') {
|
||||
@@ -84,8 +84,8 @@ pub fn new_v(args []string) &compiler.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 out_name.contains(filepath.separator) {
|
||||
d := out_name.all_before_last(filepath.separator)
|
||||
if !os.is_dir(d) {
|
||||
println('creating a new directory "$d"')
|
||||
os.mkdir(d)or{
|
||||
@@ -168,7 +168,7 @@ pub fn new_v(args []string) &compiler.V {
|
||||
pref.fill_with_defaults()
|
||||
|
||||
// v.exe's parent directory should contain vlib
|
||||
if !os.is_dir(pref.vlib_path) || !os.is_dir(pref.vlib_path + os.path_separator + 'builtin') {
|
||||
if !os.is_dir(pref.vlib_path) || !os.is_dir(pref.vlib_path + filepath.separator + 'builtin') {
|
||||
// println('vlib not found, downloading it...')
|
||||
/*
|
||||
ret := os.system('git clone --depth=1 https://github.com/vlang/v .')
|
||||
|
||||
Reference in New Issue
Block a user