Skip to content

Commit 5366520

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 f4cabbb commit 5366520

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
"github.com/arduino/arduino-cli/pkg/fqbn"
3231
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3332
"github.com/arduino/go-properties-orderedmap"
@@ -265,10 +264,7 @@ func findMonitorAndSettingsForProtocolAndBoard(pme *packagemanager.Explorer, pro
265264
} else if recipe, ok := boardPlatform.MonitorsDevRecipes[protocol]; ok {
266265
// If we have a recipe we must resolve it
267266
cmdLine := boardProperties.ExpandPropsInString(recipe)
268-
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
269-
if err != nil {
270-
return nil, nil, &cmderrors.InvalidArgumentError{Message: i18n.Tr("Invalid recipe in platform.txt"), Cause: err}
271-
}
267+
cmdArgs, _ := properties.SplitQuotedString(cmdLine, `"'`, false)
272268
id := fmt.Sprintf("%s-%s", boardPlatform, protocol)
273269
return pluggableMonitor.New(id, cmdArgs...), boardSettings, nil
274270
}

Diff for: commands/service_upload.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,7 @@ func runTool(ctx context.Context, recipeID string, props *properties.Map, outStr
720720
return errors.New(i18n.Tr("no upload port provided"))
721721
}
722722
cmdLine := props.ExpandPropsInString(recipe)
723-
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
724-
if err != nil {
725-
return errors.New(i18n.Tr("invalid recipe '%[1]s': %[2]s", recipe, err))
726-
}
723+
cmdArgs, _ := properties.SplitQuotedString(cmdLine, `"'`, false)
727724

728725
// Run Tool
729726
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
@@ -492,29 +492,26 @@ func (b *Builder) prepareCommandForRecipe(buildProperties *properties.Map, recip
492492
commandLine = properties.DeleteUnexpandedPropsFromString(commandLine)
493493
}
494494

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

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

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

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)