@@ -18,14 +18,14 @@ package builder_utils
18
18
import (
19
19
"fmt"
20
20
"os"
21
- "os/exec"
22
21
"path/filepath"
23
22
"runtime"
24
23
"strings"
25
24
"sync"
26
25
27
26
bUtils "github.com/arduino/arduino-cli/arduino/builder/utils"
28
27
"github.com/arduino/arduino-cli/arduino/globals"
28
+ "github.com/arduino/arduino-cli/executils"
29
29
"github.com/arduino/arduino-cli/i18n"
30
30
"github.com/arduino/arduino-cli/legacy/builder/constants"
31
31
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -173,7 +173,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
173
173
return nil , errors .WithStack (err )
174
174
}
175
175
176
- command , err := PrepareCommandForRecipe (properties , recipe , false , ctx . PackageManager . GetEnvVarsForSpawnedProcess () )
176
+ command , err := PrepareCommandForRecipe (properties , recipe , false )
177
177
if err != nil {
178
178
return nil , errors .WithStack (err )
179
179
}
@@ -244,7 +244,7 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
244
244
properties .SetPath (constants .BUILD_PROPERTIES_ARCHIVE_FILE_PATH , archiveFilePath )
245
245
properties .SetPath (constants .BUILD_PROPERTIES_OBJECT_FILE , objectFile )
246
246
247
- command , err := PrepareCommandForRecipe (properties , constants .RECIPE_AR_PATTERN , false , ctx . PackageManager . GetEnvVarsForSpawnedProcess () )
247
+ command , err := PrepareCommandForRecipe (properties , constants .RECIPE_AR_PATTERN , false )
248
248
if err != nil {
249
249
return nil , errors .WithStack (err )
250
250
}
@@ -260,7 +260,7 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
260
260
261
261
const COMMANDLINE_LIMIT = 30000
262
262
263
- func PrepareCommandForRecipe (buildProperties * properties.Map , recipe string , removeUnsetProperties bool , toolEnv [] string ) (* exec. Cmd , error ) {
263
+ func PrepareCommandForRecipe (buildProperties * properties.Map , recipe string , removeUnsetProperties bool ) (* executils. Process , error ) {
264
264
pattern := buildProperties .Get (recipe )
265
265
if pattern == "" {
266
266
return nil , errors .Errorf (tr ("%[1]s pattern is missing" ), recipe )
@@ -275,24 +275,30 @@ func PrepareCommandForRecipe(buildProperties *properties.Map, recipe string, rem
275
275
if err != nil {
276
276
return nil , errors .WithStack (err )
277
277
}
278
- command := exec .Command (parts [0 ], parts [1 :]... )
279
- command .Env = append (os .Environ (), toolEnv ... )
280
278
281
279
// if the overall commandline is too long for the platform
282
280
// try reducing the length by making the filenames relative
283
281
// and changing working directory to build.path
282
+ var relativePath string
284
283
if len (commandLine ) > COMMANDLINE_LIMIT {
285
- relativePath : = buildProperties .Get ("build.path" )
286
- for i , arg := range command . Args {
284
+ relativePath = buildProperties .Get ("build.path" )
285
+ for i , arg := range parts {
287
286
if _ , err := os .Stat (arg ); os .IsNotExist (err ) {
288
287
continue
289
288
}
290
289
rel , err := filepath .Rel (relativePath , arg )
291
290
if err == nil && ! strings .Contains (rel , ".." ) && len (rel ) < len (arg ) {
292
- command . Args [i ] = rel
291
+ parts [i ] = rel
293
292
}
294
293
}
295
- command .Dir = relativePath
294
+ }
295
+
296
+ command , err := executils .NewProcess (nil , parts ... )
297
+ if err != nil {
298
+ return nil , errors .WithStack (err )
299
+ }
300
+ if relativePath != "" {
301
+ command .SetDir (relativePath )
296
302
}
297
303
298
304
return command , nil
0 commit comments