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

simplify cflag parsing

This commit is contained in:
joe-conigliaro 2019-12-15 14:18:14 +11:00 committed by Alexander Medvednikov
parent be60193588
commit 717740cfcf
4 changed files with 16 additions and 27 deletions

View File

@ -74,6 +74,7 @@ fn (table mut Table) parse_cflag(cflag string, mod string) ?bool {
allowed_flags := [ allowed_flags := [
'framework', 'framework',
'library', 'library',
'Wl',
'I', 'l', 'L', 'I', 'l', 'L',
] ]
flag_orig := cflag.trim_space() flag_orig := cflag.trim_space()
@ -82,14 +83,13 @@ fn (table mut Table) parse_cflag(cflag string, mod string) ?bool {
return true return true
} }
mut fos := '' mut fos := ''
mut name := ''
if flag.starts_with('linux') || flag.starts_with('darwin') || flag.starts_with('freebsd') || flag.starts_with('windows') { if flag.starts_with('linux') || flag.starts_with('darwin') || flag.starts_with('freebsd') || flag.starts_with('windows') {
pos := flag.index(' ') or { return none } pos := flag.index(' ') or { return none }
fos = flag[..pos].trim_space() fos = flag[..pos].trim_space()
flag = flag[pos..].trim_space() flag = flag[pos..].trim_space()
} }
for { for {
mut index := -1 mut name := ''
mut value := '' mut value := ''
if flag[0] == `-` { if flag[0] == `-` {
for f in allowed_flags { for f in allowed_flags {
@ -101,34 +101,23 @@ fn (table mut Table) parse_cflag(cflag string, mod string) ?bool {
} }
} }
} }
if i := flag.index(' ') { mut index := flag.index(' -') or { -1 }
if index == -1 || i < index { for index > -1 {
index = i mut has_next := false
}
}
if i := flag.index(',') {
if index == -1 || i < index {
index = i
}
}
if index != -1 && flag[index] == ` ` && flag[index+1] == `-` {
for f in allowed_flags { for f in allowed_flags {
j := index+f.len i := index+2+f.len
if j < flag.len && f == flag[index..j] { if i <= flag.len && f == flag[index+2..i] {
index = j value = flag[..index+1].trim_space()
flag = flag[index+1..].trim_space()
has_next = true
break break
} }
} }
value = flag[..index].trim_space() if has_next { break }
flag = flag[index..].trim_space() index = flag.index_after(' -', index+1)
} }
else if index != -1 && index < flag.len-2 && flag[index] == `,` { if index == -1 {
value = flag[..index].trim_space()
flag = flag[index+1..].trim_space()
}
else {
value = flag.trim_space() value = flag.trim_space()
index = -1
} }
if (name in ['-I', '-l', '-L']) && value == '' { if (name in ['-I', '-l', '-L']) && value == '' {
hint := if name == '-l' { 'library name' } else { 'path' } hint := if name == '-l' { 'library name' } else { 'path' }

View File

@ -18,7 +18,7 @@ import (
#flag darwin -I/usr/local/include/freetype2 #flag darwin -I/usr/local/include/freetype2
#flag darwin -I/opt/local/include/freetype2 #flag darwin -I/opt/local/include/freetype2
#flag freebsd -I/usr/local/include/freetype2 #flag freebsd -I/usr/local/include/freetype2
#flag freebsd -Wl,-L/usr/local/lib #flag freebsd -Wl -L/usr/local/lib
#flag -lfreetype #flag -lfreetype
//#flag -I @VROOT/thirdparty/freetype //#flag -I @VROOT/thirdparty/freetype

View File

@ -5,7 +5,7 @@
module http module http
#flag windows -I @VROOT/thirdparty/vschannel #flag windows -I @VROOT/thirdparty/vschannel
#flag -l ws2_32, crypt32, secur32 #flag -l ws2_32 -l crypt32 -l secur32
#include "vschannel.c" #include "vschannel.c"

View File

@ -2,7 +2,7 @@ module sqlite
#flag -lsqlite3 #flag -lsqlite3
#flag freebsd -I/usr/local/include #flag freebsd -I/usr/local/include
#flag freebsd -Wl,-L/usr/local/lib,-lsqlite3 #flag freebsd -Wl -L/usr/local/lib -lsqlite3
#include "sqlite3.h" #include "sqlite3.h"
struct C.sqlite3 struct C.sqlite3