Skip to content

Commit eea4010

Browse files
committed
Use github.com/arduino/go-properties-orderedmap for handling properties
1 parent a42ba9f commit eea4010

File tree

5 files changed

+27
-88
lines changed

5 files changed

+27
-88
lines changed

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/bcmi-labs/arduino-language-server
33
go 1.12
44

55
require (
6+
github.com/arduino/go-properties-orderedmap v1.4.0
67
github.com/gorilla/websocket v1.4.0 // indirect
78
github.com/pkg/errors v0.8.1
89
github.com/sourcegraph/go-lsp v0.0.0-20181119182933-0c7d621186c1

Diff for: go.sum

+11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
2+
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
3+
github.com/arduino/go-properties-orderedmap v1.4.0 h1:YEbbzPqm1gXWDM/Jaq8tlvmh09z2qeHPJTUw9/VA4Dk=
4+
github.com/arduino/go-properties-orderedmap v1.4.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
5+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
6+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
17
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
28
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
39
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
410
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
11+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
12+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
513
github.com/sourcegraph/go-lsp v0.0.0-20181119182933-0c7d621186c1 h1:O1d7nVzpGmP5pGAZBSlp9TSpjNwwI0xThxhPd9oVJuU=
614
github.com/sourcegraph/go-lsp v0.0.0-20181119182933-0c7d621186c1/go.mod h1:tpps84QRlOVVLYk5QpKYX8Tr289D1v/UTWDLqeguiqM=
715
github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a h1:jTZwOlrDhmk4Ez2vhWh7kA0eKUahp1lCO2uyM4fi/Qk=
816
github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a/go.mod h1:eESpbCslcLDs8j2D7IEdGVgul7xuk9odqDTaor30IUU=
17+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
18+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
19+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

Diff for: handler/builder.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"strings"
1212

13+
"github.com/arduino/go-properties-orderedmap"
1314
"github.com/pkg/errors"
1415
)
1516

@@ -142,7 +143,7 @@ func generateCompileFlags(tempDir, inoPath, sourcePath, fqbn string) (string, er
142143
err = logCommandErr(globalCliPath, output, err, errMsgFilter(tempDir))
143144
return "", err
144145
}
145-
properties, err := readProperties(bytes.NewReader(output))
146+
buildProps, err := properties.LoadFromBytes(output)
146147
if err != nil {
147148
return "", errors.Wrap(err, "Error while reading build properties.")
148149
}
@@ -154,7 +155,7 @@ func generateCompileFlags(tempDir, inoPath, sourcePath, fqbn string) (string, er
154155
defer outFile.Close()
155156

156157
printer := Printer{Writer: bufio.NewWriter(outFile)}
157-
printCompileFlags(properties, &printer, fqbn)
158+
printCompileFlags(buildProps, &printer, fqbn)
158159
printLibraryPaths(sourcePath, &printer)
159160
printer.Flush()
160161
return flagsPath, printer.Err
@@ -214,40 +215,40 @@ func copyIno2Cpp(inoCode string, cppPath string) (cppCode []byte, err error) {
214215
return
215216
}
216217

217-
func printCompileFlags(properties map[string]string, printer *Printer, fqbn string) {
218+
func printCompileFlags(buildProps *properties.Map, printer *Printer, fqbn string) {
218219
if strings.Contains(fqbn, ":avr:") {
219220
printer.Println("--target=avr")
220221
} else if strings.Contains(fqbn, ":sam:") {
221222
printer.Println("--target=arm-none-eabi")
222223
}
223-
cppFlags := expandProperty(properties, "compiler.cpp.flags")
224+
cppFlags := buildProps.ExpandPropsInString(buildProps.Get("compiler.cpp.flags"))
224225
printer.Println(splitFlags(cppFlags))
225-
mcu := expandProperty(properties, "build.mcu")
226+
mcu := buildProps.ExpandPropsInString(buildProps.Get("build.mcu"))
226227
if strings.Contains(fqbn, ":avr:") {
227228
printer.Println("-mmcu=", mcu)
228229
} else if strings.Contains(fqbn, ":sam:") {
229230
printer.Println("-mcpu=", mcu)
230231
}
231-
fcpu := expandProperty(properties, "build.f_cpu")
232+
fcpu := buildProps.ExpandPropsInString(buildProps.Get("build.f_cpu"))
232233
printer.Println("-DF_CPU=", fcpu)
233-
ideVersion := expandProperty(properties, "runtime.ide.version")
234+
ideVersion := buildProps.ExpandPropsInString(buildProps.Get("runtime.ide.version"))
234235
printer.Println("-DARDUINO=", ideVersion)
235-
board := expandProperty(properties, "build.board")
236+
board := buildProps.ExpandPropsInString(buildProps.Get("build.board"))
236237
printer.Println("-DARDUINO_", board)
237-
arch := expandProperty(properties, "build.arch")
238+
arch := buildProps.ExpandPropsInString(buildProps.Get("build.arch"))
238239
printer.Println("-DARDUINO_ARCH_", arch)
239240
if strings.Contains(fqbn, ":sam:") {
240-
libSamFlags := expandProperty(properties, "compiler.libsam.c.flags")
241+
libSamFlags := buildProps.ExpandPropsInString(buildProps.Get("compiler.libsam.c.flags"))
241242
printer.Println(splitFlags(libSamFlags))
242243
}
243-
extraFlags := expandProperty(properties, "build.extra_flags")
244+
extraFlags := buildProps.ExpandPropsInString(buildProps.Get("build.extra_flags"))
244245
printer.Println(splitFlags(extraFlags))
245-
corePath := expandProperty(properties, "build.core.path")
246+
corePath := buildProps.ExpandPropsInString(buildProps.Get("build.core.path"))
246247
printer.Println("-I", corePath)
247-
variantPath := expandProperty(properties, "build.variant.path")
248+
variantPath := buildProps.ExpandPropsInString(buildProps.Get("build.variant.path"))
248249
printer.Println("-I", variantPath)
249250
if strings.Contains(fqbn, ":avr:") {
250-
avrgccPath := expandProperty(properties, "runtime.tools.avr-gcc.path")
251+
avrgccPath := buildProps.ExpandPropsInString(buildProps.Get("runtime.tools.avr-gcc.path"))
251252
printer.Println("-I", filepath.Join(avrgccPath, "avr", "include"))
252253
}
253254

Diff for: handler/properties.go

-41
This file was deleted.

Diff for: handler/properties_test.go

-33
This file was deleted.

0 commit comments

Comments
 (0)