compiler: restore ability to pass -prod option to run and runrepl. (#3095)

pull/3097/head
Delyan Angelov 2019-12-15 12:21:37 +02:00 committed by joe-conigliaro
parent f2c40bf49d
commit faa04c586f
2 changed files with 24 additions and 6 deletions

7
v.v
View File

@ -23,12 +23,7 @@ fn main() {
//defer { println(time.ticks() - t) } //defer { println(time.ticks() - t) }
// There's no `flags` module yet, so args have to be parsed manually // There's no `flags` module yet, so args have to be parsed manually
args := compiler.env_vflags_and_os_args() args := compiler.env_vflags_and_os_args()
options := args.filter(it.starts_with('-')) options, command := compiler.get_v_options_and_main_command( args )
//NB: commands should be explicitly set by the command line (os.args)
// NOT passed through VFLAGS, otherwise the naked `v` invocation for
// the repl does not work when you have VFLAGS with -cc or -cflags set
// which may be surprising to v users.
command := if os.args.len > 1 { os.args[1] } else { '' }
// external tool // external tool
if command in simple_tools { if command in simple_tools {
compiler.launch_tool('v' + command) compiler.launch_tool('v' + command)

View File

@ -0,0 +1,23 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module compiler
pub fn get_v_options_and_main_command(args []string) ([]string,string) {
mut options := []string
mut potential_commands := []string
for i := 0; i < args.len; i++ {
a := args[i]
if !a.starts_with('-') {
potential_commands << a
continue
}else{
options << a
if a in ['-o', '-os', '-cc', '-cflags'] { i++ }
}
}
// potential_commands[0] is always the executable itself, so ignore it
command := if potential_commands.len > 1 { potential_commands[1] } else { '' }
return options, command
}