parser: support @VROOT in #include too, make it use absolute paths
parent
75b8822f06
commit
1d78914a8f
|
@ -3,6 +3,7 @@
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module parser
|
module parser
|
||||||
|
|
||||||
|
import os
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
import v.pref
|
||||||
import v.vmod
|
import v.vmod
|
||||||
|
@ -13,9 +14,20 @@ const (
|
||||||
'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos']
|
'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fn (mut p Parser)resolve_vroot(flag string) string {
|
||||||
|
vmod_file_location := vmod.mod_file_cacher.get_by_folder(p.file_name_dir)
|
||||||
|
if vmod_file_location.vmod_file.len == 0 {
|
||||||
|
// There was no actual v.mod file found.
|
||||||
|
p.error('To use @VROOT, you need' + ' to have a "v.mod" file in ${p.file_name_dir},' +
|
||||||
|
' or in one of its parent folders.')
|
||||||
|
}
|
||||||
|
vmod_path := vmod_file_location.vmod_folder
|
||||||
|
return flag.replace('@VROOT', os.real_path(vmod_path))
|
||||||
|
}
|
||||||
|
|
||||||
// // #include, #flag, #v
|
// // #include, #flag, #v
|
||||||
fn (mut p Parser) hash() ast.HashStmt {
|
fn (mut p Parser) hash() ast.HashStmt {
|
||||||
val := p.tok.lit
|
mut val := p.tok.lit
|
||||||
p.next()
|
p.next()
|
||||||
if p.pref.backend == .js {
|
if p.pref.backend == .js {
|
||||||
if !p.file_name.ends_with('.js.v') {
|
if !p.file_name.ends_with('.js.v') {
|
||||||
|
@ -25,18 +37,19 @@ fn (mut p Parser) hash() ast.HashStmt {
|
||||||
p.error('Hash statements are not allowed in the main module. Please place them in a separate module.')
|
p.error('Hash statements are not allowed in the main module. Please place them in a separate module.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if val.starts_with('include') {
|
||||||
|
mut flag := val[8..]
|
||||||
|
if flag.contains('@VROOT') {
|
||||||
|
vroot := p.resolve_vroot(flag)
|
||||||
|
val = 'include $vroot'
|
||||||
|
}
|
||||||
|
}
|
||||||
if val.starts_with('flag') {
|
if val.starts_with('flag') {
|
||||||
// #flag linux -lm
|
// #flag linux -lm
|
||||||
mut flag := val[5..]
|
mut flag := val[5..]
|
||||||
// expand `@VROOT` to its absolute path
|
// expand `@VROOT` to its absolute path
|
||||||
if flag.contains('@VROOT') {
|
if flag.contains('@VROOT') {
|
||||||
vmod_file_location := vmod.mod_file_cacher.get_by_folder(p.file_name_dir)
|
flag = p.resolve_vroot(flag)
|
||||||
if vmod_file_location.vmod_file.len == 0 {
|
|
||||||
// There was no actual v.mod file found.
|
|
||||||
p.error('To use @VROOT, you need' + ' to have a "v.mod" file in ${p.file_name_dir},' +
|
|
||||||
' or in one of its parent folders.')
|
|
||||||
}
|
|
||||||
flag = flag.replace('@VROOT', vmod_file_location.vmod_folder)
|
|
||||||
}
|
}
|
||||||
for deprecated in ['@VMOD', '@VMODULE', '@VPATH', '@VLIB_PATH'] {
|
for deprecated in ['@VMOD', '@VMODULE', '@VPATH', '@VLIB_PATH'] {
|
||||||
if flag.contains(deprecated) {
|
if flag.contains(deprecated) {
|
||||||
|
|
Loading…
Reference in New Issue