Unverified Commit c9836a97 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

builder.GenBuildPath now tolerates missing sketch folder (#428)

parent c23bb9c4
......@@ -19,18 +19,22 @@ import (
"crypto/md5"
"encoding/hex"
"os"
"path/filepath"
"strings"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
)
// GenBuildPath generates a suitable name for the build folder
func GenBuildPath(sketchPath string) string {
md5SumBytes := md5.Sum([]byte(sketchPath))
// GenBuildPath generates a suitable name for the build folder.
// The sketchPath, if not nil, is also used to furhter differentiate build paths.
func GenBuildPath(sketchPath *paths.Path) *paths.Path {
path := ""
if sketchPath != nil {
path = sketchPath.String()
}
md5SumBytes := md5.Sum([]byte(path))
md5Sum := strings.ToUpper(hex.EncodeToString(md5SumBytes[:]))
return filepath.Join(os.TempDir(), "arduino-sketch-"+md5Sum)
return paths.TempDir().Join("arduino-sketch-" + md5Sum)
}
// EnsureBuildPathExists creates the build path if doesn't already exists.
......
......@@ -23,6 +23,7 @@ import (
"testing"
"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
)
......@@ -36,7 +37,10 @@ func tmpDirOrDie() string {
func TestGenBuildPath(t *testing.T) {
want := filepath.Join(os.TempDir(), "arduino-sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8")
assert.Equal(t, want, builder.GenBuildPath("foo"))
assert.Equal(t, want, builder.GenBuildPath(paths.New("foo")).String())
want = filepath.Join(os.TempDir(), "arduino-sketch-D41D8CD98F00B204E9800998ECF8427E")
assert.Equal(t, want, builder.GenBuildPath(nil).String())
}
func TestEnsureBuildPathExists(t *testing.T) {
......
......@@ -43,7 +43,6 @@ import (
"github.com/arduino/arduino-cli/legacy/builder/phases"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/arduino-cli/legacy/builder/utils"
"github.com/arduino/go-paths-helper"
)
var MAIN_FILE_VALID_EXTENSIONS = map[string]bool{".ino": true, ".pde": true}
......@@ -58,7 +57,7 @@ type Builder struct{}
func (s *Builder) Run(ctx *types.Context) error {
if ctx.BuildPath == nil {
ctx.BuildPath = paths.New(bldr.GenBuildPath(ctx.SketchLocation.String()))
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
}
if err := bldr.EnsureBuildPathExists(ctx.BuildPath.String()); err != nil {
......@@ -150,7 +149,7 @@ type Preprocess struct{}
func (s *Preprocess) Run(ctx *types.Context) error {
if ctx.BuildPath == nil {
ctx.BuildPath = paths.New(bldr.GenBuildPath(ctx.SketchLocation.String()))
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
}
if err := bldr.EnsureBuildPathExists(ctx.BuildPath.String()); err != nil {
......@@ -186,7 +185,7 @@ type ParseHardwareAndDumpBuildProperties struct{}
func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
if ctx.BuildPath == nil {
ctx.BuildPath = paths.New(bldr.GenBuildPath(ctx.SketchLocation.String()))
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
}
commands := []types.Command{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment