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

cmd/v: rewrite flags

This commit is contained in:
lutherwenxu
2020-03-07 01:53:29 +08:00
committed by GitHub
parent 522de0871a
commit aab31f4b35
37 changed files with 1087 additions and 464 deletions

View File

@ -142,12 +142,12 @@ pub fn (v mut V) compile() {
}
mut cgen := v.cgen
cgen.genln('// Generated by V')
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
println('all .v files before:')
println(v.files)
}
v.add_v_files_to_compile()
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
println('all .v files:')
println(v.files)
}
@ -303,7 +303,7 @@ pub fn (v mut V) compile() {
v.generate_init()
v.generate_main()
v.generate_hot_reload_code()
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
v.log('flags=')
for flag in v.get_os_cflags() {
println(' * ' + flag.format())
@ -324,7 +324,7 @@ pub fn (v mut V) compile2() {
}
//cgen.genln('// Generated by V')
println('compile2()')
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
println('all .v files before:')
println(v.files)
}
@ -335,7 +335,7 @@ pub fn (v mut V) compile2() {
v.files << v.get_builtin_files()
v.files << v.get_user_files()
v.set_module_lookup_paths()
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
println('all .v files:')
println(v.files)
}
@ -583,7 +583,7 @@ pub fn (v &V) v_files_from_dir(dir string) []string {
mut files := os.ls(dir)or{
panic(err)
}
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
println('v_files_from_dir ("$dir")')
}
files.sort()
@ -645,7 +645,7 @@ pub fn (v mut V) add_v_files_to_compile() {
builtin_files = [builtin_vh]
}
}
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('v.add_v_files_to_compile > builtin_files: $builtin_files')
}
// Parse builtin imports
@ -674,7 +674,7 @@ pub fn (v mut V) add_v_files_to_compile() {
}
// Parse lib imports
v.parse_lib_imports()
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_three) {
v.log('imports:')
println(v.table.imports)
}
@ -687,6 +687,8 @@ pub fn (v mut V) add_v_files_to_compile() {
continue
}
// use cached built module if exists
// Cached modules are broken currently
/*
if v.pref.vpath != '' && v.pref.build_mode != .build_module && !mod.contains('vweb') {
mod_path := mod.replace('.', filepath.separator)
vh_path := '$v_modules_path${filepath.separator}vlib${filepath.separator}${mod_path}.vh'
@ -697,6 +699,7 @@ pub fn (v mut V) add_v_files_to_compile() {
continue
}
}
*/
// standard module
vfiles := v.get_imported_module_files(mod)
for file in vfiles {
@ -716,14 +719,24 @@ pub fn (v mut V) add_v_files_to_compile() {
}
pub fn (v &V) get_builtin_files() []string {
// .vh cache exists? Use it
if v.pref.is_bare {
return v.v_files_from_dir(filepath.join(v.pref.vlib_path,'builtin','bare'))
// Lookup for built-in folder in lookup path.
// Assumption: `builtin/` folder implies usable implementation of builtin
for location in v.pref.lookup_path {
if !os.exists(filepath.join(location, 'builtin')) {
continue
}
if v.pref.is_bare {
return v.v_files_from_dir(filepath.join(location, 'builtin', 'bare'))
}
$if js {
return v.v_files_from_dir(filepath.join(location, 'builtin','js'))
}
return v.v_files_from_dir(filepath.join(location, 'builtin'))
}
$if js {
return v.v_files_from_dir(filepath.join(v.pref.vlib_path,'builtin','js'))
}
return v.v_files_from_dir(filepath.join(v.pref.vlib_path,'builtin'))
// Panic. We couldn't find the folder.
verror('`builtin/` not included on module lookup path.
Did you forget to add vlib to the path? (Use @vlib for default vlib)')
panic('Unreachable code reached.')
}
// get user files
@ -763,7 +776,7 @@ pub fn (v &V) get_user_files() []string {
if is_internal_module_test {
// v volt/slack_test.v: compile all .v files to get the environment
single_test_v_file := os.realpath(dir)
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('> Compiling an internal module _test.v file $single_test_v_file .')
v.log('> That brings in all other ordinary .v files in the same module too .')
}
@ -774,12 +787,12 @@ pub fn (v &V) get_user_files() []string {
single_v_file := dir
// Just compile one file and get parent dir
user_files << single_v_file
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('> just compile one file: "${single_v_file}"')
}
}
else {
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('> add all .v files from directory "${dir}" ...')
}
// Add .v files from the directory being compiled
@ -792,7 +805,7 @@ pub fn (v &V) get_user_files() []string {
println('No input .v files')
exit(1)
}
if v.pref.is_verbose {
if v.pref.verbosity.is_higher_or_equal(.level_two) {
v.log('user_files: $user_files')
}
return user_files
@ -840,7 +853,7 @@ pub fn (v mut V) parse_lib_imports() {
pub fn (v &V) log(s string) {
if !v.pref.is_verbose {
if !v.pref.verbosity.is_higher_or_equal(.level_two) {
return
}
println(s)