Skip to content

Commit 6e0ef40

Browse files
committed
Applied suggestion from codereview
1 parent 3fdf1b0 commit 6e0ef40

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

legacy/builder/create_cmake_rule.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ import (
3030
"github.com/arduino/arduino-cli/legacy/builder/utils"
3131
)
3232

33-
func stringArrayToLookupFunction(in []string) func(string) bool {
34-
out := map[string]bool{}
35-
for _, i := range in {
36-
out[i] = true
37-
}
38-
return func(s string) bool {
39-
return out[s]
40-
}
41-
}
42-
4333
type ExportProjectCMake struct {
4434
// Was there an error while compiling the sketch?
4535
SketchError bool
@@ -81,12 +71,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
8171
cmakeFile := cmakeFolder.Join("CMakeLists.txt")
8272

8373
dynamicLibsFromPkgConfig := map[string]bool{}
84-
extensions := stringArrayToLookupFunction(validExportExtensions)
8574
for _, library := range ctx.ImportedLibraries {
8675
// Copy used libraries in the correct folder
8776
libDir := libBaseFolder.Join(library.Name)
8877
mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU)
89-
utils.CopyDir(library.InstallDir.String(), libDir.String(), extensions)
78+
utils.CopyDir(library.InstallDir.String(), libDir.String(), validExportExtensions)
9079

9180
// Read cmake options if available
9281
isStaticLib := true
@@ -116,11 +105,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
116105
}
117106

118107
// Copy core + variant in use + preprocessed sketch in the correct folders
119-
err := utils.CopyDir(ctx.BuildProperties.Get("build.core.path"), coreFolder.String(), extensions)
108+
err := utils.CopyDir(ctx.BuildProperties.Get("build.core.path"), coreFolder.String(), validExportExtensions)
120109
if err != nil {
121110
fmt.Println(err)
122111
}
123-
err = utils.CopyDir(ctx.BuildProperties.Get("build.variant.path"), coreFolder.Join("variant").String(), extensions)
112+
err = utils.CopyDir(ctx.BuildProperties.Get("build.variant.path"), coreFolder.Join("variant").String(), validExportExtensions)
124113
if err != nil {
125114
fmt.Println(err)
126115
}
@@ -136,7 +125,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
136125
command.Run(ctx)
137126
}
138127

139-
err = utils.CopyDir(ctx.SketchBuildPath.String(), cmakeFolder.Join("sketch").String(), extensions)
128+
err = utils.CopyDir(ctx.SketchBuildPath.String(), cmakeFolder.Join("sketch").String(), validExportExtensions)
140129
if err != nil {
141130
fmt.Println(err)
142131
}

legacy/builder/utils/utils.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ func AbsolutizePaths(files []string) ([]string, error) {
243243
return files, nil
244244
}
245245

246-
type CheckExtensionFunc func(ext string) bool
247-
248246
func FindFilesInFolder(dir *paths.Path, recurse bool, extensions []string) (paths.PathList, error) {
249247
fileFilter := paths.AndFilter(
250248
paths.FilterSuffixes(extensions...),
@@ -410,7 +408,17 @@ func CopyFile(src, dst string) (err error) {
410408
// CopyDir recursively copies a directory tree, attempting to preserve permissions.
411409
// Source directory must exist, destination directory must *not* exist.
412410
// Symlinks are ignored and skipped.
413-
func CopyDir(src string, dst string, extensions CheckExtensionFunc) (err error) {
411+
func CopyDir(src string, dst string, extensions []string) (err error) {
412+
isAcceptedExtension := func(ext string) bool {
413+
ext = strings.ToLower(ext)
414+
for _, valid := range extensions {
415+
if ext == valid {
416+
return true
417+
}
418+
}
419+
return false
420+
}
421+
414422
src = filepath.Clean(src)
415423
dst = filepath.Clean(dst)
416424

@@ -455,7 +463,7 @@ func CopyDir(src string, dst string, extensions CheckExtensionFunc) (err error)
455463
continue
456464
}
457465

458-
if extensions != nil && !extensions(strings.ToLower(filepath.Ext(srcPath))) {
466+
if !isAcceptedExtension(filepath.Ext(srcPath)) {
459467
continue
460468
}
461469

0 commit comments

Comments
 (0)