@@ -25,7 +25,6 @@ import (
25
25
"sync"
26
26
27
27
"github.com/arduino/arduino-cli/legacy/builder/constants"
28
- "github.com/arduino/arduino-cli/legacy/builder/i18n"
29
28
"github.com/arduino/arduino-cli/legacy/builder/types"
30
29
"github.com/arduino/arduino-cli/legacy/builder/utils"
31
30
"github.com/arduino/go-paths-helper"
@@ -249,7 +248,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
249
248
return nil , errors .WithStack (err )
250
249
}
251
250
if ! objIsUpToDate {
252
- _ , _ , err = ExecRecipe (ctx , properties , recipe , false /* stdout */ , utils .ShowIfVerbose /* stderr */ , utils . Show )
251
+ _ , _ , _ , err : = ExecRecipe (ctx , properties , recipe , utils . ShowIfVerbose /* stdout */ , utils .Show /* stderr */ )
253
252
if err != nil {
254
253
return nil , errors .WithStack (err )
255
254
}
@@ -480,46 +479,57 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
480
479
properties .SetPath (constants .BUILD_PROPERTIES_ARCHIVE_FILE_PATH , archiveFilePath )
481
480
properties .SetPath (constants .BUILD_PROPERTIES_OBJECT_FILE , objectFile )
482
481
483
- if _ , _ , err := ExecRecipe (ctx , properties , constants .RECIPE_AR_PATTERN , false /* stdout */ , utils .ShowIfVerbose /* stderr */ , utils . Show ); err != nil {
482
+ if _ , _ , _ , err := ExecRecipe (ctx , properties , constants .RECIPE_AR_PATTERN , utils . ShowIfVerbose /* stdout */ , utils .Show /* stderr */ ); err != nil {
484
483
return nil , errors .WithStack (err )
485
484
}
486
485
}
487
486
488
487
return archiveFilePath , nil
489
488
}
490
489
491
- func ExecRecipe (ctx * types.Context , buildProperties * properties.Map , recipe string , removeUnsetProperties bool , stdout int , stderr int ) ([]byte , []byte , error ) {
490
+ func ExecRecipe (ctx * types.Context , buildProperties * properties.Map , recipe string , stdout int , stderr int ) (* exec. Cmd , []byte , []byte , error ) {
492
491
// See util.ExecCommand for stdout/stderr arguments
493
- command , err := PrepareCommandForRecipe (ctx , buildProperties , recipe , removeUnsetProperties )
492
+ command , err := PrepareCommandForRecipe (buildProperties , recipe , false )
494
493
if err != nil {
495
- return nil , nil , errors .WithStack (err )
494
+ return nil , nil , nil , errors .WithStack (err )
496
495
}
497
496
498
- return utils .ExecCommand (ctx , command , stdout , stderr )
497
+ outbytes , errbytes , err := utils .ExecCommand (ctx , command , stdout , stderr )
498
+ return command , outbytes , errbytes , err
499
499
}
500
500
501
501
const COMMANDLINE_LIMIT = 30000
502
502
503
- func PrepareCommandForRecipe (ctx * types.Context , buildProperties * properties.Map , recipe string , removeUnsetProperties bool ) (* exec.Cmd , error ) {
504
- logger := ctx .GetLogger ()
503
+ func PrepareCommandForRecipe (buildProperties * properties.Map , recipe string , removeUnsetProperties bool ) (* exec.Cmd , error ) {
505
504
pattern := buildProperties .Get (recipe )
506
505
if pattern == "" {
507
- return nil , i18n . ErrorfWithLogger ( logger , constants . MSG_PATTERN_MISSING , recipe )
506
+ return nil , errors . Errorf ( "%s pattern is missing" , recipe )
508
507
}
509
508
510
- var err error
511
509
commandLine := buildProperties .ExpandPropsInString (pattern )
512
510
if removeUnsetProperties {
513
511
commandLine = properties .DeleteUnexpandedPropsFromString (commandLine )
514
512
}
515
513
516
- relativePath := ""
514
+ command , err := utils . PrepareCommand ( commandLine )
517
515
516
+ // if the overall commandline is too long for the platform
517
+ // try reducing the length by making the filenames relative
518
+ // and changing working directory to build.path
518
519
if len (commandLine ) > COMMANDLINE_LIMIT {
519
- relativePath = buildProperties .Get ("build.path" )
520
+ relativePath := buildProperties .Get ("build.path" )
521
+ for i , arg := range command .Args {
522
+ if _ , err := os .Stat (arg ); os .IsNotExist (err ) {
523
+ continue
524
+ }
525
+ rel , err := filepath .Rel (relativePath , arg )
526
+ if err == nil && ! strings .Contains (rel , ".." ) && len (rel ) < len (arg ) {
527
+ command .Args [i ] = rel
528
+ }
529
+ }
530
+ command .Dir = relativePath
520
531
}
521
532
522
- command , err := utils .PrepareCommand (commandLine , logger , relativePath )
523
533
if err != nil {
524
534
return nil , errors .WithStack (err )
525
535
}
0 commit comments