From 8ae736b86894c8b7a7a90d57cda16671316f537d Mon Sep 17 00:00:00 2001 From: David Lesnjak Date: Wed, 5 Jun 2024 13:46:57 +0200 Subject: [PATCH] Update parsing of *.cbuild-gen.yml (#56) - solve problem when define has a value --- internal/cbuild/cbuild.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/cbuild/cbuild.go b/internal/cbuild/cbuild.go index 2a2ab8c..0bbec19 100644 --- a/internal/cbuild/cbuild.go +++ b/internal/cbuild/cbuild.go @@ -8,6 +8,7 @@ package cbuild import ( "errors" + "fmt" "github.com/open-cmsis-pack/generator-bridge/internal/common" "github.com/open-cmsis-pack/generator-bridge/internal/utils" @@ -58,6 +59,10 @@ type CbuildGenIdxType struct { } `yaml:"build-gen-idx"` } +type DefineElement struct { + NameValue map[string]string `yaml:"define,omitempty"` +} + // Sub input file type CbuildGenType struct { BuildGen struct { @@ -86,8 +91,8 @@ type CbuildGenType struct { CPP []string `yaml:"CPP"` Link []string `yaml:"Link"` } `yaml:"misc"` - Define []string `yaml:"define"` - AddPath []string `yaml:"add-path"` + Define []DefineElement `yaml:"define"` + AddPath []string `yaml:"add-path"` OutputDirs struct { Intdir string `yaml:"intdir"` Outdir string `yaml:"outdir"` @@ -160,6 +165,26 @@ type GeneratorImportType struct { Groups []CgenGroupsType `yaml:"groups,omitempty"` } +func (d *DefineElement) UnmarshalYAML(unmarshal func(interface{}) error) error { + var val interface{} + err := unmarshal(&val) + if err != nil { + return err + } + + d.NameValue = make(map[string]string) + if str, ok := val.(string); ok { + d.NameValue[str] = "" + } else if mapData, ok := val.(map[string]interface{}); ok { + for k, v := range mapData { + d.NameValue[k] = fmt.Sprintf("%v", v) + } + } else { + return fmt.Errorf("unexpected data type for DefineElement: %T", val) + } + return nil +} + func Read(name, generatorID string, params *ParamsType) error { return ReadCbuildgenIdx(name, generatorID, params) }