Skip to content

Commit 5fdf4f7

Browse files
committed
Simplified structure of CompileFiles
1 parent 7f48528 commit 5fdf4f7

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

legacy/builder/builder_utils/utils.go

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package builder_utils
1717

1818
import (
19+
"fmt"
1920
"os"
2021
"os/exec"
2122
"path/filepath"
@@ -36,45 +37,24 @@ import (
3637
var tr = i18n.Tr
3738

3839
func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
39-
var allFiles paths.PathList
40+
var sources paths.PathList
4041
var err error
4142
if recurse {
42-
allFiles, err = sourcePath.ReadDirRecursive()
43+
sources, err = sourcePath.ReadDirRecursive()
4344
} else {
44-
allFiles, err = sourcePath.ReadDir()
45+
sources, err = sourcePath.ReadDir()
4546
}
4647
if err != nil {
4748
return nil, err
4849
}
4950

50-
sSources := allFiles.Clone()
51-
sSources.FilterSuffix(".S")
52-
cSources := allFiles.Clone()
53-
cSources.FilterSuffix(".c")
54-
cppSources := allFiles.Clone()
55-
cppSources.FilterSuffix(".cpp")
51+
validExtensions := []string{".S", ".c", ".cpp"}
5652

57-
ctx.Progress.AddSubSteps(len(sSources) + len(cSources) + len(cppSources))
53+
sources.FilterSuffix(validExtensions...)
54+
ctx.Progress.AddSubSteps(len(sources))
5855
defer ctx.Progress.RemoveSubSteps()
5956

60-
sObjectFiles, err := compileFilesWithRecipe(ctx, sourcePath, sSources, buildPath, buildProperties, includes, "recipe.S.o.pattern")
61-
if err != nil {
62-
return nil, err
63-
}
64-
cObjectFiles, err := compileFilesWithRecipe(ctx, sourcePath, cSources, buildPath, buildProperties, includes, "recipe.c.o.pattern")
65-
if err != nil {
66-
return nil, err
67-
}
68-
cppObjectFiles, err := compileFilesWithRecipe(ctx, sourcePath, cppSources, buildPath, buildProperties, includes, "recipe.cpp.o.pattern")
69-
if err != nil {
70-
return nil, err
71-
}
72-
73-
objectFiles := paths.NewPathList()
74-
objectFiles.AddAll(sObjectFiles)
75-
objectFiles.AddAll(cObjectFiles)
76-
objectFiles.AddAll(cppObjectFiles)
77-
return objectFiles, nil
57+
return compileFilesWithRecipe(ctx, sourcePath, sources, buildPath, buildProperties, includes, validExtensions)
7858
}
7959

8060
func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
@@ -108,7 +88,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
10888
return sources, nil
10989
}
11090

111-
func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources paths.PathList, buildPath *paths.Path, buildProperties *properties.Map, includes []string, recipe string) (paths.PathList, error) {
91+
func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources paths.PathList, buildPath *paths.Path, buildProperties *properties.Map, includes []string, validExtensions []string) (paths.PathList, error) {
11292
objectFiles := paths.NewPathList()
11393
if len(sources) == 0 {
11494
return objectFiles, nil
@@ -119,6 +99,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
11999

120100
queue := make(chan *paths.Path)
121101
job := func(source *paths.Path) {
102+
recipe := fmt.Sprintf("recipe%s.o.pattern", source.Ext())
122103
objectFile, err := compileFileWithRecipe(ctx, sourcePath, source, buildPath, buildProperties, includes, recipe)
123104
if err != nil {
124105
errorsMux.Lock()

0 commit comments

Comments
 (0)