mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v symlink: extract to cmd/tools/vsymlink.v , use setx on windows
This commit is contained in:
parent
b4eadb9030
commit
7585483c69
36
cmd/tools/vsymlink.v
Normal file
36
cmd/tools/vsymlink.v
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import os
|
||||||
|
import v.pref
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
vexe := pref.vexe_path()
|
||||||
|
$if windows {
|
||||||
|
vdir := os.real_path(os.dir(vexe))
|
||||||
|
res := os.system('setx /M PATH "$vdir;%PATH%"')
|
||||||
|
if res == 0 {
|
||||||
|
println('v has been prepended to the path')
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
//
|
||||||
|
mut link_path := '/usr/local/bin/v'
|
||||||
|
mut ret := os.exec('ln -sf $vexe $link_path') or {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if ret.exit_code == 0 {
|
||||||
|
println('Symlink "$link_path" has been created')
|
||||||
|
} else if os.system("uname -o | grep -q \'[A/a]ndroid\'") == 0 {
|
||||||
|
println('Failed to create symlink "$link_path". Trying again with Termux path for Android.')
|
||||||
|
link_path = '/data/data/com.termux/files/usr/bin/v'
|
||||||
|
ret = os.exec('ln -sf $vexe $link_path') or {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if ret.exit_code == 0 {
|
||||||
|
println('Symlink "$link_path" has been created')
|
||||||
|
} else {
|
||||||
|
println('Failed to create symlink "$link_path". Try again with sudo.')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println('Failed to create symlink "$link_path". Try again with sudo.')
|
||||||
|
}
|
||||||
|
}
|
58
cmd/v/v.v
58
cmd/v/v.v
@ -12,12 +12,14 @@ import v.util
|
|||||||
import v.builder
|
import v.builder
|
||||||
|
|
||||||
const (
|
const (
|
||||||
simple_cmd = ['fmt', 'up'
|
simple_cmd = [
|
||||||
'self', 'test'
|
'fmt', 'up',
|
||||||
'test-fmt', 'test-compiler', 'test-fixed', 'bin2v'
|
'self', 'symlink', 'bin2v',
|
||||||
'repl'
|
'test', 'test-fmt', 'test-compiler', 'test-fixed',
|
||||||
'build-tools'
|
'repl',
|
||||||
'build-examples', 'build-vbinaries', 'setup-freetype'
|
'build-tools', 'build-examples',
|
||||||
|
'build-vbinaries',
|
||||||
|
'setup-freetype'
|
||||||
]
|
]
|
||||||
list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags']
|
list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags']
|
||||||
)
|
)
|
||||||
@ -39,10 +41,10 @@ fn main_v() {
|
|||||||
}
|
}
|
||||||
args_and_flags := util.join_env_vflags_and_os_args()[1..]
|
args_and_flags := util.join_env_vflags_and_os_args()[1..]
|
||||||
prefs, command := pref.parse_args(args_and_flags)
|
prefs, command := pref.parse_args(args_and_flags)
|
||||||
//if prefs.is_verbose {
|
// if prefs.is_verbose {
|
||||||
//println('command = "$command"')
|
// println('command = "$command"')
|
||||||
//println(util.full_v_version(prefs.is_verbose))
|
// println(util.full_v_version(prefs.is_verbose))
|
||||||
//}
|
// }
|
||||||
if args.len > 0 && (args[0] in ['version', '-V', '-version', '--version'] || (args[0] ==
|
if args.len > 0 && (args[0] in ['version', '-V', '-version', '--version'] || (args[0] ==
|
||||||
'-v' && args.len == 1)) {
|
'-v' && args.len == 1)) {
|
||||||
// `-v` flag is for setting verbosity, but without any args it prints the version, like Clang
|
// `-v` flag is for setting verbosity, but without any args it prints the version, like Clang
|
||||||
@ -86,16 +88,11 @@ fn main_v() {
|
|||||||
println(util.full_v_version(prefs.is_verbose))
|
println(util.full_v_version(prefs.is_verbose))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
'symlink' {
|
|
||||||
create_symlink()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
'doc' {
|
'doc' {
|
||||||
mut mod := ''
|
mut mod := ''
|
||||||
if args.len == 1 {
|
if args.len == 1 {
|
||||||
println('v doc [module]')
|
println('v doc [module]')
|
||||||
}
|
} else if args.len > 1 {
|
||||||
else if args.len > 1 {
|
|
||||||
mod = args[1]
|
mod = args[1]
|
||||||
}
|
}
|
||||||
table := table.new_table()
|
table := table.new_table()
|
||||||
@ -124,32 +121,3 @@ fn invoke_help_and_exit(remaining []string) {
|
|||||||
println('For usage information, use `v help`.')
|
println('For usage information, use `v help`.')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_symlink() {
|
|
||||||
$if windows {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
vexe := pref.vexe_path()
|
|
||||||
mut link_path := '/usr/local/bin/v'
|
|
||||||
mut ret := os.exec('ln -sf $vexe $link_path') or {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if ret.exit_code == 0 {
|
|
||||||
println('Symlink "$link_path" has been created')
|
|
||||||
} else if os.system("uname -o | grep -q \'[A/a]ndroid\'") == 0 {
|
|
||||||
println('Failed to create symlink "$link_path". Trying again with Termux path for Android.')
|
|
||||||
link_path = '/data/data/com.termux/files/usr/bin/v'
|
|
||||||
ret = os.exec('ln -sf $vexe $link_path') or {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if ret.exit_code == 0 {
|
|
||||||
println('Symlink "$link_path" has been created')
|
|
||||||
} else {
|
|
||||||
println('Failed to create symlink "$link_path". Try again with sudo.')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println('Failed to create symlink "$link_path". Try again with sudo.')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user