tools: distinguish complier args and tool args

pull/3375/head
Contextualist 2020-01-08 11:15:05 -05:00 committed by Alexander Medvednikov
parent 38e5f0d1cf
commit 2a98cacecd
2 changed files with 13 additions and 8 deletions

8
v.v
View File

@ -31,7 +31,7 @@ fn main() {
}
// external tool
if command in simple_tools {
compiler.launch_tool('v' + command)
compiler.launch_tool('v' + command, command)
return
}
// v run, v doc, etc
@ -50,7 +50,7 @@ fn main() {
}
// No args? REPL
else if command == '' || (args.len == 2 && args[1] == '-') {
compiler.launch_tool('vrepl')
compiler.launch_tool('vrepl', '')
return
}
// Construct the V object from command line arguments
@ -100,7 +100,7 @@ fn v_command(command string, args []string) {
println('Translating C to V will be available in V 0.3 (January)')
}
'search', 'install', 'update', 'remove' {
compiler.launch_tool('vpm')
compiler.launch_tool('vpm', command)
}
'get' {
println('use `v install` to install modules from vpm.vlang.io ')
@ -109,7 +109,7 @@ fn v_command(command string, args []string) {
compiler.create_symlink()
}
'runrepl' {
compiler.launch_tool('vrepl')
compiler.launch_tool('vrepl', 'runrepl')
}
'doc' {
vexe := os.executable()

View File

@ -5,11 +5,16 @@ import (
filepath
)
pub fn launch_tool(tname string) {
pub fn launch_tool(tname string, cmdname string) {
is_verbose := '-verbose' in os.args || '--verbose' in os.args
vexe := vexe_path()
vroot := filepath.dir(vexe)
set_vroot_folder( vroot ) // needed by tools to find back v
mut tname_index := os.args.index(cmdname)
if tname_index == -1 {
tname_index = os.args.len
}
mut compilation_options := os.args[1..tname_index].clone()
tool_args := os.args[1..].join(' ')
tool_exe := os.realpath('$vroot/tools/$tname')
tool_source := os.realpath('$vroot/tools/${tname}.v')
@ -41,9 +46,9 @@ pub fn launch_tool(tname string) {
}
if tool_should_be_recompiled {
mut compilation_options := ''
if tname == 'vfmt' { compilation_options = '-d vfmt' }
compilation_command := '"$vexe" $compilation_options "$tool_source"'
if tname == 'vfmt' { compilation_options << ['-d', 'vfmt'] }
compilation_args := compilation_options.join(' ')
compilation_command := '"$vexe" $compilation_args "$tool_source"'
if is_verbose {
eprintln('Compiling $tname with: "$compilation_command"')
}