aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-kconf/parser.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-15 14:57:17 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-21 14:22:40 +0100
commit62431cd12bc6a652a965e965c8e06f61d8d6b522 (patch)
tree1fbd589b2c111338e2eabb2d99249f259fa5c91d /tools/syz-kconf/parser.go
parent5de4ef6cb71a4a07492ab0f28b0bb35cb6ab2e21 (diff)
tools/syz-kconf: support appending string values
This will be needed for CMDLINE: common + per-arch + per-kernel.
Diffstat (limited to 'tools/syz-kconf/parser.go')
-rw-r--r--tools/syz-kconf/parser.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/tools/syz-kconf/parser.go b/tools/syz-kconf/parser.go
index dad090b8a..fa926ca6d 100644
--- a/tools/syz-kconf/parser.go
+++ b/tools/syz-kconf/parser.go
@@ -27,7 +27,6 @@ type Instance struct {
type Config struct {
Name string
Value string
- Override bool
Optional bool
Constraints []string
File string
@@ -48,10 +47,6 @@ type Features map[string]bool
func (features Features) Match(constraints []string) bool {
for _, feat := range constraints {
- switch feat {
- case featOptional, featOverride, featWeak:
- continue
- }
if feat[0] == '-' {
if features[feat[1:]] {
return false
@@ -188,26 +183,38 @@ func mergeConfig(inst *Instance, file string, node yaml.Node, errs *Errors) {
File: file,
Line: node.Line,
}
+ override, appendVal := false, false
for _, feat := range constraints {
switch feat {
case featOverride:
- cfg.Override = true
+ override = true
case featOptional:
cfg.Optional = true
case featWeak:
- cfg.Override, cfg.Optional = true, true
+ override, cfg.Optional = true, true
+ case featAppend:
+ override, appendVal = true, true
default:
cfg.Constraints = append(cfg.Constraints, feat)
}
}
if prev := inst.ConfigMap[name]; prev != nil {
- if !cfg.Override {
+ if !override {
errs.push("%v:%v: %v is already defined at %v:%v", file, node.Line, name, prev.File, prev.Line)
}
- *prev = *cfg
+ if appendVal {
+ a, b := prev.Value, cfg.Value
+ if a == "" || a[len(a)-1] != '"' || b == "" || b[0] != '"' {
+ errs.push("%v:%v: bad values to append, want non-empty strings", file, node.Line)
+ return
+ }
+ prev.Value = a[:len(a)-1] + " " + b[1:]
+ } else {
+ *prev = *cfg
+ }
return
}
- if cfg.Override && !cfg.Optional {
+ if override && !cfg.Optional {
errs.push("%v:%v: %v nothing to override", file, node.Line, name)
}
inst.ConfigMap[name] = cfg