Skip to content

Commit bfe6d8c

Browse files
committed
Simplify use of properties.SplitQuotedString
The new release of the library allow ignoring the returned error. arduino/go-properties-orderedmap#42
1 parent 86bdc5f commit bfe6d8c

File tree

7 files changed

+15
-39
lines changed

7 files changed

+15
-39
lines changed

Diff for: commands/service_monitor.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/arduino/arduino-cli/internal/arduino/cores"
2828
"github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager"
2929
pluggableMonitor "github.com/arduino/arduino-cli/internal/arduino/monitor"
30-
"github.com/arduino/arduino-cli/internal/i18n"
3130
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3231
"github.com/arduino/go-properties-orderedmap"
3332
"github.com/djherbis/buffer"
@@ -264,10 +263,7 @@ func findMonitorAndSettingsForProtocolAndBoard(pme *packagemanager.Explorer, pro
264263
} else if recipe, ok := boardPlatform.MonitorsDevRecipes[protocol]; ok {
265264
// If we have a recipe we must resolve it
266265
cmdLine := boardProperties.ExpandPropsInString(recipe)
267-
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
268-
if err != nil {
269-
return nil, nil, &cmderrors.InvalidArgumentError{Message: i18n.Tr("Invalid recipe in platform.txt"), Cause: err}
270-
}
266+
cmdArgs, _ := properties.SplitQuotedString(cmdLine, `"'`, false)
271267
id := fmt.Sprintf("%s-%s", boardPlatform, protocol)
272268
return pluggableMonitor.New(id, cmdArgs...), boardSettings, nil
273269
}

Diff for: commands/service_upload.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,7 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri
703703
return errors.New(i18n.Tr("no upload port provided"))
704704
}
705705
cmdLine := props.ExpandPropsInString(recipe)
706-
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
707-
if err != nil {
708-
return errors.New(i18n.Tr("invalid recipe '%[1]s': %[2]s", recipe, err))
709-
}
706+
cmdArgs, _ := properties.SplitQuotedString(cmdLine, `"'`, false)
710707

711708
// Run Tool
712709
logrus.WithField("phase", "upload").Tracef("Executing upload tool: %s", cmdLine)

Diff for: internal/arduino/builder/builder.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -493,29 +493,26 @@ func (b *Builder) prepareCommandForRecipe(buildProperties *properties.Map, recip
493493
commandLine = properties.DeleteUnexpandedPropsFromString(commandLine)
494494
}
495495

496-
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
497-
if err != nil {
498-
return nil, err
499-
}
496+
args, _ := properties.SplitQuotedString(commandLine, `"'`, false)
500497

501498
// if the overall commandline is too long for the platform
502499
// try reducing the length by making the filenames relative
503500
// and changing working directory to build.path
504501
var relativePath string
505502
if len(commandLine) > 30000 {
506503
relativePath = buildProperties.Get("build.path")
507-
for i, arg := range parts {
504+
for i, arg := range args {
508505
if _, err := os.Stat(arg); os.IsNotExist(err) {
509506
continue
510507
}
511508
rel, err := filepath.Rel(relativePath, arg)
512509
if err == nil && !strings.Contains(rel, "..") && len(rel) < len(arg) {
513-
parts[i] = rel
510+
args[i] = rel
514511
}
515512
}
516513
}
517514

518-
command, err := paths.NewProcess(b.toolEnv, parts...)
515+
command, err := paths.NewProcess(b.toolEnv, args...)
519516
if err != nil {
520517
return nil, err
521518
}

Diff for: internal/arduino/builder/internal/preprocessor/arduino_preprocessor.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,14 @@ func PreprocessSketchWithArduinoPreprocessor(
6666
}
6767

6868
commandLine := arduinoPreprocessorProperties.ExpandPropsInString(pattern)
69-
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
70-
if err != nil {
71-
return nil, err
72-
}
73-
74-
command, err := paths.NewProcess(nil, parts...)
69+
args, _ := properties.SplitQuotedString(commandLine, `"'`, false)
70+
command, err := paths.NewProcess(nil, args...)
7571
if err != nil {
7672
return nil, err
7773
}
7874
if runtime.GOOS == "windows" {
7975
// chdir in the uppermost directory to avoid UTF-8 bug in clang (https://github.com/arduino/arduino-preprocessor/issues/2)
80-
command.SetDir(filepath.VolumeName(parts[0]) + "/")
76+
command.SetDir(filepath.VolumeName(args[0]) + "/")
8177
}
8278

8379
verboseOut.WriteString(commandLine)

Diff for: internal/arduino/builder/internal/preprocessor/ctags.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,15 @@ func RunCTags(ctx context.Context, sourceFile *paths.Path, buildProperties *prop
194194
}
195195

196196
commandLine := ctagsBuildProperties.ExpandPropsInString(pattern)
197-
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
198-
if err != nil {
199-
return nil, nil, err
200-
}
201-
proc, err := paths.NewProcess(nil, parts...)
197+
args, _ := properties.SplitQuotedString(commandLine, `"'`, false)
198+
proc, err := paths.NewProcess(nil, args...)
202199
if err != nil {
203200
return nil, nil, err
204201
}
205202
stdout, stderr, err := proc.RunAndCaptureOutput(ctx)
206203

207204
// Append ctags arguments to stderr
208-
args := fmt.Sprintln(strings.Join(parts, " "))
209-
stderr = append([]byte(args), stderr...)
205+
stderr = append([]byte(fmt.Sprintln(strings.Join(args, " "))), stderr...)
210206
return stdout, stderr, err
211207
}
212208

Diff for: internal/arduino/builder/internal/preprocessor/gcc.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ func GCC(
6565

6666
commandLine := gccBuildProperties.ExpandPropsInString(pattern)
6767
commandLine = properties.DeleteUnexpandedPropsFromString(commandLine)
68-
args, err := properties.SplitQuotedString(commandLine, `"'`, false)
69-
if err != nil {
70-
return nil, err
71-
}
68+
args, _ := properties.SplitQuotedString(commandLine, `"'`, false)
7269

7370
// Remove -MMD argument if present. Leaving it will make gcc try
7471
// to create a /dev/null.d dependency file, which won't work.

Diff for: internal/arduino/cores/packagemanager/loader.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,8 @@ func (pme *Explorer) loadDiscoveries(release *cores.PlatformRelease) []error {
721721
}
722722

723723
cmd := configuration.ExpandPropsInString(pattern)
724-
if cmdArgs, err := properties.SplitQuotedString(cmd, `"'`, true); err != nil {
725-
merr = append(merr, err)
726-
} else {
727-
pme.discoveryManager.Add(discoveryID, cmdArgs...)
728-
}
724+
cmdArgs, _ := properties.SplitQuotedString(cmd, `"'`, true)
725+
pme.discoveryManager.Add(discoveryID, cmdArgs...)
729726
}
730727

731728
return merr

0 commit comments

Comments
 (0)