Skip to content

Fix buildpath regression #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/arduino/arduino-builder
go 1.12

require (
github.com/arduino/arduino-cli v0.0.0-20190909101745-b3db7a6400cf
github.com/arduino/arduino-cli v0.0.0-20190920124130-b6774033151c
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c
github.com/go-errors/errors v1.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/arduino/arduino-cli v0.0.0-20190828173137-fffa451acd60 h1:5jnGjqzOYyS
github.com/arduino/arduino-cli v0.0.0-20190828173137-fffa451acd60/go.mod h1:mTVK2WsKc1Ehy2ic+rChPLo9N0uf3ZuUVO7C3y4Y04Q=
github.com/arduino/arduino-cli v0.0.0-20190909101745-b3db7a6400cf h1:MWVsGOfaT0/HzX5PP6/fWiPviu2YzBe1SbPMtX4qb7s=
github.com/arduino/arduino-cli v0.0.0-20190909101745-b3db7a6400cf/go.mod h1:mTVK2WsKc1Ehy2ic+rChPLo9N0uf3ZuUVO7C3y4Y04Q=
github.com/arduino/arduino-cli v0.0.0-20190920124130-b6774033151c h1:0ewBEBzUPbdJgXusSiofkoCJbrT2uKex5ZswdawmdAM=
github.com/arduino/arduino-cli v0.0.0-20190920124130-b6774033151c/go.mod h1:tGmlOZBUyZunMKW2TIwP/ztR2wnfL81+BNNuZaZmXuQ=
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT96G8egU7FEb13L4dq3fnCN7lxXhJ86t69+W7s=
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1 h1:S0NpDSqjlkNA510vmRCP5Cq9mPgu3rWDSdeN4SI1Mwc=
Expand Down
45 changes: 31 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import (
"runtime"
"runtime/pprof"
"runtime/trace"
"strconv"
"strings"
"syscall"

"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/legacy/builder"
"github.com/arduino/arduino-cli/legacy/builder/gohasissues"
jsonrpc "github.com/arduino/arduino-cli/legacy/builder/grpc"
"github.com/arduino/arduino-cli/legacy/builder/i18n"
"github.com/arduino/arduino-cli/legacy/builder/types"
Expand Down Expand Up @@ -258,9 +258,9 @@ func main() {
if toolsFolders, err := toSliceOfUnquoted(toolsFoldersFlag); err != nil {
printCompleteError(err)
} else if len(toolsFolders) > 0 {
ctx.ToolsDirs = paths.NewPathList(toolsFolders...)
ctx.BuiltInToolsDirs = paths.NewPathList(toolsFolders...)
}
if len(ctx.ToolsDirs) == 0 {
if len(ctx.BuiltInToolsDirs) == 0 {
printErrorMessageAndFlagUsage(errors.New("Parameter '" + FLAG_TOOLS + "' is mandatory"))
}

Expand All @@ -286,7 +286,7 @@ func main() {
}

// FLAG_FQBN
if fqbnIn, err := gohasissues.Unquote(*fqbnFlag); err != nil {
if fqbnIn, err := unquote(*fqbnFlag); err != nil {
printCompleteError(err)
} else if fqbnIn != "" {
if fqbn, err := cores.ParseFQBN(fqbnIn); err != nil {
Expand All @@ -300,13 +300,13 @@ func main() {
}

// FLAG_BUILD_PATH
buildPathUnquoted, err := gohasissues.Unquote(*buildPathFlag)
if err != nil {
printCompleteError(err)
}
buildPath := paths.New(buildPathUnquoted)
if buildPath != nil {
// TODO: mmmmhhh... this one looks like a bug, why check existence?
if *buildPathFlag != "" {
buildPathUnquoted, err := unquote(*buildPathFlag)
if err != nil {
printCompleteError(err)
}
buildPath := paths.New(buildPathUnquoted)

if _, err := buildPath.Stat(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand All @@ -320,7 +320,7 @@ func main() {

// FLAG_BUILD_CACHE
if *buildCachePathFlag != "" {
buildCachePathUnquoted, err := gohasissues.Unquote(*buildCachePathFlag)
buildCachePathUnquoted, err := unquote(*buildCachePathFlag)
if err != nil {
printCompleteError(err)
}
Expand All @@ -339,7 +339,7 @@ func main() {
}

if flag.NArg() > 0 {
sketchLocationUnquoted, err := gohasissues.Unquote(flag.Arg(0))
sketchLocationUnquoted, err := unquote(flag.Arg(0))
if err != nil {
printCompleteError(err)
}
Expand Down Expand Up @@ -384,6 +384,7 @@ func main() {
ctx.SetLogger(i18n.HumanLogger{})
}

var err error
if *dumpPrefsFlag {
err = builder.RunParseHardwareAndDumpBuildProperties(ctx)
} else if *preprocessFlag || *codeCompleteAtFlag != "" {
Expand Down Expand Up @@ -423,7 +424,7 @@ func toExitCode(err error) int {
func toSliceOfUnquoted(value []string) ([]string, error) {
var values []string
for _, v := range value {
v, err := gohasissues.Unquote(v)
v, err := unquote(v)
if err != nil {
return nil, err
}
Expand All @@ -432,6 +433,22 @@ func toSliceOfUnquoted(value []string) ([]string, error) {
return values, nil
}

func unquote(s string) (string, error) {
if stringStartsEndsWith(s, "'") {
s = s[1 : len(s)-1]
}

if !stringStartsEndsWith(s, "\"") {
return s, nil
}

return strconv.Unquote(s)
}

func stringStartsEndsWith(s string, c string) bool {
return strings.HasPrefix(s, c) && strings.HasSuffix(s, c)
}

func printCompleteError(err error) {
err = i18n.WrapError(err)
fmt.Fprintln(os.Stderr, err.(*errors.Error).ErrorStack())
Expand Down