@@ -45,8 +45,8 @@ import (
4545 "github.com/arduino/go-properties-map"
4646)
4747
48- func CompileFilesRecursive (objectFiles []string , sourcePath string , buildPath string , buildProperties properties.Map , includes []string , verbose bool , warningsLevel string , logger i18n. Logger ) ([]string , error ) {
49- objectFiles , err := CompileFiles (objectFiles , sourcePath , false , buildPath , buildProperties , includes , verbose , warningsLevel , logger )
48+ func CompileFilesRecursive (ctx * types. Context , objectFiles []string , sourcePath string , buildPath string , buildProperties properties.Map , includes []string ) ([]string , error ) {
49+ objectFiles , err := CompileFiles (ctx , objectFiles , sourcePath , false , buildPath , buildProperties , includes )
5050 if err != nil {
5151 return nil , i18n .WrapError (err )
5252 }
@@ -57,7 +57,7 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
5757 }
5858
5959 for _ , folder := range folders {
60- objectFiles , err = CompileFilesRecursive (objectFiles , filepath .Join (sourcePath , folder .Name ()), filepath .Join (buildPath , folder .Name ()), buildProperties , includes , verbose , warningsLevel , logger )
60+ objectFiles , err = CompileFilesRecursive (ctx , objectFiles , filepath .Join (sourcePath , folder .Name ()), filepath .Join (buildPath , folder .Name ()), buildProperties , includes )
6161 if err != nil {
6262 return nil , i18n .WrapError (err )
6363 }
@@ -66,28 +66,28 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
6666 return objectFiles , nil
6767}
6868
69- func CompileFiles (objectFiles []string , sourcePath string , recurse bool , buildPath string , buildProperties properties.Map , includes []string , verbose bool , warningsLevel string , logger i18n. Logger ) ([]string , error ) {
70- objectFiles , err := compileFilesWithExtensionWithRecipe (objectFiles , sourcePath , recurse , buildPath , buildProperties , includes , ".S" , constants .RECIPE_S_PATTERN , verbose , warningsLevel , logger )
69+ func CompileFiles (ctx * types. Context , objectFiles []string , sourcePath string , recurse bool , buildPath string , buildProperties properties.Map , includes []string ) ([]string , error ) {
70+ objectFiles , err := compileFilesWithExtensionWithRecipe (ctx , objectFiles , sourcePath , recurse , buildPath , buildProperties , includes , ".S" , constants .RECIPE_S_PATTERN )
7171 if err != nil {
7272 return nil , i18n .WrapError (err )
7373 }
74- objectFiles , err = compileFilesWithExtensionWithRecipe (objectFiles , sourcePath , recurse , buildPath , buildProperties , includes , ".c" , constants .RECIPE_C_PATTERN , verbose , warningsLevel , logger )
74+ objectFiles , err = compileFilesWithExtensionWithRecipe (ctx , objectFiles , sourcePath , recurse , buildPath , buildProperties , includes , ".c" , constants .RECIPE_C_PATTERN )
7575 if err != nil {
7676 return nil , i18n .WrapError (err )
7777 }
78- objectFiles , err = compileFilesWithExtensionWithRecipe (objectFiles , sourcePath , recurse , buildPath , buildProperties , includes , ".cpp" , constants .RECIPE_CPP_PATTERN , verbose , warningsLevel , logger )
78+ objectFiles , err = compileFilesWithExtensionWithRecipe (ctx , objectFiles , sourcePath , recurse , buildPath , buildProperties , includes , ".cpp" , constants .RECIPE_CPP_PATTERN )
7979 if err != nil {
8080 return nil , i18n .WrapError (err )
8181 }
8282 return objectFiles , nil
8383}
8484
85- func compileFilesWithExtensionWithRecipe (objectFiles []string , sourcePath string , recurse bool , buildPath string , buildProperties properties.Map , includes []string , extension string , recipe string , verbose bool , warningsLevel string , logger i18n. Logger ) ([]string , error ) {
85+ func compileFilesWithExtensionWithRecipe (ctx * types. Context , objectFiles []string , sourcePath string , recurse bool , buildPath string , buildProperties properties.Map , includes []string , extension string , recipe string ) ([]string , error ) {
8686 sources , err := findFilesInFolder (sourcePath , extension , recurse )
8787 if err != nil {
8888 return nil , i18n .WrapError (err )
8989 }
90- return compileFilesWithRecipe (objectFiles , sourcePath , sources , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
90+ return compileFilesWithRecipe (ctx , objectFiles , sourcePath , sources , buildPath , buildProperties , includes , recipe )
9191}
9292
9393func findFilesInFolder (sourcePath string , extension string , recurse bool ) ([]string , error ) {
@@ -146,7 +146,7 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
146146 return sources , nil
147147}
148148
149- func compileFilesWithRecipe (objectFiles []string , sourcePath string , sources []string , buildPath string , buildProperties properties.Map , includes []string , recipe string , verbose bool , warningsLevel string , logger i18n. Logger ) ([]string , error ) {
149+ func compileFilesWithRecipe (ctx * types. Context , objectFiles []string , sourcePath string , sources []string , buildPath string , buildProperties properties.Map , includes []string , recipe string ) ([]string , error ) {
150150 if len (sources ) == 0 {
151151 return objectFiles , nil
152152 }
@@ -160,7 +160,7 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s
160160 for _ , source := range sources {
161161 go func (source string ) {
162162 defer wg .Done ()
163- objectFile , err := compileFileWithRecipe (sourcePath , source , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
163+ objectFile , err := compileFileWithRecipe (ctx , sourcePath , source , buildPath , buildProperties , includes , recipe )
164164 if err != nil {
165165 errorsChan <- err
166166 } else {
@@ -190,9 +190,10 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s
190190 }
191191}
192192
193- func compileFileWithRecipe (sourcePath string , source string , buildPath string , buildProperties properties.Map , includes []string , recipe string , verbose bool , warningsLevel string , logger i18n.Logger ) (string , error ) {
193+ func compileFileWithRecipe (ctx * types.Context , sourcePath string , source string , buildPath string , buildProperties properties.Map , includes []string , recipe string ) (string , error ) {
194+ logger := ctx .GetLogger ()
194195 properties := buildProperties .Clone ()
195- properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + warningsLevel ]
196+ properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + ctx . WarningsLevel ]
196197 properties [constants .BUILD_PROPERTIES_INCLUDES ] = strings .Join (includes , constants .SPACE )
197198 properties [constants .BUILD_PROPERTIES_SOURCE_FILE ] = source
198199 relativeSource , err := filepath .Rel (sourcePath , source )
@@ -212,11 +213,11 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b
212213 }
213214
214215 if ! objIsUpToDate {
215- _ , err = ExecRecipe (properties , recipe , false , verbose , verbose , logger )
216+ _ , err = ExecRecipe (properties , recipe , false , ctx . Verbose , ctx . Verbose , logger )
216217 if err != nil {
217218 return "" , i18n .WrapError (err )
218219 }
219- } else if verbose {
220+ } else if ctx . Verbose {
220221 logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_USING_PREVIOUS_COMPILED_FILE , properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
221222 }
222223
@@ -342,7 +343,8 @@ func CoreOrReferencedCoreHasChanged(corePath, targetCorePath, targetFile string)
342343 return true
343344}
344345
345- func ArchiveCompiledFiles (buildPath string , archiveFile string , objectFiles []string , buildProperties properties.Map , verbose bool , logger i18n.Logger ) (string , error ) {
346+ func ArchiveCompiledFiles (ctx * types.Context , buildPath string , archiveFile string , objectFiles []string , buildProperties properties.Map ) (string , error ) {
347+ logger := ctx .GetLogger ()
346348 archiveFilePath := filepath .Join (buildPath , archiveFile )
347349
348350 rebuildArchive := false
@@ -365,7 +367,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
365367 return "" , i18n .WrapError (err )
366368 }
367369 } else {
368- if verbose {
370+ if ctx . Verbose {
369371 logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_USING_PREVIOUS_COMPILED_FILE , archiveFilePath )
370372 }
371373 return archiveFilePath , nil
@@ -378,7 +380,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
378380 properties [constants .BUILD_PROPERTIES_ARCHIVE_FILE_PATH ] = archiveFilePath
379381 properties [constants .BUILD_PROPERTIES_OBJECT_FILE ] = objectFile
380382
381- _ , err := ExecRecipe (properties , constants .RECIPE_AR_PATTERN , false , verbose , verbose , logger )
383+ _ , err := ExecRecipe (properties , constants .RECIPE_AR_PATTERN , false , ctx . Verbose , ctx . Verbose , logger )
382384 if err != nil {
383385 return "" , i18n .WrapError (err )
384386 }
0 commit comments