Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend parser implementation and tests #21

Merged
merged 1 commit into from
Jan 26, 2024
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
2 changes: 1 addition & 1 deletion cmd/cbuild2cmake/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestCommands(t *testing.T) {
assert.Equal(log.ErrorLevel, log.GetLevel())
})

t.Run("test debug debug level", func(t *testing.T) {
t.Run("test debug level", func(t *testing.T) {
cmd := commands.NewRootCmd()
cmd.SetArgs([]string{"--debug", "--version"})
err := cmd.Execute()
Expand Down
4 changes: 2 additions & 2 deletions pkg/maker/contextlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
func (m *Maker) CreateContextCMakeLists(index int, cbuild *Cbuild) error {

outDir := path.Join(cbuild.BaseDir, cbuild.BuildDescType.OutputDirs.Outdir)
intDir := path.Join(m.CbuildIndex.BaseDir, "tmp")
objDir := path.Join(intDir, strconv.Itoa(index))
intDir := path.Join(cbuild.BaseDir, cbuild.BuildDescType.OutputDirs.Intdir)
objDir := path.Join(m.SolutionIntDir, strconv.Itoa(index))

var outputFile, outputType string
for _, output := range cbuild.BuildDescType.Output {
Expand Down
4 changes: 4 additions & 0 deletions pkg/maker/maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package maker

import (
"path"

semver "github.com/Masterminds/semver/v3"
utils "github.com/Open-CMSIS-Pack/cbuild/v2/pkg/utils"
)
Expand All @@ -33,6 +35,7 @@ type Vars struct {
RegisteredToolchains map[*semver.Version]Toolchain
SelectedToolchainVersion *semver.Version
SelectedToolchainConfig string
SolutionIntDir string
}

type Maker struct {
Expand All @@ -57,6 +60,7 @@ func (m *Maker) GenerateCMakeLists() error {
}

// Create super project CMakeLists.txt
m.SolutionIntDir = path.Join(m.CbuildIndex.BaseDir, "tmp")
err = m.CreateSuperCMakeLists()
if err != nil {
return err
Expand Down
38 changes: 38 additions & 0 deletions pkg/maker/maker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package maker_test

import (
"testing"

"github.com/Open-CMSIS-Pack/cbuild2cmake/pkg/inittest"
"github.com/Open-CMSIS-Pack/cbuild2cmake/pkg/maker"
"github.com/stretchr/testify/assert"
)

const testRoot = "../../test"

func init() {
inittest.TestInitialization(testRoot)
}

func TestMaker(t *testing.T) {
assert := assert.New(t)
var m maker.Maker

t.Run("test maker", func(t *testing.T) {
m.Params.InputFile = testRoot + "/run/generic/solutionName1.cbuild-idx.yml"
err := m.GenerateCMakeLists()
assert.Nil(err)
})

t.Run("test maker with invalid input param", func(t *testing.T) {
m.Params.InputFile = testRoot + "invalid.cbuild-idx.yml"
err := m.GenerateCMakeLists()
assert.Error(err)
})
}
158 changes: 127 additions & 31 deletions pkg/maker/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,19 @@ import (

type CbuildIndex struct {
BuildIdx struct {
GeneratedBy string `yaml:"generated-by"`
Cdefault string `yaml:"cdefault"`
Csolution string `yaml:"csolution"`
Cprojects []struct {
Cproject string `yaml:"cproject"`
} `yaml:"cprojects"`
Licenses interface{} `yaml:"licenses"`
Cbuilds []struct {
Cbuild string `yaml:"cbuild"`
Project string `json:"project"`
Configuration string `json:"configuration"`
} `yaml:"cbuilds"`
GeneratedBy string `yaml:"generated-by"`
Cdefault string `yaml:"cdefault"`
Csolution string `yaml:"csolution"`
Cprojects []Cprojects `yaml:"cprojects"`
Cbuilds []Cbuilds `yaml:"cbuilds"`
} `yaml:"build-idx"`
BaseDir string
}

type Cbuild struct {
BuildDescType struct {
GeneratedBy string `yaml:"generated-by"`
CurrentGenerator []struct{} `yaml:"current-generator"`
CurrentGenerator struct{} `yaml:"current-generator"`
Solution string `yaml:"solution"`
Project string `yaml:"project"`
Context string `yaml:"context"`
Expand All @@ -46,33 +39,136 @@ type Cbuild struct {
BoardPack string `yaml:"board-pack"`
Device string `yaml:"device"`
DevicePack string `yaml:"device-pack"`
Processor struct{} `yaml:"processor"`
Packs []struct{} `yaml:"packs"`
Processor Processor `yaml:"processor"`
Packs []Packs `yaml:"packs"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
Misc struct{} `yaml:"misc"`
Misc Misc `yaml:"misc"`
Define []interface{} `yaml:"define"`
AddPath []string `yaml:"add-path"`
OutputDirs struct {
Intdir string `yaml:"intdir"`
Outdir string `yaml:"outdir"`
Cprjdir string `yaml:"cprjdir"`
} `yaml:"output-dirs"`
Output []struct {
File string `yaml:"file"`
Type string `yaml:"type"`
} `yaml:"output"`
Components []struct{} `yaml:"components"`
Linker struct{} `yaml:"linker"`
Groups []struct{} `yaml:"groups"`
Generators []struct{} `yaml:"generators"`
ConstructedFiles []struct{} `yaml:"constructed-files"`
Licenses []struct{} `yaml:"licenses"`
OutputDirs OutputDirs `yaml:"output-dirs"`
Output []Output `yaml:"output"`
Components []Components `yaml:"components"`
Linker Linker `yaml:"linker"`
Groups []Groups `yaml:"groups"`
Generators []struct{} `yaml:"generators"`
ConstructedFiles []Files `yaml:"constructed-files"`
Licenses []struct{} `yaml:"licenses"`
} `yaml:"build"`
BaseDir string
}

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

type Clayers struct {
Clayer string `yaml:"clayer"`
}

type Cprojects struct {
Cproject string `yaml:"cproject"`
Clayers []Clayers `yaml:"clayers"`
}

type Components struct {
Component string `yaml:"component"`
Condition string `yaml:"condition"`
SelectedBy string `yaml:"selected-by"`
Rtedir string `yaml:"rtedir"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
LanguageC string `yaml:"language-C"`
LanguageCPP string `yaml:"language-CPP"`
Define []interface{} `yaml:"define"`
Undefine []string `yaml:"undefine"`
AddPath []string `yaml:"add-path"`
DelPath []string `yaml:"del-path"`
Misc Misc `yaml:"misc"`
Files []Files `yaml:"files"`
Generator Generator `yaml:"generator"`
FromPack string `yaml:"from-pack"`
}

type Files struct {
File string `yaml:"file"`
Category string `yaml:"category"`
Attr string `yaml:"attr"`
Version string `yaml:"version"`
Optimize string `yaml:"optimize"`
Debug string `yaml:"debug"`
Warnings string `yaml:"warnings"`
LanguageC string `yaml:"language-C"`
LanguageCPP string `yaml:"language-CPP"`
Define []interface{} `yaml:"define"`
Undefine []string `yaml:"undefine"`
AddPath []string `yaml:"add-path"`
DelPath []string `yaml:"del-path"`
Misc Misc `yaml:"misc"`
}

type Generator struct {
ID string `yaml:"id"`
Path string `yaml:"path"`
FromPack string `yaml:"from-pack"`
Files []Files `yaml:"files"`
}

type Groups struct {
Group string `yaml:"group"`
Files []Files `yaml:"files"`
}

type Linker struct {
Regions string `yaml:"regions"`
Script string `yaml:"script"`
Define []interface{} `yaml:"define"`
}

type Misc struct {
C []string `yaml:"C"`
CPP []string `yaml:"CPP"`
CCPP []string `yaml:"C-CPP"`
ASM []string `yaml:"ASM"`
Link []string `yaml:"Link"`
LinkC []string `yaml:"Link-C"`
LinkCPP []string `yaml:"Link-CPP"`
Library []string `yaml:"Library"`
Lib []string `yaml:"Lib"`
}

type OutputDirs struct {
Intdir string `yaml:"intdir"`
Outdir string `yaml:"outdir"`
Cprjdir string `yaml:"cprjdir"`
Rtedir string `yaml:"rtedir"`
}

type Output struct {
File string `yaml:"file"`
Type string `yaml:"type"`
}

type Processor struct {
Fpu string `yaml:"fpu"`
Dsp string `yaml:"dsp"`
Mve string `yaml:"mve"`
Endian string `yaml:"endian"`
Trustzone string `yaml:"trustzone"`
BranchProtection string `yaml:"branch-protection"`
Core string `yaml:"core"`
}

type Packs struct {
Pack string `yaml:"pack"`
Path string `yaml:"path"`
}

func (m *Maker) ParseCbuildIndexFile(cbuildIndexFile string) (data CbuildIndex, err error) {
yfile, err := os.ReadFile(cbuildIndexFile)
if err != nil {
Expand Down
Loading
Loading