Skip to content

Commit

Permalink
Remove '>=' from missing pack version string (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 authored Apr 4, 2024
1 parent 76ad65f commit d8ef1ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/builder/csolution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (b CSolutionBuilder) installMissingPacks() (err error) {
if pack == "" {
continue
}

// This call should be removed once the limitation of 'cpackget'
// to handle '>=' in pack version, is resolved
pack = utils.RemoveVersionRange(pack)

args = []string{"add", pack, "--force-reinstall", "--agree-embedded-license"}
cpackgetBin := filepath.Join(b.InstallConfigs.BinPath, "cpackget"+b.InstallConfigs.BinExtn)
if _, err := os.Stat(cpackgetBin); os.IsNotExist(err) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"

Expand Down Expand Up @@ -325,3 +326,15 @@ func ResolveContexts(allContext []string, contextFilters []string) ([]string, er
}
return selectedContexts, nil
}

func RemoveVersionRange(str string) string {
// This function removes the version range specifier '>='
// from the pack version. for e.g. "ARM::CMSIS@>=6.0.0" is
// converted into "ARM::[email protected]"
re := regexp.MustCompile(`@([^0-9]*)(\d)`)
match := re.FindStringSubmatch(str)
if len(match) >= 3 {
return strings.Replace(str, match[1], "", 1)
}
return str
}
20 changes: 20 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,23 @@ func TestParseCsolutionFile(t *testing.T) {
assert.Equal(data.Solution.TargetTypes[1].Type, "CM0")
})
}

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

testCases := []struct {
inputString string
expectedOutput string
}{
{"ARM::CMSIS@>=6.0.0", "ARM::[email protected]"},
{"ARM::CMSIS@>=6.0.0-alpha0", "ARM::[email protected]"},
{"ARM::[email protected]", "ARM::[email protected]"},
{"ARM::CMSIS", "ARM::CMSIS"},
{"", ""},
}

for _, test := range testCases {
outString := RemoveVersionRange(test.inputString)
assert.Equal(test.expectedOutput, outString)
}
}

0 comments on commit d8ef1ed

Please sign in to comment.