Skip to content

Commit 785e300

Browse files
committed
Use relative paths if commandline is too long
1 parent b33f583 commit 785e300

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

Diff for: src/arduino.cc/builder/builder_utils/utils.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ func ExecRecipe(properties properties.Map, recipe string, removeUnsetProperties
418418
return bytes, i18n.WrapError(err)
419419
}
420420

421+
const COMMANDLINE_LIMIT = 32000
422+
421423
func PrepareCommandForRecipe(buildProperties properties.Map, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
422424
pattern := buildProperties[recipe]
423425
if pattern == constants.EMPTY_STRING {
@@ -433,7 +435,13 @@ func PrepareCommandForRecipe(buildProperties properties.Map, recipe string, remo
433435
}
434436
}
435437

436-
command, err := utils.PrepareCommand(commandLine, logger)
438+
relativePath := ""
439+
440+
if len(commandLine) > COMMANDLINE_LIMIT {
441+
relativePath = buildProperties[constants.BUILD_PROPERTIES_BUILD_PATH]
442+
}
443+
444+
command, err := utils.PrepareCommand(commandLine, logger, relativePath)
437445
if err != nil {
438446
return nil, i18n.WrapError(err)
439447
}

Diff for: src/arduino.cc/builder/ctags_runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *CTagsRunner) Run(ctx *types.Context) error {
5656
}
5757

5858
commandLine := properties.ExpandPropsInString(pattern)
59-
command, err := utils.PrepareCommand(commandLine, logger)
59+
command, err := utils.PrepareCommand(commandLine, logger, "")
6060
if err != nil {
6161
return i18n.WrapError(err)
6262
}

Diff for: src/arduino.cc/builder/preprocess_sketch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error {
8888
}
8989

9090
commandLine := properties.ExpandPropsInString(pattern)
91-
command, err := utils.PrepareCommand(commandLine, logger)
91+
command, err := utils.PrepareCommand(commandLine, logger, "")
9292
if err != nil {
9393
return i18n.WrapError(err)
9494
}

Diff for: src/arduino.cc/builder/utils/utils.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func TrimSpace(value string) string {
231231

232232
type argFilterFunc func(int, string, []string) bool
233233

234-
func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger) (*exec.Cmd, error) {
234+
func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger, relativePath string) (*exec.Cmd, error) {
235235
parts, err := ParseCommandLine(pattern, logger)
236236
if err != nil {
237237
return nil, i18n.WrapError(err)
@@ -241,19 +241,36 @@ func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18
241241
var args []string
242242
for idx, part := range parts {
243243
if filter(idx, part, parts) {
244+
// if relativePath is specified, the overall commandline is too long for the platform
245+
// try reducing the length by making the filenames relative
246+
// and changing working directory to build.path
247+
if relativePath != "" {
248+
if _, err := os.Stat(part); !os.IsNotExist(err) {
249+
tmp, err := filepath.Rel(relativePath, part)
250+
if err == nil {
251+
part = tmp
252+
}
253+
}
254+
}
244255
args = append(args, part)
245256
}
246257
}
247258

248-
return exec.Command(command, args...), nil
259+
cmd := exec.Command(command, args...)
260+
261+
if relativePath != "" {
262+
cmd.Dir = relativePath
263+
}
264+
265+
return cmd, nil
249266
}
250267

251268
func filterEmptyArg(_ int, arg string, _ []string) bool {
252269
return arg != constants.EMPTY_STRING
253270
}
254271

255-
func PrepareCommand(pattern string, logger i18n.Logger) (*exec.Cmd, error) {
256-
return PrepareCommandFilteredArgs(pattern, filterEmptyArg, logger)
272+
func PrepareCommand(pattern string, logger i18n.Logger, relativePath string) (*exec.Cmd, error) {
273+
return PrepareCommandFilteredArgs(pattern, filterEmptyArg, logger, relativePath)
257274
}
258275

259276
func MapHas(aMap map[string]interface{}, key string) bool {

0 commit comments

Comments
 (0)