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

94 lines
2.1 KiB
V
Raw Normal View History

2020-04-09 16:59:19 +03:00
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module table
2020-04-18 17:29:43 +03:00
import v.cflag
2020-04-09 16:59:19 +03:00
// check if cflag is in table
2020-04-18 17:29:43 +03:00
fn (table &Table) has_cflag(flag cflag.CFlag) bool {
2020-04-09 16:59:19 +03:00
for cf in table.cflags {
2020-04-18 17:29:43 +03:00
if cf.os == flag.os && cf.name == flag.name && cf.value == flag.value {
2020-04-09 16:59:19 +03:00
return true
}
}
return false
}
// parse the flags to (table.cflags) []CFlag
// Note: clean up big time (joe-c)
2020-04-25 18:49:16 +03:00
pub fn (mut table Table) parse_cflag(cflg, mod string, ctimedefines []string) ?bool {
2020-04-09 16:59:19 +03:00
allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L']
2020-04-18 17:29:43 +03:00
flag_orig := cflg.trim_space()
2020-04-23 02:16:58 +03:00
mut flag := flag_orig
2020-04-09 16:59:19 +03:00
if flag == '' {
2020-04-19 00:45:17 +03:00
return none
2020-04-09 16:59:19 +03:00
}
2020-04-23 02:16:58 +03:00
mut fos := ''
mut allowed_os_overrides := ['linux', 'darwin', 'freebsd', 'windows', 'mingw', 'solaris']
2020-04-09 16:59:19 +03:00
allowed_os_overrides << ctimedefines
for os_override in allowed_os_overrides {
if !flag.starts_with(os_override) {
continue
}
pos := flag.index(' ') or {
return none
}
fos = flag[..pos].trim_space()
flag = flag[pos..].trim_space()
}
for {
2020-04-23 02:16:58 +03:00
mut name := ''
mut value := ''
2020-04-09 16:59:19 +03:00
if flag[0] == `-` {
for f in allowed_flags {
i := 1 + f.len
if i <= flag.len && f == flag[1..i] {
name = flag[..i].trim_space()
flag = flag[i..].trim_space()
break
}
}
}
2020-04-23 02:16:58 +03:00
mut index := flag.index(' -') or {
2020-04-09 16:59:19 +03:00
-1
}
for index > -1 {
2020-04-23 02:16:58 +03:00
mut has_next := false
2020-04-09 16:59:19 +03:00
for f in allowed_flags {
i := index + 2 + f.len
if i <= flag.len && f == flag[index + 2..i] {
value = flag[..index + 1].trim_space()
flag = flag[index + 1..].trim_space()
has_next = true
break
}
}
if has_next {
break
}
index = flag.index_after(' -', index + 1)
}
if index == -1 {
value = flag.trim_space()
}
if (name in ['-I', '-l', '-L']) && value == '' {
hint := if name == '-l' { 'library name' } else { 'path' }
return error('bad #flag `$flag_orig`: missing $hint after `$name`')
}
2020-04-18 17:29:43 +03:00
cf := cflag.CFlag{
2020-04-09 16:59:19 +03:00
mod: mod
os: fos
name: name
value: value
}
if !table.has_cflag(cf) {
table.cflags << cf
}
if index == -1 {
break
}
}
return true
}