diff --git a/pkg/maker/contextlists.go b/pkg/maker/contextlists.go index 15a7450..606e04b 100644 --- a/pkg/maker/contextlists.go +++ b/pkg/maker/contextlists.go @@ -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) diff --git a/pkg/maker/maker.go b/pkg/maker/maker.go index e1f6b32..e6c845a 100644 --- a/pkg/maker/maker.go +++ b/pkg/maker/maker.go @@ -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 } diff --git a/pkg/maker/maker_test.go b/pkg/maker/maker_test.go index 114b36b..5831a88 100644 --- a/pkg/maker/maker_test.go +++ b/pkg/maker/maker_test.go @@ -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) diff --git a/pkg/maker/superlists.go b/pkg/maker/superlists.go index 34e4f17..7fb5924 100644 --- a/pkg/maker/superlists.go +++ b/pkg/maker/superlists.go @@ -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" } diff --git a/test/data/generic/project/subfolder/contextName.cbuild.yml b/test/data/generic/project/subfolder/contextName.cbuild.yml new file mode 100644 index 0000000..17b6745 --- /dev/null +++ b/test/data/generic/project/subfolder/contextName.cbuild.yml @@ -0,0 +1,6 @@ +build: + compiler: AC6@>=6.6.6 + device: deviceName + output: + - type: lib + file: projectName.lib diff --git a/test/data/generic/solutionName4.cbuild-idx.yml b/test/data/generic/solutionName4.cbuild-idx.yml new file mode 100644 index 0000000..2ec6786 --- /dev/null +++ b/test/data/generic/solutionName4.cbuild-idx.yml @@ -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