Skip to content

Commit

Permalink
Update parsing of *.cbuild-gen.yml (#56)
Browse files Browse the repository at this point in the history
- solve problem when define has a value
  • Loading branch information
DavidLesnjak authored Jun 5, 2024
1 parent 7a4a87f commit 8ae736b
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions internal/cbuild/cbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8ae736b

Please sign in to comment.