16
16
package builder_utils
17
17
18
18
import (
19
+ "fmt"
19
20
"os"
20
21
"os/exec"
21
22
"path/filepath"
@@ -36,45 +37,24 @@ import (
36
37
var tr = i18n .Tr
37
38
38
39
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
40
41
var err error
41
42
if recurse {
42
- allFiles , err = sourcePath .ReadDirRecursive ()
43
+ sources , err = sourcePath .ReadDirRecursive ()
43
44
} else {
44
- allFiles , err = sourcePath .ReadDir ()
45
+ sources , err = sourcePath .ReadDir ()
45
46
}
46
47
if err != nil {
47
48
return nil , err
48
49
}
49
50
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" }
56
52
57
- ctx .Progress .AddSubSteps (len (sSources ) + len (cSources ) + len (cppSources ))
53
+ sources .FilterSuffix (validExtensions ... )
54
+ ctx .Progress .AddSubSteps (len (sources ))
58
55
defer ctx .Progress .RemoveSubSteps ()
59
56
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 )
78
58
}
79
59
80
60
func findAllFilesInFolder (sourcePath string , recurse bool ) ([]string , error ) {
@@ -108,7 +88,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
108
88
return sources , nil
109
89
}
110
90
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 ) {
112
92
objectFiles := paths .NewPathList ()
113
93
if len (sources ) == 0 {
114
94
return objectFiles , nil
@@ -119,6 +99,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
119
99
120
100
queue := make (chan * paths.Path )
121
101
job := func (source * paths.Path ) {
102
+ recipe := fmt .Sprintf ("recipe%s.o.pattern" , source .Ext ())
122
103
objectFile , err := compileFileWithRecipe (ctx , sourcePath , source , buildPath , buildProperties , includes , recipe )
123
104
if err != nil {
124
105
errorsMux .Lock ()
0 commit comments