Skip to content

Commit 40e7d7c

Browse files
committed
FindFilesInFolder now returns the result instead of changine the reference
1 parent 7b40f21 commit 40e7d7c

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

legacy/builder/container_find_includes.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile *SourceFile) error
409409
func (f *CppIncludesFinder) queueSourceFilesFromFolder(srcDir, buildDir *paths.Path, recurse bool) error {
410410
extensions := func(ext string) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS[ext] }
411411
f.log.Debugf(" Queueing source files from %s (recurse %v)", srcDir, recurse)
412-
filePaths := []string{}
413-
err := utils.FindFilesInFolder(&filePaths, srcDir.String(), extensions, recurse)
412+
filePaths, err := utils.FindFilesInFolder(srcDir.String(), extensions, recurse)
414413
if err != nil {
415414
return errors.WithStack(err)
416415
}

legacy/builder/create_cmake_rule.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
9393
}
9494

9595
// Remove stray folders contining incompatible or not needed libraries archives
96-
var files []string
97-
utils.FindFilesInFolder(&files, libDir.Join("src").String(), staticLibsExtensions, true)
96+
files, _ := utils.FindFilesInFolder(libDir.Join("src").String(), staticLibsExtensions, true)
9897
for _, file := range files {
9998
staticLibDir := filepath.Dir(file)
10099
if !isStaticLib || !strings.Contains(staticLibDir, mcu) {
@@ -130,8 +129,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
130129
}
131130

132131
// remove "#line 1 ..." from exported c_make folder sketch
133-
var sketchFiles []string
134-
utils.FindFilesInFolder(&sketchFiles, cmakeFolder.Join("sketch").String(), extensions, false)
132+
sketchFiles, _ := utils.FindFilesInFolder(cmakeFolder.Join("sketch").String(), extensions, false)
135133

136134
for _, file := range sketchFiles {
137135
input, err := ioutil.ReadFile(file)
@@ -165,14 +163,12 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
165163
extractCompileFlags(ctx, constants.RECIPE_CPP_PATTERN, &defines, &dynamicLibsFromGccMinusL, &linkerflags, &linkDirectories, logger)
166164

167165
// Extract folders with .h in them for adding in include list
168-
var headerFiles []string
169166
isHeader := func(ext string) bool { return DOTHEXTENSION[ext] }
170-
utils.FindFilesInFolder(&headerFiles, cmakeFolder.String(), isHeader, true)
167+
headerFiles, _ := utils.FindFilesInFolder(cmakeFolder.String(), isHeader, true)
171168
foldersContainingDotH := findUniqueFoldersRelative(headerFiles, cmakeFolder.String())
172169

173170
// Extract folders with .a in them for adding in static libs paths list
174-
var staticLibs []string
175-
utils.FindFilesInFolder(&staticLibs, cmakeFolder.String(), staticLibsExtensions, true)
171+
staticLibs, _ := utils.FindFilesInFolder(cmakeFolder.String(), staticLibsExtensions, true)
176172

177173
// Generate the CMakeLists global file
178174

legacy/builder/phases/libraries_builder.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libs libraries.List) e
120120
break
121121
}
122122
// find all library names in the folder and prepend -l
123-
filePaths := []string{}
124123
libs_cmd := library.LDflags + " "
125124
extensions := func(ext string) bool {
126125
return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC[ext] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext]
127126
}
128-
utils.FindFilesInFolder(&filePaths, path.String(), extensions, false)
127+
filePaths, _ := utils.FindFilesInFolder(path.String(), extensions, false)
129128
for _, lib := range filePaths {
130129
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
131130
// strip "lib" first occurrence
@@ -178,13 +177,12 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
178177
// search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
179178
extensions := func(ext string) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext] }
180179

181-
filePaths := []string{}
182180
precompiledPath := findExpectedPrecompiledLibFolder(ctx, library)
183181
if precompiledPath != nil {
184182
// TODO: This codepath is just taken for .a with unusual names that would
185183
// be ignored by -L / -l methods.
186184
// Should we force precompiled libraries to start with "lib" ?
187-
err := utils.FindFilesInFolder(&filePaths, precompiledPath.String(), extensions, false)
185+
filePaths, err := utils.FindFilesInFolder(precompiledPath.String(), extensions, false)
188186
if err != nil {
189187
return nil, errors.WithStack(err)
190188
}

legacy/builder/sketch_loader.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ func (s *SketchLoader) Run(ctx *types.Context) error {
7373
}
7474

7575
func collectAllSketchFiles(from *paths.Path) (paths.PathList, error) {
76-
filePaths := []string{}
7776
// Source files in the root are compiled, non-recursively. This
7877
// is the only place where .ino files can be present.
7978
rootExtensions := func(ext string) bool { return MAIN_FILE_VALID_EXTENSIONS[ext] || ADDITIONAL_FILE_VALID_EXTENSIONS[ext] }
80-
err := utils.FindFilesInFolder(&filePaths, from.String(), rootExtensions, true /* recurse */)
79+
filePaths, err := utils.FindFilesInFolder(from.String(), rootExtensions, true /* recurse */)
8180
if err != nil {
8281
return nil, errors.WithStack(err)
8382
}

legacy/builder/utils/utils.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ func FindAllSubdirectories(folder string, output *[]string) error {
343343
return gohasissues.Walk(folder, walkFunc)
344344
}
345345

346-
func FindFilesInFolder(files *[]string, folder string, extensions CheckExtensionFunc, recurse bool) error {
346+
func FindFilesInFolder(folder string, extensions CheckExtensionFunc, recurse bool) ([]string, error) {
347+
files := []string{}
347348
walkFunc := func(path string, info os.FileInfo, err error) error {
348349
if err != nil {
349350
return err
@@ -379,10 +380,11 @@ func FindFilesInFolder(files *[]string, folder string, extensions CheckExtension
379380
}
380381
currentFile.Close()
381382

382-
*files = append(*files, path)
383+
files = append(files, path)
383384
return nil
384385
}
385-
return gohasissues.Walk(folder, walkFunc)
386+
err := gohasissues.Walk(folder, walkFunc)
387+
return files, err
386388
}
387389

388390
func AppendIfNotPresent(target []string, elements ...string) []string {

0 commit comments

Comments
 (0)