@@ -19,15 +19,20 @@ import (
19
19
"errors"
20
20
"fmt"
21
21
"io"
22
+ "os"
23
+ "path/filepath"
24
+ "strings"
22
25
23
26
"github.com/arduino/arduino-cli/arduino/builder/internal/compilation"
24
27
"github.com/arduino/arduino-cli/arduino/builder/internal/detector"
25
28
"github.com/arduino/arduino-cli/arduino/builder/internal/logger"
26
29
"github.com/arduino/arduino-cli/arduino/builder/internal/progress"
30
+ "github.com/arduino/arduino-cli/arduino/builder/internal/utils"
27
31
"github.com/arduino/arduino-cli/arduino/cores"
28
32
"github.com/arduino/arduino-cli/arduino/libraries"
29
33
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
30
34
"github.com/arduino/arduino-cli/arduino/sketch"
35
+ "github.com/arduino/arduino-cli/executils"
31
36
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
32
37
"github.com/arduino/go-paths-helper"
33
38
"github.com/arduino/go-properties-orderedmap"
@@ -268,19 +273,16 @@ func (b *Builder) preprocess() error {
268
273
return err
269
274
}
270
275
b .Progress .CompleteStep ()
271
- b .Progress .PushProgress ()
272
276
273
277
if err := b .RunRecipe ("recipe.hooks.prebuild" , ".pattern" , false ); err != nil {
274
278
return err
275
279
}
276
280
b .Progress .CompleteStep ()
277
- b .Progress .PushProgress ()
278
281
279
282
if err := b .prepareSketchBuildPath (); err != nil {
280
283
return err
281
284
}
282
285
b .Progress .CompleteStep ()
283
- b .Progress .PushProgress ()
284
286
285
287
b .logIfVerbose (false , tr ("Detecting libraries used..." ))
286
288
err := b .libsDetector .FindIncludes (
@@ -297,18 +299,15 @@ func (b *Builder) preprocess() error {
297
299
return err
298
300
}
299
301
b .Progress .CompleteStep ()
300
- b .Progress .PushProgress ()
301
302
302
303
b .warnAboutArchIncompatibleLibraries (b .libsDetector .ImportedLibraries ())
303
304
b .Progress .CompleteStep ()
304
- b .Progress .PushProgress ()
305
305
306
306
b .logIfVerbose (false , tr ("Generating function prototypes..." ))
307
307
if err := b .preprocessSketch (b .libsDetector .IncludeFolders ()); err != nil {
308
308
return err
309
309
}
310
310
b .Progress .CompleteStep ()
311
- b .Progress .PushProgress ()
312
311
313
312
return nil
314
313
}
@@ -337,11 +336,9 @@ func (b *Builder) Build() error {
337
336
338
337
b .libsDetector .PrintUsedAndNotUsedLibraries (buildErr != nil )
339
338
b .Progress .CompleteStep ()
340
- b .Progress .PushProgress ()
341
339
342
340
b .printUsedLibraries (b .libsDetector .ImportedLibraries ())
343
341
b .Progress .CompleteStep ()
344
- b .Progress .PushProgress ()
345
342
346
343
if buildErr != nil {
347
344
return buildErr
@@ -350,13 +347,11 @@ func (b *Builder) Build() error {
350
347
return err
351
348
}
352
349
b .Progress .CompleteStep ()
353
- b .Progress .PushProgress ()
354
350
355
351
if err := b .size (); err != nil {
356
352
return err
357
353
}
358
354
b .Progress .CompleteStep ()
359
- b .Progress .PushProgress ()
360
355
361
356
return nil
362
357
}
@@ -368,115 +363,155 @@ func (b *Builder) build() error {
368
363
return err
369
364
}
370
365
b .Progress .CompleteStep ()
371
- b .Progress .PushProgress ()
372
366
373
- if err := b .BuildSketch (b .libsDetector .IncludeFolders ()); err != nil {
367
+ if err := b .buildSketch (b .libsDetector .IncludeFolders ()); err != nil {
374
368
return err
375
369
}
376
370
b .Progress .CompleteStep ()
377
- b .Progress .PushProgress ()
378
371
379
372
if err := b .RunRecipe ("recipe.hooks.sketch.postbuild" , ".pattern" , true ); err != nil {
380
373
return err
381
374
}
382
375
b .Progress .CompleteStep ()
383
- b .Progress .PushProgress ()
384
376
385
377
b .logIfVerbose (false , tr ("Compiling libraries..." ))
386
378
if err := b .RunRecipe ("recipe.hooks.libraries.prebuild" , ".pattern" , false ); err != nil {
387
379
return err
388
380
}
389
381
b .Progress .CompleteStep ()
390
- b .Progress .PushProgress ()
391
382
392
383
if err := b .removeUnusedCompiledLibraries (b .libsDetector .ImportedLibraries ()); err != nil {
393
384
return err
394
385
}
395
386
b .Progress .CompleteStep ()
396
- b .Progress .PushProgress ()
397
387
398
388
if err := b .buildLibraries (b .libsDetector .IncludeFolders (), b .libsDetector .ImportedLibraries ()); err != nil {
399
389
return err
400
390
}
401
391
b .Progress .CompleteStep ()
402
- b .Progress .PushProgress ()
403
392
404
393
if err := b .RunRecipe ("recipe.hooks.libraries.postbuild" , ".pattern" , true ); err != nil {
405
394
return err
406
395
}
407
396
b .Progress .CompleteStep ()
408
- b .Progress .PushProgress ()
409
397
410
398
b .logIfVerbose (false , tr ("Compiling core..." ))
411
399
if err := b .RunRecipe ("recipe.hooks.core.prebuild" , ".pattern" , false ); err != nil {
412
400
return err
413
401
}
414
402
b .Progress .CompleteStep ()
415
- b .Progress .PushProgress ()
416
403
417
404
if err := b .buildCore (); err != nil {
418
405
return err
419
406
}
420
407
b .Progress .CompleteStep ()
421
- b .Progress .PushProgress ()
422
408
423
409
if err := b .RunRecipe ("recipe.hooks.core.postbuild" , ".pattern" , true ); err != nil {
424
410
return err
425
411
}
426
412
b .Progress .CompleteStep ()
427
- b .Progress .PushProgress ()
428
413
429
414
b .logIfVerbose (false , tr ("Linking everything together..." ))
430
415
if err := b .RunRecipe ("recipe.hooks.linking.prelink" , ".pattern" , false ); err != nil {
431
416
return err
432
417
}
433
418
b .Progress .CompleteStep ()
434
- b .Progress .PushProgress ()
435
419
436
420
if err := b .link (); err != nil {
437
421
return err
438
422
}
439
423
b .Progress .CompleteStep ()
440
- b .Progress .PushProgress ()
441
424
442
425
if err := b .RunRecipe ("recipe.hooks.linking.postlink" , ".pattern" , true ); err != nil {
443
426
return err
444
427
}
445
428
b .Progress .CompleteStep ()
446
- b .Progress .PushProgress ()
447
429
448
430
if err := b .RunRecipe ("recipe.hooks.objcopy.preobjcopy" , ".pattern" , false ); err != nil {
449
431
return err
450
432
}
451
433
b .Progress .CompleteStep ()
452
- b .Progress .PushProgress ()
453
434
454
435
if err := b .RunRecipe ("recipe.objcopy." , ".pattern" , true ); err != nil {
455
436
return err
456
437
}
457
438
b .Progress .CompleteStep ()
458
- b .Progress .PushProgress ()
459
439
460
440
if err := b .RunRecipe ("recipe.hooks.objcopy.postobjcopy" , ".pattern" , true ); err != nil {
461
441
return err
462
442
}
463
443
b .Progress .CompleteStep ()
464
- b .Progress .PushProgress ()
465
444
466
- if err := b .MergeSketchWithBootloader (); err != nil {
445
+ if err := b .mergeSketchWithBootloader (); err != nil {
467
446
return err
468
447
}
469
448
b .Progress .CompleteStep ()
470
- b .Progress .PushProgress ()
471
449
472
450
if err := b .RunRecipe ("recipe.hooks.postbuild" , ".pattern" , true ); err != nil {
473
451
return err
474
452
}
475
453
b .Progress .CompleteStep ()
476
- b .Progress .PushProgress ()
477
454
478
455
if b .compilationDatabase != nil {
479
456
b .compilationDatabase .SaveToFile ()
480
457
}
481
458
return nil
482
459
}
460
+
461
+ func (b * Builder ) prepareCommandForRecipe (buildProperties * properties.Map , recipe string , removeUnsetProperties bool ) (* executils.Process , error ) {
462
+ pattern := buildProperties .Get (recipe )
463
+ if pattern == "" {
464
+ return nil , fmt .Errorf (tr ("%[1]s pattern is missing" ), recipe )
465
+ }
466
+
467
+ commandLine := buildProperties .ExpandPropsInString (pattern )
468
+ if removeUnsetProperties {
469
+ commandLine = properties .DeleteUnexpandedPropsFromString (commandLine )
470
+ }
471
+
472
+ parts , err := properties .SplitQuotedString (commandLine , `"'` , false )
473
+ if err != nil {
474
+ return nil , err
475
+ }
476
+
477
+ // if the overall commandline is too long for the platform
478
+ // try reducing the length by making the filenames relative
479
+ // and changing working directory to build.path
480
+ var relativePath string
481
+ if len (commandLine ) > 30000 {
482
+ relativePath = buildProperties .Get ("build.path" )
483
+ for i , arg := range parts {
484
+ if _ , err := os .Stat (arg ); os .IsNotExist (err ) {
485
+ continue
486
+ }
487
+ rel , err := filepath .Rel (relativePath , arg )
488
+ if err == nil && ! strings .Contains (rel , ".." ) && len (rel ) < len (arg ) {
489
+ parts [i ] = rel
490
+ }
491
+ }
492
+ }
493
+
494
+ command , err := executils .NewProcess (nil , parts ... )
495
+ if err != nil {
496
+ return nil , err
497
+ }
498
+ if relativePath != "" {
499
+ command .SetDir (relativePath )
500
+ }
501
+
502
+ return command , nil
503
+ }
504
+
505
+ func (b * Builder ) execCommand (command * executils.Process ) error {
506
+ if b .logger .Verbose () {
507
+ b .logger .Info (utils .PrintableCommand (command .GetArgs ()))
508
+ command .RedirectStdoutTo (b .logger .Stdout ())
509
+ }
510
+ command .RedirectStderrTo (b .logger .Stderr ())
511
+
512
+ if err := command .Start (); err != nil {
513
+ return err
514
+ }
515
+
516
+ return command .Wait ()
517
+ }
0 commit comments