@@ -30,6 +30,7 @@ import (
30
30
"github.com/arduino/arduino-cli/legacy/builder/utils"
31
31
"github.com/arduino/go-paths-helper"
32
32
"github.com/arduino/go-properties-orderedmap"
33
+ "github.com/pkg/errors"
33
34
)
34
35
35
36
func PrintProgressIfProgressEnabledAndMachineLogger (ctx * types.Context ) {
@@ -48,18 +49,18 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
48
49
func CompileFilesRecursive (ctx * types.Context , sourcePath * paths.Path , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
49
50
objectFiles , err := CompileFiles (ctx , sourcePath , false , buildPath , buildProperties , includes )
50
51
if err != nil {
51
- return nil , i18n . WrapError (err )
52
+ return nil , errors . WithStack (err )
52
53
}
53
54
54
55
folders , err := utils .ReadDirFiltered (sourcePath .String (), utils .FilterDirs )
55
56
if err != nil {
56
- return nil , i18n . WrapError (err )
57
+ return nil , errors . WithStack (err )
57
58
}
58
59
59
60
for _ , folder := range folders {
60
61
subFolderObjectFiles , err := CompileFilesRecursive (ctx , sourcePath .Join (folder .Name ()), buildPath .Join (folder .Name ()), buildProperties , includes )
61
62
if err != nil {
62
- return nil , i18n . WrapError (err )
63
+ return nil , errors . WithStack (err )
63
64
}
64
65
objectFiles .AddAll (subFolderObjectFiles )
65
66
}
@@ -70,15 +71,15 @@ func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath
70
71
func CompileFiles (ctx * types.Context , sourcePath * paths.Path , recurse bool , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
71
72
sObjectFiles , err := compileFilesWithExtensionWithRecipe (ctx , sourcePath , recurse , buildPath , buildProperties , includes , ".S" , constants .RECIPE_S_PATTERN )
72
73
if err != nil {
73
- return nil , i18n . WrapError (err )
74
+ return nil , errors . WithStack (err )
74
75
}
75
76
cObjectFiles , err := compileFilesWithExtensionWithRecipe (ctx , sourcePath , recurse , buildPath , buildProperties , includes , ".c" , constants .RECIPE_C_PATTERN )
76
77
if err != nil {
77
- return nil , i18n . WrapError (err )
78
+ return nil , errors . WithStack (err )
78
79
}
79
80
cppObjectFiles , err := compileFilesWithExtensionWithRecipe (ctx , sourcePath , recurse , buildPath , buildProperties , includes , ".cpp" , constants .RECIPE_CPP_PATTERN )
80
81
if err != nil {
81
- return nil , i18n . WrapError (err )
82
+ return nil , errors . WithStack (err )
82
83
}
83
84
objectFiles := paths .NewPathList ()
84
85
objectFiles .AddAll (sObjectFiles )
@@ -90,15 +91,15 @@ func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buil
90
91
func compileFilesWithExtensionWithRecipe (ctx * types.Context , sourcePath * paths.Path , recurse bool , buildPath * paths.Path , buildProperties * properties.Map , includes []string , extension string , recipe string ) (paths.PathList , error ) {
91
92
sources , err := findFilesInFolder (sourcePath , extension , recurse )
92
93
if err != nil {
93
- return nil , i18n . WrapError (err )
94
+ return nil , errors . WithStack (err )
94
95
}
95
96
return compileFilesWithRecipe (ctx , sourcePath , sources , buildPath , buildProperties , includes , recipe )
96
97
}
97
98
98
99
func findFilesInFolder (sourcePath * paths.Path , extension string , recurse bool ) (paths.PathList , error ) {
99
100
files , err := utils .ReadDirFiltered (sourcePath .String (), utils .FilterFilesWithExtensions (extension ))
100
101
if err != nil {
101
- return nil , i18n . WrapError (err )
102
+ return nil , errors . WithStack (err )
102
103
}
103
104
var sources paths.PathList
104
105
for _ , file := range files {
@@ -108,13 +109,13 @@ func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (
108
109
if recurse {
109
110
folders , err := utils .ReadDirFiltered (sourcePath .String (), utils .FilterDirs )
110
111
if err != nil {
111
- return nil , i18n . WrapError (err )
112
+ return nil , errors . WithStack (err )
112
113
}
113
114
114
115
for _ , folder := range folders {
115
116
otherSources , err := findFilesInFolder (sourcePath .Join (folder .Name ()), extension , recurse )
116
117
if err != nil {
117
- return nil , i18n . WrapError (err )
118
+ return nil , errors . WithStack (err )
118
119
}
119
120
sources = append (sources , otherSources ... )
120
121
}
@@ -126,7 +127,7 @@ func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (
126
127
func findAllFilesInFolder (sourcePath string , recurse bool ) ([]string , error ) {
127
128
files , err := utils .ReadDirFiltered (sourcePath , utils .FilterFiles ())
128
129
if err != nil {
129
- return nil , i18n . WrapError (err )
130
+ return nil , errors . WithStack (err )
130
131
}
131
132
var sources []string
132
133
for _ , file := range files {
@@ -136,15 +137,15 @@ func findAllFilesInFolder(sourcePath string, recurse bool) ([]string, error) {
136
137
if recurse {
137
138
folders , err := utils .ReadDirFiltered (sourcePath , utils .FilterDirs )
138
139
if err != nil {
139
- return nil , i18n . WrapError (err )
140
+ return nil , errors . WithStack (err )
140
141
}
141
142
142
143
for _ , folder := range folders {
143
144
if ! utils .IsSCCSOrHiddenFile (folder ) {
144
145
// Skip SCCS directories as they do not influence the build and can be very large
145
146
otherSources , err := findAllFilesInFolder (filepath .Join (sourcePath , folder .Name ()), recurse )
146
147
if err != nil {
147
- return nil , i18n . WrapError (err )
148
+ return nil , errors . WithStack (err )
148
149
}
149
150
sources = append (sources , otherSources ... )
150
151
}
@@ -160,7 +161,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
160
161
return objectFiles , nil
161
162
}
162
163
var objectFilesMux sync.Mutex
163
- var errors []error
164
+ var errorsList []error
164
165
var errorsMux sync.Mutex
165
166
166
167
ctx .Progress .Steps = ctx .Progress .Steps / float64 (len (sources ))
@@ -171,7 +172,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
171
172
objectFile , err := compileFileWithRecipe (ctx , sourcePath , source , buildPath , buildProperties , includes , recipe )
172
173
if err != nil {
173
174
errorsMux .Lock ()
174
- errors = append (errors , err )
175
+ errorsList = append (errorsList , err )
175
176
errorsMux .Unlock ()
176
177
} else {
177
178
objectFilesMux .Lock ()
@@ -199,7 +200,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
199
200
// Feed jobs until error or done
200
201
for _ , source := range sources {
201
202
errorsMux .Lock ()
202
- gotError := len (errors ) > 0
203
+ gotError := len (errorsList ) > 0
203
204
errorsMux .Unlock ()
204
205
if gotError {
205
206
break
@@ -208,9 +209,9 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
208
209
}
209
210
close (queue )
210
211
wg .Wait ()
211
- if len (errors ) > 0 {
212
+ if len (errorsList ) > 0 {
212
213
// output the first error
213
- return nil , i18n . WrapError ( errors [0 ])
214
+ return nil , errors . WithStack ( errorsList [0 ])
214
215
}
215
216
objectFiles .Sort ()
216
217
return objectFiles , nil
@@ -224,25 +225,25 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
224
225
properties .SetPath (constants .BUILD_PROPERTIES_SOURCE_FILE , source )
225
226
relativeSource , err := sourcePath .RelTo (source )
226
227
if err != nil {
227
- return nil , i18n . WrapError (err )
228
+ return nil , errors . WithStack (err )
228
229
}
229
230
depsFile := buildPath .Join (relativeSource .String () + ".d" )
230
231
objectFile := buildPath .Join (relativeSource .String () + ".o" )
231
232
232
233
properties .SetPath (constants .BUILD_PROPERTIES_OBJECT_FILE , objectFile )
233
234
err = objectFile .Parent ().MkdirAll ()
234
235
if err != nil {
235
- return nil , i18n . WrapError (err )
236
+ return nil , errors . WithStack (err )
236
237
}
237
238
238
239
objIsUpToDate , err := ObjFileIsUpToDate (ctx , source , objectFile , depsFile )
239
240
if err != nil {
240
- return nil , i18n . WrapError (err )
241
+ return nil , errors . WithStack (err )
241
242
}
242
243
if ! objIsUpToDate {
243
244
_ , _ , err = ExecRecipe (ctx , properties , recipe , false /* stdout */ , utils .ShowIfVerbose /* stderr */ , utils .Show )
244
245
if err != nil {
245
- return nil , i18n . WrapError (err )
246
+ return nil , errors . WithStack (err )
246
247
}
247
248
} else if ctx .Verbose {
248
249
logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_USING_PREVIOUS_COMPILED_FILE , objectFile )
@@ -267,7 +268,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
267
268
sourceFile = sourceFile .Clean ()
268
269
sourceFileStat , err := sourceFile .Stat ()
269
270
if err != nil {
270
- return false , i18n . WrapError (err )
271
+ return false , errors . WithStack (err )
271
272
}
272
273
273
274
objectFile = objectFile .Clean ()
@@ -279,7 +280,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
279
280
}
280
281
return false , nil
281
282
} else {
282
- return false , i18n . WrapError (err )
283
+ return false , errors . WithStack (err )
283
284
}
284
285
}
285
286
@@ -292,7 +293,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
292
293
}
293
294
return false , nil
294
295
} else {
295
- return false , i18n . WrapError (err )
296
+ return false , errors . WithStack (err )
296
297
}
297
298
}
298
299
@@ -311,7 +312,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
311
312
312
313
rows , err := dependencyFile .ReadFileAsLines ()
313
314
if err != nil {
314
- return false , i18n . WrapError (err )
315
+ return false , errors . WithStack (err )
315
316
}
316
317
317
318
rows = utils .Map (rows , removeEndingBackSlash )
@@ -346,7 +347,7 @@ func ObjFileIsUpToDate(ctx *types.Context, sourceFile, objectFile, dependencyFil
346
347
// Ignore the error and trigger a full rebuild anyway
347
348
if debugLevel >= 20 {
348
349
logger .Fprintln (os .Stdout , constants .LOG_LEVEL_DEBUG , "Failed to read: {0}" , row )
349
- logger .Fprintln (os .Stdout , constants .LOG_LEVEL_DEBUG , i18n . WrapError ( err ) .Error ())
350
+ logger .Fprintln (os .Stdout , constants .LOG_LEVEL_DEBUG , err .Error ())
350
351
}
351
352
return false , nil
352
353
}
@@ -454,9 +455,8 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
454
455
455
456
// something changed, rebuild the core archive
456
457
if rebuildArchive {
457
- err = archiveFilePath .Remove ()
458
- if err != nil {
459
- return nil , i18n .WrapError (err )
458
+ if err := archiveFilePath .Remove (); err != nil {
459
+ return nil , errors .WithStack (err )
460
460
}
461
461
} else {
462
462
if ctx .Verbose {
@@ -472,9 +472,8 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
472
472
properties .SetPath (constants .BUILD_PROPERTIES_ARCHIVE_FILE_PATH , archiveFilePath )
473
473
properties .SetPath (constants .BUILD_PROPERTIES_OBJECT_FILE , objectFile )
474
474
475
- _ , _ , err := ExecRecipe (ctx , properties , constants .RECIPE_AR_PATTERN , false /* stdout */ , utils .ShowIfVerbose /* stderr */ , utils .Show )
476
- if err != nil {
477
- return nil , i18n .WrapError (err )
475
+ if _ , _ , err := ExecRecipe (ctx , properties , constants .RECIPE_AR_PATTERN , false /* stdout */ , utils .ShowIfVerbose /* stderr */ , utils .Show ); err != nil {
476
+ return nil , errors .WithStack (err )
478
477
}
479
478
}
480
479
@@ -485,7 +484,7 @@ func ExecRecipe(ctx *types.Context, buildProperties *properties.Map, recipe stri
485
484
// See util.ExecCommand for stdout/stderr arguments
486
485
command , err := PrepareCommandForRecipe (ctx , buildProperties , recipe , removeUnsetProperties )
487
486
if err != nil {
488
- return nil , nil , i18n . WrapError (err )
487
+ return nil , nil , errors . WithStack (err )
489
488
}
490
489
491
490
return utils .ExecCommand (ctx , command , stdout , stderr )
@@ -514,7 +513,7 @@ func PrepareCommandForRecipe(ctx *types.Context, buildProperties *properties.Map
514
513
515
514
command , err := utils .PrepareCommand (commandLine , logger , relativePath )
516
515
if err != nil {
517
- return nil , i18n . WrapError (err )
516
+ return nil , errors . WithStack (err )
518
517
}
519
518
520
519
return command , nil
0 commit comments