@@ -40,12 +40,13 @@ import (
40
40
41
41
"github.com/arduino/arduino-builder/constants"
42
42
"github.com/arduino/arduino-builder/i18n"
43
+ "github.com/arduino/arduino-builder/types"
43
44
"github.com/arduino/arduino-builder/utils"
44
45
"github.com/arduino/go-properties-map"
45
46
)
46
47
47
- func CompileFilesRecursive (objectFiles []string , sourcePath string , buildPath string , buildProperties properties.Map , includes []string , verbose bool , warningsLevel string , logger i18n. Logger ) ([]string , error ) {
48
- 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 )
49
50
if err != nil {
50
51
return nil , i18n .WrapError (err )
51
52
}
@@ -56,7 +57,7 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
56
57
}
57
58
58
59
for _ , folder := range folders {
59
- 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 )
60
61
if err != nil {
61
62
return nil , i18n .WrapError (err )
62
63
}
@@ -65,28 +66,28 @@ func CompileFilesRecursive(objectFiles []string, sourcePath string, buildPath st
65
66
return objectFiles , nil
66
67
}
67
68
68
- func CompileFiles (objectFiles []string , sourcePath string , recurse bool , buildPath string , buildProperties properties.Map , includes []string , verbose bool , warningsLevel string , logger i18n. Logger ) ([]string , error ) {
69
- 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 )
70
71
if err != nil {
71
72
return nil , i18n .WrapError (err )
72
73
}
73
- 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 )
74
75
if err != nil {
75
76
return nil , i18n .WrapError (err )
76
77
}
77
- 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 )
78
79
if err != nil {
79
80
return nil , i18n .WrapError (err )
80
81
}
81
82
return objectFiles , nil
82
83
}
83
84
84
- 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 ) {
85
86
sources , err := findFilesInFolder (sourcePath , extension , recurse )
86
87
if err != nil {
87
88
return nil , i18n .WrapError (err )
88
89
}
89
- return compileFilesWithRecipe (objectFiles , sourcePath , sources , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
90
+ return compileFilesWithRecipe (ctx , objectFiles , sourcePath , sources , buildPath , buildProperties , includes , recipe )
90
91
}
91
92
92
93
func findFilesInFolder (sourcePath string , extension string , recurse bool ) ([]string , error ) {
@@ -145,9 +146,9 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
145
146
return sources , nil
146
147
}
147
148
148
- 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 ) {
149
150
for _ , source := range sources {
150
- objectFile , err := compileFileWithRecipe (sourcePath , source , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
151
+ objectFile , err := compileFileWithRecipe (ctx , sourcePath , source , buildPath , buildProperties , includes , recipe )
151
152
if err != nil {
152
153
return nil , i18n .WrapError (err )
153
154
}
@@ -157,9 +158,10 @@ func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []s
157
158
return objectFiles , nil
158
159
}
159
160
160
- func compileFileWithRecipe (sourcePath string , source string , buildPath string , buildProperties properties.Map , includes []string , recipe string , verbose bool , warningsLevel string , logger i18n.Logger ) (string , error ) {
161
+ func compileFileWithRecipe (ctx * types.Context , sourcePath string , source string , buildPath string , buildProperties properties.Map , includes []string , recipe string ) (string , error ) {
162
+ logger := ctx .GetLogger ()
161
163
properties := buildProperties .Clone ()
162
- properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + warningsLevel ]
164
+ properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + ctx . WarningsLevel ]
163
165
properties [constants .BUILD_PROPERTIES_INCLUDES ] = strings .Join (includes , constants .SPACE )
164
166
properties [constants .BUILD_PROPERTIES_SOURCE_FILE ] = source
165
167
relativeSource , err := filepath .Rel (sourcePath , source )
@@ -179,11 +181,11 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b
179
181
}
180
182
181
183
if ! objIsUpToDate {
182
- _ , err = ExecRecipe (properties , recipe , false , verbose , verbose , logger )
184
+ _ , err = ExecRecipe (properties , recipe , false , ctx . Verbose , ctx . Verbose , logger )
183
185
if err != nil {
184
186
return "" , i18n .WrapError (err )
185
187
}
186
- } else if verbose {
188
+ } else if ctx . Verbose {
187
189
logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_USING_PREVIOUS_COMPILED_FILE , properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
188
190
}
189
191
@@ -309,7 +311,8 @@ func CoreOrReferencedCoreHasChanged(corePath, targetCorePath, targetFile string)
309
311
return true
310
312
}
311
313
312
- func ArchiveCompiledFiles (buildPath string , archiveFile string , objectFiles []string , buildProperties properties.Map , verbose bool , logger i18n.Logger ) (string , error ) {
314
+ func ArchiveCompiledFiles (ctx * types.Context , buildPath string , archiveFile string , objectFiles []string , buildProperties properties.Map ) (string , error ) {
315
+ logger := ctx .GetLogger ()
313
316
archiveFilePath := filepath .Join (buildPath , archiveFile )
314
317
315
318
rebuildArchive := false
@@ -332,7 +335,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
332
335
return "" , i18n .WrapError (err )
333
336
}
334
337
} else {
335
- if verbose {
338
+ if ctx . Verbose {
336
339
logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_USING_PREVIOUS_COMPILED_FILE , archiveFilePath )
337
340
}
338
341
return archiveFilePath , nil
@@ -345,7 +348,7 @@ func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []st
345
348
properties [constants .BUILD_PROPERTIES_ARCHIVE_FILE_PATH ] = archiveFilePath
346
349
properties [constants .BUILD_PROPERTIES_OBJECT_FILE ] = objectFile
347
350
348
- _ , err := ExecRecipe (properties , constants .RECIPE_AR_PATTERN , false , verbose , verbose , logger )
351
+ _ , err := ExecRecipe (properties , constants .RECIPE_AR_PATTERN , false , ctx . Verbose , ctx . Verbose , logger )
349
352
if err != nil {
350
353
return "" , i18n .WrapError (err )
351
354
}
0 commit comments