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

builder: skip warnings; pref: move pref creation to pref.v

This commit is contained in:
Alexander Medvednikov
2020-05-16 22:45:38 +02:00
parent 3e4d99a0e3
commit 0845b2cfbe
5 changed files with 186 additions and 171 deletions

169
cmd/v/v.v
View File

@ -5,7 +5,6 @@ module main
import help
import os
import os.cmdline
import v.table
import v.doc
import v.pref
@ -21,10 +20,6 @@ const (
'build-examples', 'build-vbinaries', 'setup-freetype'
]
list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags']
list_of_flags_with_param = [
'o'
'output', 'd', 'define', 'b', 'backend', 'cc', 'os', 'target-os', 'arch', 'csource'
'cf', 'cflags', 'path']
)
fn main() {
@ -49,7 +44,7 @@ fn main_v() {
return
}
args_and_flags := util.join_env_vflags_and_os_args()[1..]
prefs, command := parse_args(args_and_flags)
prefs, command := pref.parse_args(args_and_flags)
if prefs.is_verbose {
println('command = "$command"')
println(util.full_v_version())
@ -115,168 +110,6 @@ fn main_v() {
exit(1)
}
fn parse_args(args []string) (&pref.Preferences, string) {
mut res := &pref.Preferences{}
mut command := ''
mut command_pos := 0
// for i, arg in args {
for i := 0; i < args.len; i++ {
arg := args[i]
current_args := args[i..]
match arg {
'-v' {
res.is_verbose = true
}
'-silent' {
res.output_mode = .silent
}
'-cg' {
res.is_debug = true
}
'-repl' {
res.is_repl = true
}
'-live' {
res.is_livemain = true
}
'-sharedlive' {
res.is_liveshared = true
res.is_shared = true
}
'-shared' {
res.is_shared = true
}
'--enable-globals' {
res.enable_globals = true
}
'-autofree' {
res.autofree = true
}
'-compress' {
res.compress = true
}
'-freestanding' {
res.is_bare = true
}
'-prof', '-profile' {
res.profile_file = cmdline.option(current_args, '-profile', '-')
res.is_prof = true
i++
}
'-profile-no-inline' {
res.profile_no_inline = true
}
'-prod' {
res.is_prod = true
}
'-stats' {
res.is_stats = true
}
'-obfuscate' {
res.obfuscate = true
}
'-translated' {
res.translated = true
}
'-showcc' {
res.show_cc = true
}
'-usecache' {
res.use_cache = true
}
'-keepc' {
res.keep_c = true
}
'-x64' {
res.backend = .x64
}
'-print_v_files' {
res.print_v_files = true
}
'-os' {
target_os := cmdline.option(current_args, '-os', '')
i++
target_os_kind := pref.os_from_string(target_os) or {
if target_os == 'cross' {
res.output_cross_c = true
continue
}
println('unknown operating system target `$target_os`')
exit(1)
}
res.os = target_os_kind
}
'-printfn' {
res.printfn_list << cmdline.option(current_args, '-printfn', '')
i++
}
'-cflags' {
res.cflags += ' ' + cmdline.option(current_args, '-cflags', '')
i++
}
'-define', '-d' {
if current_args.len > 1 {
define := current_args[1]
parse_define(mut res, define)
}
i++
}
'-cc' {
res.ccompiler = cmdline.option(current_args, '-cc', 'cc')
i++
}
'-o' {
res.out_name = cmdline.option(current_args, '-o', '')
i++
}
'-b' {
b := pref.backend_from_string(cmdline.option(current_args, '-b', 'c')) or {
continue
}
res.backend = b
i++
}
else {
mut should_continue := false
for flag_with_param in list_of_flags_with_param {
if '-$flag_with_param' == arg {
should_continue = true
i++
break
}
}
if should_continue {
continue
}
if !arg.starts_with('-') && command == '' {
command = arg
command_pos = i
}
}
}
}
if command.ends_with('.v') || os.exists(command) {
res.path = command
} else if command == 'run' {
res.is_run = true
if command_pos > args.len {
eprintln('v run: no v files listed')
exit(1)
}
res.path = args[command_pos + 1]
res.run_args = args[command_pos + 2..]
}
if command == 'build-module' {
res.build_mode = .build_module
res.path = args[command_pos + 1]
}
if res.is_verbose {
println('setting pref.path to "$res.path"')
}
res.fill_with_defaults()
return res, command
}
fn invoke_help_and_exit(remaining []string) {
match remaining.len {
0, 1 { help.print_and_exit('default') }