mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Fix modules order
This commit is contained in:
parent
382f85fa39
commit
b3bdcfda42
@ -750,11 +750,16 @@ fn (v mut V) add_user_v_files() {
|
||||
v.log('user_files:')
|
||||
println(user_files)
|
||||
}
|
||||
// To store the import table for user imports
|
||||
mut user_imports := []FileImportTable
|
||||
// Parse user imports
|
||||
for file in user_files {
|
||||
mut p := v.new_parser(file, Pass.imports)
|
||||
p.parse()
|
||||
user_imports << *p.import_table
|
||||
}
|
||||
// To store the import table for lib imports
|
||||
mut lib_imports := []FileImportTable
|
||||
// Parse lib imports
|
||||
if v.pref.build_mode == .default_mode {
|
||||
for i := 0; i < v.table.imports.len; i++ {
|
||||
@ -764,6 +769,7 @@ fn (v mut V) add_user_v_files() {
|
||||
for file in vfiles {
|
||||
mut p := v.new_parser(file, Pass.imports)
|
||||
p.parse()
|
||||
lib_imports << *p.import_table
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -774,7 +780,7 @@ fn (v mut V) add_user_v_files() {
|
||||
pkg := v.module_path(v.table.imports[i])
|
||||
idir := os.getwd()
|
||||
mut import_path := '$idir/$pkg'
|
||||
if(!os.file_exists(import_path)) {
|
||||
if !os.file_exists(import_path) {
|
||||
import_path = '$v.lang_dir/vlib/$pkg'
|
||||
}
|
||||
vfiles := v.v_files_from_dir(import_path)
|
||||
@ -782,6 +788,7 @@ fn (v mut V) add_user_v_files() {
|
||||
for file in vfiles {
|
||||
mut p := v.new_parser(file, Pass.imports)
|
||||
p.parse()
|
||||
lib_imports << *p.import_table
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -789,31 +796,42 @@ fn (v mut V) add_user_v_files() {
|
||||
v.log('imports:')
|
||||
println(v.table.imports)
|
||||
}
|
||||
// this order is important for declaration
|
||||
mut combined_imports := []FileImportTable
|
||||
for i := lib_imports.len-1; i>=0; i-- {
|
||||
combined_imports << lib_imports[i]
|
||||
}
|
||||
for i in user_imports {
|
||||
combined_imports << i
|
||||
}
|
||||
// Only now add all combined lib files
|
||||
for _pkg in v.table.imports {
|
||||
pkg := v.module_path(_pkg)
|
||||
idir := os.getwd()
|
||||
mut module_path := '$idir/$pkg'
|
||||
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
||||
// TmpPath/vlib
|
||||
// These were generated by vfmt
|
||||
if v.pref.build_mode == .default_mode || v.pref.build_mode == .build {
|
||||
module_path = '$ModPath/vlib/$pkg'
|
||||
// adding the modules each file imports first
|
||||
for fit in combined_imports {
|
||||
for _, mod in fit.imports {
|
||||
mod_p := v.module_path(mod)
|
||||
idir := os.getwd()
|
||||
mut module_path := '$idir/$mod_p'
|
||||
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
||||
// TmpPath/vlib
|
||||
// These were generated by vfmt
|
||||
if v.pref.build_mode == .default_mode || v.pref.build_mode == .build {
|
||||
module_path = '$ModPath/vlib/$mod_p'
|
||||
}
|
||||
if !os.file_exists(module_path) {
|
||||
module_path = '$v.lang_dir/vlib/$mod_p'
|
||||
}
|
||||
vfiles := v.v_files_from_dir(module_path)
|
||||
for file in vfiles {
|
||||
if !file in v.files {
|
||||
v.files << file
|
||||
}
|
||||
}
|
||||
// TODO v.files.append_array(vfiles)
|
||||
}
|
||||
if(!os.file_exists(module_path)) {
|
||||
module_path = '$v.lang_dir/vlib/$pkg'
|
||||
if !fit.file_path in v.files {
|
||||
v.files << fit.file_path
|
||||
}
|
||||
vfiles := v.v_files_from_dir(module_path)
|
||||
for vfile in vfiles {
|
||||
v.files << vfile
|
||||
}
|
||||
// TODO v.files.append_array(vfiles)
|
||||
}
|
||||
// Add user code last
|
||||
for file in user_files {
|
||||
v.files << file
|
||||
}
|
||||
// v.files.append_array(user_files)
|
||||
}
|
||||
|
||||
fn get_arg(joined_args, arg, def string) string {
|
||||
|
Loading…
Reference in New Issue
Block a user