Skip to content

Commit

Permalink
Use forward slash as separator after path relativize
Browse files Browse the repository at this point in the history
  • Loading branch information
brondani authored Apr 3, 2024
1 parent da3c215 commit 3f72bf7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/maker/contextlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import (
"golang.org/x/exp/maps"
)

func (m *Maker) CreateContextCMakeLists(index int, cbuild Cbuild) error {

func (m *Maker) CreateContextCMakeLists(index int) error {
cbuild := &m.Cbuilds[index]
outputByProducts, outputFile, outputType, customCommands := OutputFiles(cbuild.BuildDescType.Output)
outputExt := path.Ext(outputFile)
outputName := strings.TrimSuffix(outputFile, outputExt)
cbuild.ContextRoot, _ = filepath.Rel(m.CbuildIndex.BaseDir, cbuild.BaseDir)
cbuild.ContextRoot = filepath.ToSlash(cbuild.ContextRoot)
cbuild.Toolchain = m.RegisteredToolchains[m.SelectedToolchainVersion[index]].Name
outDir := AddRootPrefix(cbuild.ContextRoot, cbuild.BuildDescType.OutputDirs.Outdir)
contextDir := path.Join(m.SolutionIntDir, cbuild.BuildDescType.Context)
Expand Down
2 changes: 1 addition & 1 deletion pkg/maker/maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m *Maker) GenerateCMakeLists() error {

// Create context specific CMake files
for index := range m.Cbuilds {
err = m.CreateContextCMakeLists(index, m.Cbuilds[index])
err = m.CreateContextCMakeLists(index)
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/maker/maker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ func init() {

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

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

t.Run("test maker with cbuild in subfolder", func(t *testing.T) {
var m maker.Maker
m.Params.InputFile = testRoot + "/run/generic/solutionName4.cbuild-idx.yml"
err := m.GenerateCMakeLists()
assert.Nil(err)
assert.Equal("project/subfolder", m.Cbuilds[0].ContextRoot)
})

t.Run("test maker with invalid input param", func(t *testing.T) {
var m maker.Maker
m.Params.InputFile = testRoot + "invalid.cbuild-idx.yml"
err := m.GenerateCMakeLists()
assert.Error(err)
Expand Down
1 change: 1 addition & 0 deletions pkg/maker/superlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (m *Maker) CreateSuperCMakeLists() error {
}
}
cbuildRelativePath, _ := filepath.Rel(m.CbuildIndex.BaseDir, cbuild.BaseDir)
cbuildRelativePath = filepath.ToSlash(cbuildRelativePath)
output := AddRootPrefix(cbuildRelativePath, path.Join(cbuild.BuildDescType.OutputDirs.Outdir, outputFile))
outputs += " \"" + output + "\"\n"
}
Expand Down
6 changes: 6 additions & 0 deletions test/data/generic/project/subfolder/contextName.cbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build:
compiler: AC6@>=6.6.6
device: deviceName
output:
- type: lib
file: projectName.lib
9 changes: 9 additions & 0 deletions test/data/generic/solutionName4.cbuild-idx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build-idx:
generated-by: csolution version 2.2.1
csolution: solutionName.csolution.yml
cprojects:
- cproject: projectName.cproject.yml
cbuilds:
- cbuild: project/subfolder/contextName.cbuild.yml
project: projectName
configuration: .BuildType+TargetType

0 comments on commit 3f72bf7

Please sign in to comment.