@@ -20,6 +20,7 @@ import (
20
20
"fmt"
21
21
22
22
"github.com/arduino/arduino-cli/arduino/builder/compilation"
23
+ "github.com/arduino/arduino-cli/arduino/builder/detector"
23
24
"github.com/arduino/arduino-cli/arduino/builder/logger"
24
25
"github.com/arduino/arduino-cli/arduino/builder/progress"
25
26
"github.com/arduino/arduino-cli/arduino/cores"
@@ -223,14 +224,243 @@ func (b *Builder) ExecutableSectionsSize() ExecutablesFileSections {
223
224
return b .executableSectionsSize
224
225
}
225
226
226
- // SaveCompilationDatabase fixdoc
227
- func (b * Builder ) SaveCompilationDatabase () {
228
- if b .compilationDatabase != nil {
229
- b .compilationDatabase .SaveToFile ()
230
- }
231
- }
232
-
233
227
// TargetPlatform fixdoc
234
228
func (b * Builder ) TargetPlatform () * cores.PlatformRelease {
235
229
return b .targetPlatform
236
230
}
231
+
232
+ // Preprocess fixdoc
233
+ func (b * Builder ) Preprocess (detector * detector.SketchLibrariesDetector ) error {
234
+ b .Progress .AddSubSteps (6 )
235
+ defer b .Progress .RemoveSubSteps ()
236
+ return b .preprocess (detector )
237
+ }
238
+
239
+ func (b * Builder ) preprocess (detector * detector.SketchLibrariesDetector ) error {
240
+ if err := b .buildPath .MkdirAll (); err != nil {
241
+ return err
242
+ }
243
+
244
+ if err := b .BuildOptionsManager .WipeBuildPath (); err != nil {
245
+ return err
246
+ }
247
+ b .Progress .CompleteStep ()
248
+ b .Progress .PushProgress ()
249
+
250
+ if err := b .RunRecipe ("recipe.hooks.prebuild" , ".pattern" , false ); err != nil {
251
+ return err
252
+ }
253
+ b .Progress .CompleteStep ()
254
+ b .Progress .PushProgress ()
255
+
256
+ if err := b .PrepareSketchBuildPath (); err != nil {
257
+ return err
258
+ }
259
+ b .Progress .CompleteStep ()
260
+ b .Progress .PushProgress ()
261
+
262
+ b .logIfVerbose (false , tr ("Detecting libraries used..." ))
263
+ err := detector .FindIncludes (
264
+ b .GetBuildPath (),
265
+ b .GetBuildProperties ().GetPath ("build.core.path" ),
266
+ b .GetBuildProperties ().GetPath ("build.variant.path" ),
267
+ b .GetSketchBuildPath (),
268
+ b .Sketch (),
269
+ b .GetLibrariesBuildPath (),
270
+ b .GetBuildProperties (),
271
+ b .TargetPlatform ().Platform .Architecture ,
272
+ )
273
+ if err != nil {
274
+ return err
275
+ }
276
+ b .Progress .CompleteStep ()
277
+ b .Progress .PushProgress ()
278
+
279
+ b .WarnAboutArchIncompatibleLibraries (detector .ImportedLibraries ())
280
+ b .Progress .CompleteStep ()
281
+ b .Progress .PushProgress ()
282
+
283
+ b .logIfVerbose (false , tr ("Generating function prototypes..." ))
284
+ if err := b .PreprocessSketch (detector .IncludeFolders ()); err != nil {
285
+ return err
286
+ }
287
+ b .Progress .CompleteStep ()
288
+ b .Progress .PushProgress ()
289
+
290
+ // Output arduino-preprocessed source
291
+ preprocessedSketch , err := b .sketchBuildPath .Join (b .sketch .MainFile .Base () + ".cpp" ).ReadFile ()
292
+ if err != nil {
293
+ return err
294
+ }
295
+ b .logger .WriteStdout (preprocessedSketch )
296
+
297
+ return nil
298
+ }
299
+
300
+ func (b * Builder ) logIfVerbose (warn bool , msg string ) {
301
+ if ! b .logger .Verbose () {
302
+ return
303
+ }
304
+ if warn {
305
+ b .logger .Warn (msg )
306
+ return
307
+ }
308
+ b .logger .Info (msg )
309
+ }
310
+
311
+ // Build fixdoc
312
+ func (b * Builder ) Build (detector * detector.SketchLibrariesDetector ) error {
313
+ b .Progress .AddSubSteps (6 /** preprocess **/ + 21 /** build **/ )
314
+ defer b .Progress .RemoveSubSteps ()
315
+
316
+ if err := b .preprocess (detector ); err != nil {
317
+ return err
318
+ }
319
+
320
+ buildErr := b .build (detector )
321
+
322
+ detector .PrintUsedAndNotUsedLibraries (buildErr != nil )
323
+ b .Progress .CompleteStep ()
324
+ b .Progress .PushProgress ()
325
+
326
+ b .PrintUsedLibraries (detector .ImportedLibraries ())
327
+ b .Progress .CompleteStep ()
328
+ b .Progress .PushProgress ()
329
+
330
+ if buildErr != nil {
331
+ return buildErr
332
+ }
333
+ if err := b .ExportProjectCMake (detector .ImportedLibraries (), detector .IncludeFolders ()); err != nil {
334
+ return err
335
+ }
336
+ b .Progress .CompleteStep ()
337
+ b .Progress .PushProgress ()
338
+
339
+ if err := b .Size (); err != nil {
340
+ return err
341
+ }
342
+ b .Progress .CompleteStep ()
343
+ b .Progress .PushProgress ()
344
+
345
+ return nil
346
+ }
347
+
348
+ // Build fixdoc
349
+ func (b * Builder ) build (detector * detector.SketchLibrariesDetector ) error {
350
+ b .logIfVerbose (false , tr ("Compiling sketch..." ))
351
+ if err := b .RunRecipe ("recipe.hooks.sketch.prebuild" , ".pattern" , false ); err != nil {
352
+ return err
353
+ }
354
+ b .Progress .CompleteStep ()
355
+ b .Progress .PushProgress ()
356
+
357
+ if err := b .BuildSketch (detector .IncludeFolders ()); err != nil {
358
+ return err
359
+ }
360
+ b .Progress .CompleteStep ()
361
+ b .Progress .PushProgress ()
362
+
363
+ if err := b .RunRecipe ("recipe.hooks.sketch.postbuild" , ".pattern" , true ); err != nil {
364
+ return err
365
+ }
366
+ b .Progress .CompleteStep ()
367
+ b .Progress .PushProgress ()
368
+
369
+ b .logIfVerbose (false , tr ("Compiling libraries..." ))
370
+ if err := b .RunRecipe ("recipe.hooks.libraries.prebuild" , ".pattern" , false ); err != nil {
371
+ return err
372
+ }
373
+ b .Progress .CompleteStep ()
374
+ b .Progress .PushProgress ()
375
+
376
+ if err := b .RemoveUnusedCompiledLibraries (detector .ImportedLibraries ()); err != nil {
377
+ return err
378
+ }
379
+ b .Progress .CompleteStep ()
380
+ b .Progress .PushProgress ()
381
+
382
+ if err := b .BuildLibraries (detector .IncludeFolders (), detector .ImportedLibraries ()); err != nil {
383
+ return err
384
+ }
385
+ b .Progress .CompleteStep ()
386
+ b .Progress .PushProgress ()
387
+
388
+ if err := b .RunRecipe ("recipe.hooks.libraries.postbuild" , ".pattern" , true ); err != nil {
389
+ return err
390
+ }
391
+ b .Progress .CompleteStep ()
392
+ b .Progress .PushProgress ()
393
+
394
+ b .logIfVerbose (false , tr ("Compiling core..." ))
395
+ if err := b .RunRecipe ("recipe.hooks.core.prebuild" , ".pattern" , false ); err != nil {
396
+ return err
397
+ }
398
+ b .Progress .CompleteStep ()
399
+ b .Progress .PushProgress ()
400
+
401
+ if err := b .BuildCore (); err != nil {
402
+ return err
403
+ }
404
+ b .Progress .CompleteStep ()
405
+ b .Progress .PushProgress ()
406
+
407
+ if err := b .RunRecipe ("recipe.hooks.core.postbuild" , ".pattern" , true ); err != nil {
408
+ return err
409
+ }
410
+ b .Progress .CompleteStep ()
411
+ b .Progress .PushProgress ()
412
+
413
+ b .logIfVerbose (false , tr ("Linking everything together..." ))
414
+ if err := b .RunRecipe ("recipe.hooks.linking.prelink" , ".pattern" , false ); err != nil {
415
+ return err
416
+ }
417
+ b .Progress .CompleteStep ()
418
+ b .Progress .PushProgress ()
419
+
420
+ if err := b .Link (); err != nil {
421
+ return err
422
+ }
423
+ b .Progress .CompleteStep ()
424
+ b .Progress .PushProgress ()
425
+
426
+ if err := b .RunRecipe ("recipe.hooks.linking.postlink" , ".pattern" , true ); err != nil {
427
+ return err
428
+ }
429
+ b .Progress .CompleteStep ()
430
+ b .Progress .PushProgress ()
431
+
432
+ if err := b .RunRecipe ("recipe.hooks.objcopy.preobjcopy" , ".pattern" , false ); err != nil {
433
+ return err
434
+ }
435
+ b .Progress .CompleteStep ()
436
+ b .Progress .PushProgress ()
437
+
438
+ if err := b .RunRecipe ("recipe.objcopy." , ".pattern" , true ); err != nil {
439
+ return err
440
+ }
441
+ b .Progress .CompleteStep ()
442
+ b .Progress .PushProgress ()
443
+
444
+ if err := b .RunRecipe ("recipe.hooks.objcopy.postobjcopy" , ".pattern" , true ); err != nil {
445
+ return err
446
+ }
447
+ b .Progress .CompleteStep ()
448
+ b .Progress .PushProgress ()
449
+
450
+ if err := b .MergeSketchWithBootloader (); err != nil {
451
+ return err
452
+ }
453
+ b .Progress .CompleteStep ()
454
+ b .Progress .PushProgress ()
455
+
456
+ if err := b .RunRecipe ("recipe.hooks.postbuild" , ".pattern" , true ); err != nil {
457
+ return err
458
+ }
459
+ b .Progress .CompleteStep ()
460
+ b .Progress .PushProgress ()
461
+
462
+ if b .compilationDatabase != nil {
463
+ b .compilationDatabase .SaveToFile ()
464
+ }
465
+ return nil
466
+ }
0 commit comments