Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/cbuild2cmake/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Arm Limited. All rights reserved.
* Copyright (c) 2024-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -94,12 +94,14 @@ func NewRootCmd() *cobra.Command {
debug, _ := cmd.Flags().GetBool("debug")
verbose, _ := cmd.Flags().GetBool("verbose")
useContextSet, _ := cmd.Flags().GetBool("context-set")
zephyr, _ := cmd.Flags().GetBool("zephyr")

options := maker.Options{
Quiet: quiet,
Debug: debug,
Verbose: verbose,
UseContextSet: useContextSet,
Zephyr: zephyr,
}

configs, _ := utils.GetInstallConfigs()
Expand Down Expand Up @@ -134,6 +136,7 @@ func NewRootCmd() *cobra.Command {
rootCmd.Flags().BoolP("debug", "d", false, "Enable debug messages")
rootCmd.Flags().BoolP("verbose", "v", false, "Enable verbose messages from toolchain builds")
rootCmd.Flags().BoolP("context-set", "S", false, "Select the context names from cbuild-set.yml")
rootCmd.Flags().BoolP("zephyr", "z", false, "Generate Zephyr modules for clayer.yml files")

rootCmd.SetFlagErrorFunc(FlagErrorFunc)
return rootCmd
Expand Down
7 changes: 7 additions & 0 deletions pkg/maker/buildcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ func GetScope(file Files) string {
}

func ReplaceDelimiters(identifier string) string {
// replace component delimiters
pattern := regexp.MustCompile(`::|:|&|@>=|@|\.|/|\(|\)| `)
return pattern.ReplaceAllString(identifier, "_")
}

func ReplaceSpecialChars(identifier string) string {
// replace component delimiters and dash '-'
pattern := regexp.MustCompile(`::|:|&|@>=|@|\.|/|\(|\)|-| `)
return pattern.ReplaceAllString(identifier, "_")
}

func MergeLanguageCommonIncludes(languages LanguageMap) LanguageMap {
intersection := utils.Intersection(languages["C"], languages["CXX"])
if len(intersection) > 0 {
Expand Down
13 changes: 13 additions & 0 deletions pkg/maker/buildcontent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ func TestReplaceDelimiters(t *testing.T) {
})
}

func TestReplaceSpecialChars(t *testing.T) {
assert := assert.New(t)

t.Run("test replace special chars", func(t *testing.T) {
assert.Equal("Cvendor_Cbundle_Cclass_Cgroup_Cvariant_Cversion", maker.ReplaceSpecialChars("Cvendor&Cbundle::Cclass:Cgroup&Cvariant@Cversion"))
assert.Equal("ARM_CMSIS_CORE_A", maker.ReplaceSpecialChars("ARM::CMSIS.CORE A"))
assert.Equal("AC6_6_16_0", maker.ReplaceSpecialChars("AC6@>=6.16.0"))
assert.Equal("path_with_spaces", maker.ReplaceSpecialChars("path/with spaces"))
assert.Equal("Handlers__GCC_", maker.ReplaceSpecialChars("Handlers (GCC)"))
assert.Equal("name_with_dash", maker.ReplaceSpecialChars("name-with-dash"))
})
}

func TestBuildContent(t *testing.T) {
assert := assert.New(t)

Expand Down
10 changes: 9 additions & 1 deletion pkg/maker/maker.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024-2025 Arm Limited. All rights reserved.
* Copyright (c) 2024-2026 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -26,12 +26,14 @@ type Options struct {
Debug bool
Verbose bool
UseContextSet bool
Zephyr bool
}

type Vars struct {
CbuildIndex CbuildIndex
CbuildSet CbuildSet
Cbuilds []Cbuild
Clayers []Clayer
Contexts []string
EnvVars utils.EnvVars
GeneratedFiles []string
Expand All @@ -42,6 +44,7 @@ type Vars struct {
SolutionTmpDir string
SolutionRoot string
SolutionName string
ZephyrMaker ZephyrMaker
}

type Maker struct {
Expand Down Expand Up @@ -69,6 +72,11 @@ func (m *Maker) GenerateCMakeLists() error {
}
m.SolutionTmpDir = path.Join(m.CbuildIndex.BaseDir, m.CbuildIndex.BuildIdx.TmpDir)

// Create Zephyr modules
if m.Options.Zephyr {
return m.GenerateZephyrModules()
}

// Create roots.cmake
err = m.CMakeCreateRoots(m.SolutionRoot)
if err != nil {
Expand Down
59 changes: 54 additions & 5 deletions pkg/maker/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"regexp"
"slices"
"strings"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -92,12 +93,27 @@ type Cbuild struct {
LinkerLto bool
}

type Clayer struct {
Layer struct {
Description string `yaml:"description"`
Packs []Packs `yaml:"packs"`
Define []interface{} `yaml:"define"`
Components []struct {
Component string `yaml:"component"`
} `yaml:"components"`
} `yaml:"layer"`
Name string
File string
BaseDir string
}

type Cbuilds struct {
Cbuild string `yaml:"cbuild"`
Project string `yaml:"project"`
Configuration string `yaml:"configuration"`
DependsOn []string `yaml:"depends-on"`
West bool `yaml:"west"`
Cbuild string `yaml:"cbuild"`
Project string `yaml:"project"`
Configuration string `yaml:"configuration"`
DependsOn []string `yaml:"depends-on"`
Clayers []Clayers `yaml:"clayers"`
West bool `yaml:"west"`
}

type Clayers struct {
Expand Down Expand Up @@ -338,3 +354,36 @@ func (m *Maker) ParseCbuildFiles() error {
}
return err
}

func (m *Maker) ParseClayerFile(clayerFile string) (data Clayer, err error) {
yfile, err := os.ReadFile(clayerFile)
if err != nil {
return
}
err = yaml.Unmarshal(yfile, &data)
return
}

func (m *Maker) ParseClayerFiles() error {
// Parse clayer files
if len(m.CbuildIndex.BuildIdx.Cbuilds) > 0 {
m.Clayers = make([]Clayer, 0, len(m.CbuildIndex.BuildIdx.Cbuilds[0].Clayers))
for _, clayerRef := range m.CbuildIndex.BuildIdx.Cbuilds[0].Clayers {
clayerFile := path.Join(m.CbuildIndex.BaseDir, clayerRef.Clayer)
if _, err := os.Stat(clayerFile); os.IsNotExist(err) {
log.Warn("file " + clayerFile + " was not found")
continue
}
clayer, err := m.ParseClayerFile(clayerFile)
if err != nil {
return err
}
clayer.File = filepath.ToSlash(clayerFile)
clayer.BaseDir, _ = filepath.Abs(path.Dir(clayerFile))
clayer.BaseDir = filepath.ToSlash(clayer.BaseDir)
clayer.Name = strings.TrimSuffix(filepath.Base(clayerFile), ".clayer.yml")
m.Clayers = append(m.Clayers, clayer)
}
}
Comment thread
brondani marked this conversation as resolved.
return nil
}
Loading
Loading