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:')
|
v.log('user_files:')
|
||||||
println(user_files)
|
println(user_files)
|
||||||
}
|
}
|
||||||
|
// To store the import table for user imports
|
||||||
|
mut user_imports := []FileImportTable
|
||||||
// Parse user imports
|
// Parse user imports
|
||||||
for file in user_files {
|
for file in user_files {
|
||||||
mut p := v.new_parser(file, Pass.imports)
|
mut p := v.new_parser(file, Pass.imports)
|
||||||
p.parse()
|
p.parse()
|
||||||
|
user_imports << *p.import_table
|
||||||
}
|
}
|
||||||
|
// To store the import table for lib imports
|
||||||
|
mut lib_imports := []FileImportTable
|
||||||
// Parse lib imports
|
// Parse lib imports
|
||||||
if v.pref.build_mode == .default_mode {
|
if v.pref.build_mode == .default_mode {
|
||||||
for i := 0; i < v.table.imports.len; i++ {
|
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 {
|
for file in vfiles {
|
||||||
mut p := v.new_parser(file, Pass.imports)
|
mut p := v.new_parser(file, Pass.imports)
|
||||||
p.parse()
|
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])
|
pkg := v.module_path(v.table.imports[i])
|
||||||
idir := os.getwd()
|
idir := os.getwd()
|
||||||
mut import_path := '$idir/$pkg'
|
mut import_path := '$idir/$pkg'
|
||||||
if(!os.file_exists(import_path)) {
|
if !os.file_exists(import_path) {
|
||||||
import_path = '$v.lang_dir/vlib/$pkg'
|
import_path = '$v.lang_dir/vlib/$pkg'
|
||||||
}
|
}
|
||||||
vfiles := v.v_files_from_dir(import_path)
|
vfiles := v.v_files_from_dir(import_path)
|
||||||
@ -782,6 +788,7 @@ fn (v mut V) add_user_v_files() {
|
|||||||
for file in vfiles {
|
for file in vfiles {
|
||||||
mut p := v.new_parser(file, Pass.imports)
|
mut p := v.new_parser(file, Pass.imports)
|
||||||
p.parse()
|
p.parse()
|
||||||
|
lib_imports << *p.import_table
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -789,31 +796,42 @@ fn (v mut V) add_user_v_files() {
|
|||||||
v.log('imports:')
|
v.log('imports:')
|
||||||
println(v.table.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
|
// Only now add all combined lib files
|
||||||
for _pkg in v.table.imports {
|
// adding the modules each file imports first
|
||||||
pkg := v.module_path(_pkg)
|
for fit in combined_imports {
|
||||||
idir := os.getwd()
|
for _, mod in fit.imports {
|
||||||
mut module_path := '$idir/$pkg'
|
mod_p := v.module_path(mod)
|
||||||
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
idir := os.getwd()
|
||||||
// TmpPath/vlib
|
mut module_path := '$idir/$mod_p'
|
||||||
// These were generated by vfmt
|
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
||||||
if v.pref.build_mode == .default_mode || v.pref.build_mode == .build {
|
// TmpPath/vlib
|
||||||
module_path = '$ModPath/vlib/$pkg'
|
// 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)) {
|
if !fit.file_path in v.files {
|
||||||
module_path = '$v.lang_dir/vlib/$pkg'
|
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 {
|
fn get_arg(joined_args, arg, def string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user