Skip to content

Commit

Permalink
Align selection of first build & target type when cbuild-set doesn't …
Browse files Browse the repository at this point in the history
…exist

aligning with : Open-CMSIS-Pack/devtools#1562
  • Loading branch information
soumeh01 authored Jul 4, 2024
1 parent 111267e commit 15c0e63
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 75 deletions.
42 changes: 6 additions & 36 deletions pkg/builder/csolution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,22 @@ func (b CSolutionBuilder) generateBuildFiles() (err error) {
selectedContexts, _ = b.getSelectedContexts(cbuildSetFile)
}

// when using "cbuild setup *.csolution -S" with no existing cbuild-set file
// Select first target-type and the first build-type for each project
// when using "cbuild setup *.csolution.yml -S" with no existing cbuild-set file
// Select first target-type and the first build-type for first listed project
if b.Setup && b.Options.UseContextSet && (len(b.Options.Contexts) == 0) && errors.Is(err, os.ErrNotExist) {
// Retrieve all available contexts in yml-order
allContexts, err := b.listContexts(true, true)
allYmlOrderedContexts, err := b.listContexts(true, true)
if err != nil {
return err
}

// Ensure at least one context exists
if len(allContexts) == 0 {
if len(allYmlOrderedContexts) == 0 {
return errutils.New(errutils.ErrNoContextFound)
}

csolution, err := utils.ParseCSolutionFile(b.InputFile)
if err != nil {
return err
}

var buildType string
if len(csolution.Solution.BuildTypes) > 0 {
buildType = csolution.Solution.BuildTypes[0].Type
} else {
buildType = "*"
}

// Determine default context from the parsed solution file
context := utils.ContextItem{
ProjectName: "*",
BuildType: buildType,
TargetType: csolution.Solution.TargetTypes[0].Type,
}

// Create the default context
defaultContext := utils.CreateContext(context)

// Resolve the selected contexts including the default one
selectedContexts, err = utils.ResolveContexts(allContexts, []string{defaultContext})
if err != nil {
return err
}

// Append selected contexts to the arguments
for _, ctx := range selectedContexts {
args = append(args, "--context="+ctx)
}
// Append first context from yml ordered context list
args = append(args, "--context="+allYmlOrderedContexts[0])
}

// on setup command, run csolution convert command with --quiet
Expand Down
20 changes: 0 additions & 20 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,6 @@ type CbuildSet struct {
} `yaml:"cbuild-set"`
}

type CSolution struct {
Solution struct {
TargetTypes []struct {
Type string `yaml:"type"`
} `yaml:"target-types"`
BuildTypes []struct {
Type string `yaml:"type"`
} `yaml:"build-types"`
} `yaml:"solution"`
}

func ParseCbuildIndexFile(cbuildIndexFile string) (data CbuildIndex, err error) {
yfile, err := os.ReadFile(cbuildIndexFile)
if err != nil {
Expand All @@ -223,15 +212,6 @@ func ParseCbuildSetFile(cbuildSetFile string) (data CbuildSet, err error) {
return
}

func ParseCSolutionFile(csolutionFile string) (data CSolution, err error) {
yfile, err := os.ReadFile(csolutionFile)
if err != nil {
return
}
err = yaml.Unmarshal(yfile, &data)
return
}

func AppendUnique[T comparable](slice []T, elems ...T) []T {
lookup := make(map[T]struct{})
all := append(slice, elems...)
Expand Down
19 changes: 0 additions & 19 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,6 @@ func TestResolveContexts(t *testing.T) {
}
}

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

t.Run("test input file not available", func(t *testing.T) {
_, err := ParseCSolutionFile("Unknown.csolution.yml")
assert.Error(err)
})

t.Run("test csolution file parsing", func(t *testing.T) {
data, err := ParseCSolutionFile(filepath.Join(testRoot, testDir, "TestSolution/test.csolution.yml"))
assert.Nil(err)
assert.Equal(len(data.Solution.BuildTypes), 1)
assert.Equal(len(data.Solution.TargetTypes), 2)
assert.Equal(data.Solution.BuildTypes[0].Type, "Debug")
assert.Equal(data.Solution.TargetTypes[0].Type, "CM3")
assert.Equal(data.Solution.TargetTypes[1].Type, "CM0")
})
}

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

Expand Down

0 comments on commit 15c0e63

Please sign in to comment.