Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5b5b49

Browse files
committedSep 25, 2019
builder.GenBuildPath now tolerates missing sketch folder
1 parent 9c64df7 commit b5b5b49

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed
 

‎arduino/builder/builder.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ import (
1919
"crypto/md5"
2020
"encoding/hex"
2121
"os"
22-
"path/filepath"
2322
"strings"
2423

24+
"github.com/arduino/go-paths-helper"
2525
"github.com/pkg/errors"
2626
)
2727

28-
// GenBuildPath generates a suitable name for the build folder
29-
func GenBuildPath(sketchPath string) string {
30-
md5SumBytes := md5.Sum([]byte(sketchPath))
28+
// GenBuildPath generates a suitable name for the build folder.
29+
// The sketchPath, if not nil, is also used to furhter differentiate build paths.
30+
func GenBuildPath(sketchPath *paths.Path) *paths.Path {
31+
path := ""
32+
if sketchPath != nil {
33+
path = sketchPath.String()
34+
}
35+
md5SumBytes := md5.Sum([]byte(path))
3136
md5Sum := strings.ToUpper(hex.EncodeToString(md5SumBytes[:]))
32-
33-
return filepath.Join(os.TempDir(), "arduino-sketch-"+md5Sum)
37+
return paths.TempDir().Join("arduino-sketch-" + md5Sum)
3438
}
3539

3640
// EnsureBuildPathExists creates the build path if doesn't already exists.

‎legacy/builder/builder.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343
"github.com/arduino/arduino-cli/legacy/builder/phases"
4444
"github.com/arduino/arduino-cli/legacy/builder/types"
4545
"github.com/arduino/arduino-cli/legacy/builder/utils"
46-
"github.com/arduino/go-paths-helper"
4746
)
4847

4948
var MAIN_FILE_VALID_EXTENSIONS = map[string]bool{".ino": true, ".pde": true}
@@ -58,7 +57,7 @@ type Builder struct{}
5857

5958
func (s *Builder) Run(ctx *types.Context) error {
6059
if ctx.BuildPath == nil {
61-
ctx.BuildPath = paths.New(bldr.GenBuildPath(ctx.SketchLocation.String()))
60+
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
6261
}
6362

6463
if err := bldr.EnsureBuildPathExists(ctx.BuildPath.String()); err != nil {
@@ -150,7 +149,7 @@ type Preprocess struct{}
150149

151150
func (s *Preprocess) Run(ctx *types.Context) error {
152151
if ctx.BuildPath == nil {
153-
ctx.BuildPath = paths.New(bldr.GenBuildPath(ctx.SketchLocation.String()))
152+
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
154153
}
155154

156155
if err := bldr.EnsureBuildPathExists(ctx.BuildPath.String()); err != nil {
@@ -186,7 +185,7 @@ type ParseHardwareAndDumpBuildProperties struct{}
186185

187186
func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
188187
if ctx.BuildPath == nil {
189-
ctx.BuildPath = paths.New(bldr.GenBuildPath(ctx.SketchLocation.String()))
188+
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
190189
}
191190

192191
commands := []types.Command{

0 commit comments

Comments
 (0)
Please sign in to comment.