Skip to content

Commit 856e791

Browse files
committed
Replaced utils.SliceContains with stdlib function
1 parent e5166dc commit 856e791

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

legacy/builder/create_cmake_rule.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
properties "github.com/arduino/go-properties-orderedmap"
25+
"golang.org/x/exp/slices"
2526

2627
bldr "github.com/arduino/arduino-cli/arduino/builder"
2728
"github.com/arduino/arduino-cli/arduino/globals"
@@ -209,7 +210,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
209210
lib := staticLib.Base()
210211
lib = strings.TrimPrefix(lib, "lib")
211212
lib = strings.TrimSuffix(lib, ".a")
212-
if !utils.SliceContains(dynamicLibsFromGccMinusL, lib) {
213+
if !slices.Contains(dynamicLibsFromGccMinusL, lib) {
213214
linkGroup += " " + lib
214215
cmakelist += "add_library (" + lib + " STATIC IMPORTED)\n"
215216
location := strings.TrimPrefix(staticLib.String(), cmakeFolder.String())
@@ -264,7 +265,7 @@ func findUniqueFoldersRelative(slice []string, base string) string {
264265
for _, element := range slice {
265266
path := filepath.Dir(element)
266267
path = strings.TrimPrefix(path, base+"/")
267-
if !utils.SliceContains(out, path) {
268+
if !slices.Contains(out, path) {
268269
out = append(out, path)
269270
}
270271
}

legacy/builder/test/helper_tools_downloader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929

3030
"github.com/arduino/arduino-cli/legacy/builder/constants"
3131
"github.com/arduino/arduino-cli/legacy/builder/gohasissues"
32-
"github.com/arduino/arduino-cli/legacy/builder/utils"
3332
"github.com/arduino/go-paths-helper"
3433
"github.com/arduino/go-properties-orderedmap"
3534
"github.com/pkg/errors"
35+
"golang.org/x/exp/slices"
3636
)
3737

3838
var hardwareFolder = paths.New("downloaded_hardware")
@@ -692,7 +692,7 @@ func translateGOOSGOARCHToPackageIndexValue() []string {
692692
func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string, error) {
693693
if len(tool.OsUrls) > 0 {
694694
for _, osUrl := range tool.OsUrls {
695-
if utils.SliceContains(host, osUrl.Os) {
695+
if slices.Contains(host, osUrl.Os) {
696696
return osUrl.Url, nil
697697
}
698698
}
@@ -709,7 +709,7 @@ func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string
709709
systems := packageTool["systems"].([]interface{})
710710
for _, s := range systems {
711711
system := s.(map[string]interface{})
712-
if utils.SliceContains(host, system["host"].(string)) {
712+
if slices.Contains(host, system["host"].(string)) {
713713
return system[constants.TOOL_URL].(string), nil
714714
}
715715
}

legacy/builder/unused_compiled_libraries_remover.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package builder
1818
import (
1919
"github.com/arduino/arduino-cli/arduino/libraries"
2020
"github.com/arduino/arduino-cli/legacy/builder/types"
21-
"github.com/arduino/arduino-cli/legacy/builder/utils"
2221
"github.com/pkg/errors"
22+
"golang.org/x/exp/slices"
2323
)
2424

2525
type UnusedCompiledLibrariesRemover struct{}
@@ -39,7 +39,7 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error {
3939
}
4040
for _, file := range files {
4141
if file.IsDir() {
42-
if !utils.SliceContains(libraryNames, file.Base()) {
42+
if !slices.Contains(libraryNames, file.Base()) {
4343
if err := file.RemoveAll(); err != nil {
4444
return errors.WithStack(err)
4545
}

legacy/builder/utils/utils.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/arduino/arduino-cli/legacy/builder/types"
3333
paths "github.com/arduino/go-paths-helper"
3434
"github.com/pkg/errors"
35+
"golang.org/x/exp/slices"
3536
"golang.org/x/text/runes"
3637
"golang.org/x/text/transform"
3738
"golang.org/x/text/unicode/norm"
@@ -63,7 +64,7 @@ func FilterFilesWithExtensions(extensions ...string) filterFiles {
6364
return func(files []os.FileInfo) []os.FileInfo {
6465
var filtered []os.FileInfo
6566
for _, file := range files {
66-
if !file.IsDir() && SliceContains(extensions, filepath.Ext(file.Name())) {
67+
if !file.IsDir() && slices.Contains(extensions, filepath.Ext(file.Name())) {
6768
filtered = append(filtered, file)
6869
}
6970
}
@@ -118,15 +119,6 @@ func IsSCCSFile(file os.FileInfo) bool {
118119
return SOURCE_CONTROL_FOLDERS[name]
119120
}
120121

121-
func SliceContains(slice []string, target string) bool {
122-
for _, value := range slice {
123-
if value == target {
124-
return true
125-
}
126-
}
127-
return false
128-
}
129-
130122
type mapFunc func(string) string
131123

132124
func Map(slice []string, fn mapFunc) []string {
@@ -262,7 +254,7 @@ func FindFilesInFolder(dir *paths.Path, recurse bool, extensions []string) (path
262254

263255
func AppendIfNotPresent(target []string, elements ...string) []string {
264256
for _, element := range elements {
265-
if !SliceContains(target, element) {
257+
if !slices.Contains(target, element) {
266258
target = append(target, element)
267259
}
268260
}

0 commit comments

Comments
 (0)