@@ -25,7 +25,6 @@ import (
2525 "sync"
2626
2727 "github.com/arduino/arduino-cli/legacy/builder/constants"
28- "github.com/arduino/arduino-cli/legacy/builder/i18n"
2928 "github.com/arduino/arduino-cli/legacy/builder/types"
3029 "github.com/arduino/arduino-cli/legacy/builder/utils"
3130 "github.com/arduino/go-paths-helper"
@@ -249,7 +248,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
249248 return nil , errors .WithStack (err )
250249 }
251250 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 */ )
253252 if err != nil {
254253 return nil , errors .WithStack (err )
255254 }
@@ -480,46 +479,57 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
480479 properties .SetPath (constants .BUILD_PROPERTIES_ARCHIVE_FILE_PATH , archiveFilePath )
481480 properties .SetPath (constants .BUILD_PROPERTIES_OBJECT_FILE , objectFile )
482481
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 {
484483 return nil , errors .WithStack (err )
485484 }
486485 }
487486
488487 return archiveFilePath , nil
489488}
490489
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 ) {
492491 // See util.ExecCommand for stdout/stderr arguments
493- command , err := PrepareCommandForRecipe (ctx , buildProperties , recipe , removeUnsetProperties )
492+ command , err := PrepareCommandForRecipe (buildProperties , recipe , false )
494493 if err != nil {
495- return nil , nil , errors .WithStack (err )
494+ return nil , nil , nil , errors .WithStack (err )
496495 }
497496
498- return utils .ExecCommand (ctx , command , stdout , stderr )
497+ outbytes , errbytes , err := utils .ExecCommand (ctx , command , stdout , stderr )
498+ return command , outbytes , errbytes , err
499499}
500500
501501const COMMANDLINE_LIMIT = 30000
502502
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 ) {
505504 pattern := buildProperties .Get (recipe )
506505 if pattern == "" {
507- return nil , i18n . ErrorfWithLogger ( logger , constants . MSG_PATTERN_MISSING , recipe )
506+ return nil , errors . Errorf ( "%s pattern is missing" , recipe )
508507 }
509508
510- var err error
511509 commandLine := buildProperties .ExpandPropsInString (pattern )
512510 if removeUnsetProperties {
513511 commandLine = properties .DeleteUnexpandedPropsFromString (commandLine )
514512 }
515513
516- relativePath := ""
514+ command , err := utils . PrepareCommand ( commandLine )
517515
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
518519 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
520531 }
521532
522- command , err := utils .PrepareCommand (commandLine , logger , relativePath )
523533 if err != nil {
524534 return nil , errors .WithStack (err )
525535 }
0 commit comments