1616package builder_utils
1717
1818import (
19+ "fmt"
1920 "os"
2021 "os/exec"
2122 "path/filepath"
@@ -36,45 +37,24 @@ import (
3637var tr = i18n .Tr
3738
3839func 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
8060func 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