Skip to content

Commit e65eb34

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 954633c commit e65eb34

File tree

10 files changed

+19
-43
lines changed

10 files changed

+19
-43
lines changed

Diff for: .licenses/go/github.com/arduino/go-properties-orderedmap.dep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: github.com/arduino/go-properties-orderedmap
3-
version: v1.8.0
3+
version: v1.8.1
44
type: go
55
summary: Package properties is a library for handling maps of hierarchical properties.
66
homepage: https://pkg.go.dev/github.com/arduino/go-properties-orderedmap

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: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1
88
require (
99
github.com/ProtonMail/go-crypto v1.1.0-alpha.0
1010
github.com/arduino/go-paths-helper v1.12.0
11-
github.com/arduino/go-properties-orderedmap v1.8.0
11+
github.com/arduino/go-properties-orderedmap v1.8.1
1212
github.com/arduino/go-serial-utils v0.1.2
1313
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1414
github.com/arduino/go-win32-utils v1.0.0

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU
1313
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
1414
github.com/arduino/go-paths-helper v1.12.0 h1:xizOQtI9iHdl19qXd1EmWg5i9W//2bOCOYwlNv8F61E=
1515
github.com/arduino/go-paths-helper v1.12.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM=
16-
github.com/arduino/go-properties-orderedmap v1.8.0 h1:wEfa6hHdpezrVOh787OmClsf/Kd8qB+zE3P2Xbrn0CQ=
17-
github.com/arduino/go-properties-orderedmap v1.8.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
16+
github.com/arduino/go-properties-orderedmap v1.8.1 h1:nU5S6cXPwMoxZs4ORw61wPTALNfriIduvNB4cxTmNYM=
17+
github.com/arduino/go-properties-orderedmap v1.8.1/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
1818
github.com/arduino/go-serial-utils v0.1.2 h1:MRFwME4w/uaVkJ1R+wzz4KSbI9cF9IDVrYorazvjpTk=
1919
github.com/arduino/go-serial-utils v0.1.2/go.mod h1:kzIsNPgz8DFAd1sAFKve4ubxrdGcwQ4XzvRLlztsgnE=
2020
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=

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)