@@ -12,6 +12,7 @@ import (
1212 "path/filepath"
1313 "regexp"
1414 "slices"
15+ "strings"
1516
1617 "gopkg.in/yaml.v3"
1718
@@ -92,12 +93,27 @@ type Cbuild struct {
9293 LinkerLto bool
9394}
9495
96+ type Clayer struct {
97+ Layer struct {
98+ Description string `yaml:"description"`
99+ Packs []Packs `yaml:"packs"`
100+ Define []interface {} `yaml:"define"`
101+ Components []struct {
102+ Component string `yaml:"component"`
103+ } `yaml:"components"`
104+ } `yaml:"layer"`
105+ Name string
106+ File string
107+ BaseDir string
108+ }
109+
95110type Cbuilds struct {
96- Cbuild string `yaml:"cbuild"`
97- Project string `yaml:"project"`
98- Configuration string `yaml:"configuration"`
99- DependsOn []string `yaml:"depends-on"`
100- West bool `yaml:"west"`
111+ Cbuild string `yaml:"cbuild"`
112+ Project string `yaml:"project"`
113+ Configuration string `yaml:"configuration"`
114+ DependsOn []string `yaml:"depends-on"`
115+ Clayers []Clayers `yaml:"clayers"`
116+ West bool `yaml:"west"`
101117}
102118
103119type Clayers struct {
@@ -338,3 +354,36 @@ func (m *Maker) ParseCbuildFiles() error {
338354 }
339355 return err
340356}
357+
358+ func (m * Maker ) ParseClayerFile (clayerFile string ) (data Clayer , err error ) {
359+ yfile , err := os .ReadFile (clayerFile )
360+ if err != nil {
361+ return
362+ }
363+ err = yaml .Unmarshal (yfile , & data )
364+ return
365+ }
366+
367+ func (m * Maker ) ParseClayerFiles () error {
368+ // Parse clayer files
369+ if len (m .CbuildIndex .BuildIdx .Cbuilds ) > 0 {
370+ m .Clayers = make ([]Clayer , 0 , len (m .CbuildIndex .BuildIdx .Cbuilds [0 ].Clayers ))
371+ for _ , clayerRef := range m .CbuildIndex .BuildIdx .Cbuilds [0 ].Clayers {
372+ clayerFile := path .Join (m .CbuildIndex .BaseDir , clayerRef .Clayer )
373+ if _ , err := os .Stat (clayerFile ); os .IsNotExist (err ) {
374+ log .Warn ("file " + clayerFile + " was not found" )
375+ continue
376+ }
377+ clayer , err := m .ParseClayerFile (clayerFile )
378+ if err != nil {
379+ return err
380+ }
381+ clayer .File = filepath .ToSlash (clayerFile )
382+ clayer .BaseDir , _ = filepath .Abs (path .Dir (clayerFile ))
383+ clayer .BaseDir = filepath .ToSlash (clayer .BaseDir )
384+ clayer .Name = strings .TrimSuffix (filepath .Base (clayerFile ), ".clayer.yml" )
385+ m .Clayers = append (m .Clayers , clayer )
386+ }
387+ }
388+ return nil
389+ }
0 commit comments