Skip to content

Commit 1dce7a6

Browse files
authored
[cbuild2cmake] Fix executes IO paths for shifted cbuild-idx
1 parent ea69fa5 commit 1dce7a6

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

pkg/maker/buildcontent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ func (m *Maker) ListExecutesIOs(io string, list []string, run string) string {
900900
content := "\nset(" + io
901901
var listItems string
902902
for index, input := range list {
903-
content += "\n " + AddRootPrefix("", input, m.SolutionRoot)
903+
content += "\n " + AddRootPrefix(m.CbuildIndex.RelDir, input, m.SolutionRoot)
904904
if strings.Contains(run, "${"+io+"_"+strconv.Itoa(index)+"}") {
905905
listItems += "\nlist(GET " + io + " " + strconv.Itoa(index) + " " + io + "_" + strconv.Itoa(index) + ")"
906906
}
@@ -912,7 +912,7 @@ func (m *Maker) ListExecutesIOs(io string, list []string, run string) string {
912912

913913
func (m *Maker) GetGeneratedFiles(list []string) {
914914
for _, input := range list {
915-
file := AddRootPrefix("", input, m.SolutionRoot)
915+
file := AddRootPrefix(m.CbuildIndex.RelDir, input, m.SolutionRoot)
916916
m.GeneratedFiles = utils.AppendUniquely(m.GeneratedFiles, file)
917917
}
918918
}

pkg/maker/buildcontent_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,26 @@ add_dependencies(project.debug+target-executes
522522

523523
t.Run("get executes generated files", func(t *testing.T) {
524524
var m maker.Maker
525-
var files = []string{"./source0.c", "./source1.c"}
525+
m.SolutionRoot, _ = filepath.Abs(testRoot)
526+
m.SolutionRoot = filepath.ToSlash(m.SolutionRoot)
527+
m.CbuildIndex.RelDir = "1/2/3"
528+
var files = []string{"../source0.c", "../../source1.c"}
526529
m.GetGeneratedFiles(files)
527530
assert.Equal(
528-
[]string{"${SOLUTION_ROOT}/source0.c", "${SOLUTION_ROOT}/source1.c"},
531+
[]string{"${SOLUTION_ROOT}/1/2/source0.c", "${SOLUTION_ROOT}/1/source1.c"},
529532
m.GeneratedFiles,
530533
)
531534
})
532535

536+
t.Run("list executes IOs", func(t *testing.T) {
537+
var m maker.Maker
538+
m.SolutionRoot, _ = filepath.Abs(testRoot)
539+
m.SolutionRoot = filepath.ToSlash(m.SolutionRoot)
540+
m.CbuildIndex.RelDir = "1/2/3"
541+
var files = []string{"../source0.c", "../../source1.c"}
542+
assert.Equal(
543+
"\nset(INPUT\n ${SOLUTION_ROOT}/1/2/source0.c\n ${SOLUTION_ROOT}/1/source1.c\n)",
544+
m.ListExecutesIOs("INPUT", files, ""),
545+
)
546+
})
533547
}

pkg/maker/parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type CbuildIndex struct {
3030
Executes []Executes `yaml:"executes"`
3131
} `yaml:"build-idx"`
3232
BaseDir string
33+
RelDir string
3334
}
3435

3536
type CbuildSet struct {
@@ -294,6 +295,8 @@ func (m *Maker) ParseCbuildFiles() error {
294295
m.SolutionName = filepath.Base(m.CbuildIndex.BuildIdx.Csolution)
295296
reg := regexp.MustCompile(`(.*)\.csolution.ya?ml`)
296297
m.SolutionName = reg.ReplaceAllString(m.SolutionName, "$1")
298+
m.CbuildIndex.RelDir, _ = filepath.Rel(m.SolutionRoot, m.CbuildIndex.BaseDir)
299+
m.CbuildIndex.RelDir = filepath.ToSlash(m.CbuildIndex.RelDir)
297300

298301
// Parse cbuild-set file
299302
if m.Options.UseContextSet {

0 commit comments

Comments
 (0)