ast: fix bug in parsing `-Isomething -Danother` from #flag and #pkgconfig directives

pull/12859/head
Delyan Angelov 2021-12-15 17:55:52 +02:00
parent 65f12f3217
commit 2b981b011e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 6 additions and 1 deletions

View File

@ -18,7 +18,7 @@ fn (t &Table) has_cflag(flag cflag.CFlag) bool {
// parse the flags to (ast.cflags) []CFlag
// Note: clean up big time (joe-c)
pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) ?bool {
allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L']
allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L', 'D']
flag_orig := cflg.trim_space()
mut flag := flag_orig
if flag == '' {

View File

@ -20,6 +20,10 @@ fn test_parse_valid_cflags() {
make_flag('windows', '-l', 'gdi32'),
make_flag(no_os, '-l', 'mysqlclient'),
make_flag(no_os, no_name, '-test'),
make_flag('linux', '-I', '/usr/include/SDL2'),
make_flag('linux', '-D', '_REENTRANT'),
make_flag('linux', '-L', '/usr/lib/x86_64-linux-gnu'),
make_flag('linux', '-l', 'SDL2'),
]
parse_valid_flag(mut t, '-lmysqlclient')
parse_valid_flag(mut t, '-test')
@ -29,6 +33,7 @@ fn test_parse_valid_cflags() {
parse_valid_flag(mut t, 'mingw -mwindows')
parse_valid_flag(mut t, 'solaris -L/opt/local/lib')
parse_valid_flag(mut t, 'windows -lgdi32')
parse_valid_flag(mut t, 'linux -I/usr/include/SDL2 -D_REENTRANT -L/usr/lib/x86_64-linux-gnu -lSDL2')
assert t.cflags.len == expected_flags.len
for f in expected_flags {
assert t.has_cflag(f)