pkgconfig: improve and fix the parser; move to v.pkgconfig (#6695)

pull/6715/head
pancake 2020-10-29 10:57:23 +01:00 committed by GitHub
parent 423044d4d6
commit 367067dfff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 24 deletions

View File

@ -8,7 +8,7 @@ import v.token
import v.pref import v.pref
import v.util import v.util
import v.errors import v.errors
import pkgconfig import v.pkgconfig
const ( const (
max_nr_errors = 300 max_nr_errors = 300

View File

@ -1,6 +1,6 @@
module main module main
import pkgconfig import v.pkgconfig
import os import os
fn main() { fn main() {

View File

@ -37,18 +37,25 @@ pub mut:
modname string modname string
} }
fn (mut pc PkgConfig) filters(s string) []string { fn (mut pc PkgConfig) parse_list(s string) []string {
r := pc.filter(s).split(' ') operators := [ '=', '<', '>', '>=', '<=' ]
r := pc.parse_line(s.replace(',', '')).split(' ')
mut res := []string{} mut res := []string{}
mut skip := false
for a in r { for a in r {
if a != '' { b := a.trim_space()
res << a if skip {
skip = false
} else if b in operators {
skip = true
} else if b != '' {
res << b
} }
} }
return res return res
} }
fn (mut pc PkgConfig) filter(s string) string { fn (mut pc PkgConfig) parse_line(s string) string {
mut r := s.trim_space() mut r := s.trim_space()
for r.contains('\${') { for r.contains('\${') {
tok0 := r.index('\${') or { tok0 := r.index('\${') or {
@ -68,8 +75,8 @@ fn (mut pc PkgConfig) setvar(line string) {
kv := line.trim_space().split('=') kv := line.trim_space().split('=')
if kv.len == 2 { if kv.len == 2 {
k := kv[0] k := kv[0]
v := pc.filter(kv[1]) v := pc.parse_line(kv[1])
pc.vars[k] = pc.filter(v) pc.vars[k] = pc.parse_line(v)
} }
} }
@ -86,7 +93,7 @@ fn (mut pc PkgConfig) parse(file string) bool {
// TODO: use different variable. norecurse have nothing to do with this // TODO: use different variable. norecurse have nothing to do with this
for line in lines { for line in lines {
if line.starts_with('Description: ') { if line.starts_with('Description: ') {
pc.description = pc.filter(line[13..]) pc.description = pc.parse_line(line[13..])
} }
} }
} else { } else {
@ -98,20 +105,20 @@ fn (mut pc PkgConfig) parse(file string) bool {
pc.setvar(line) pc.setvar(line)
continue continue
} }
if line.starts_with('Description: ') { if line.starts_with('Description:') {
pc.description = pc.filter(line[13..]) pc.description = pc.parse_line(line[12..])
} else if line.starts_with('Name: ') { } else if line.starts_with('Name:') {
pc.name = pc.filter(line[6..]) pc.name = pc.parse_line(line[5..])
} else if line.starts_with('Version: ') { } else if line.starts_with('Version:') {
pc.version = pc.filter(line[9..]) pc.version = pc.parse_line(line[8..])
} else if line.starts_with('Requires: ') { } else if line.starts_with('Requires:') {
pc.requires = pc.filters(line[10..]) pc.requires = pc.parse_list(line[9..])
} else if line.starts_with('Cflags: ') { } else if line.starts_with('Cflags:') {
pc.cflags = pc.filters(line[8..]) pc.cflags = pc.parse_list(line[7..])
} else if line.starts_with('Libs: ') { } else if line.starts_with('Libs:') {
pc.libs = pc.filters(line[6..]) pc.libs = pc.parse_list(line[5..])
} else if line.starts_with('Libs.private: ') { } else if line.starts_with('Libs.private:') {
pc.libs_private = pc.filters(line[14..]) pc.libs_private = pc.parse_list(line[13..])
} }
} }
} }