Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5296056

Browse files
author
Luca Bianconi
committed
Merge branch 'feat/purge-build-cache' of github.com:arduino/arduino-cli into feat/purge-build-cache
2 parents bf58720 + 9f3de10 commit 5296056

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

‎buildcache/build_cache.go‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,32 @@ import (
2323
"github.com/sirupsen/logrus"
2424
)
2525

26-
type wrapError struct {
27-
wrapped error
28-
}
26+
const (
27+
createDirErrCode = 1
28+
fileWriteErrCode = 2
29+
)
2930

30-
func (e wrapError) Error() string {
31-
return e.wrapped.Error()
31+
type cacheError struct {
32+
Code int
33+
wrappedErr error
3234
}
3335

34-
func (e wrapError) Unwrap() error {
35-
return e.wrapped
36+
func (e cacheError) Error() string {
37+
return e.wrappedErr.Error()
3638
}
3739

38-
type ErrCreateBaseDir struct {
39-
wrapError
40-
}
41-
type ErrWriteLastUsedFile struct {
42-
wrapError
40+
func (e cacheError) Is(target error) bool {
41+
te, ok := target.(cacheError)
42+
return ok && te.Code == e.Code
4343
}
4444

45+
var (
46+
// CreateDirErr error occurred when creating the cache directory
47+
CreateDirErr = cacheError{Code: createDirErrCode}
48+
// FileWriteErr error occurred when writing the placeholder file
49+
FileWriteErr = cacheError{Code: fileWriteErrCode}
50+
)
51+
4552
const lastUsedFileName = ".last-used"
4653

4754
// BuildCache represents a cache of built files (sketches and cores), it's designed
@@ -56,11 +63,11 @@ type BuildCache struct {
5663
func (bc *BuildCache) GetOrCreate(key string) (*paths.Path, error) {
5764
keyDir := bc.baseDir.Join(key)
5865
if err := keyDir.MkdirAll(); err != nil {
59-
return nil, &ErrCreateBaseDir{wrapError{err}}
66+
return nil, cacheError{createDirErrCode, err}
6067
}
6168

6269
if err := keyDir.Join(lastUsedFileName).WriteFile([]byte{}); err != nil {
63-
return nil, &ErrWriteLastUsedFile{wrapError{err}}
70+
return nil, cacheError{fileWriteErrCode, err}
6471
}
6572
return keyDir, nil
6673
}

‎commands/sketch/new.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ func validateSketchName(name string) error {
7575
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name cannot be empty"))}
7676
}
7777
if len(name) > sketchNameMaxLength {
78-
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%d characters). Maximum allowed length is %d",
78+
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%[1]d characters). Maximum allowed length is %[2]d",
7979
len(name),
8080
sketchNameMaxLength))}
8181
}
8282
if !sketchNameValidationRegex.MatchString(name) {
83-
return &arduino.CantCreateSketchError{Cause: errors.New(tr("invalid sketch name \"%s\". Required pattern %s",
84-
name,
85-
sketchNameValidationRegex.String()))}
83+
return &arduino.CantCreateSketchError{Cause: errors.New(tr(`invalid sketch name "%[1]s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
84+
name))}
8685
}
8786
return nil
8887
}

‎commands/sketch/new_test.go‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sketch
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -11,7 +12,6 @@ import (
1112
func Test_SketchNameWrongPattern(t *testing.T) {
1213
invalidNames := []string{
1314
"&",
14-
"",
1515
".hello",
1616
"_hello",
1717
"-hello",
@@ -24,11 +24,9 @@ func Test_SketchNameWrongPattern(t *testing.T) {
2424
SketchName: name,
2525
SketchDir: t.TempDir(),
2626
})
27-
require.NotNil(t, err)
2827

29-
require.Error(t, err, `Can't create sketch: invalid sketch name "%s". Required pattern %s`,
30-
name,
31-
sketchNameValidationRegex)
28+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: invalid sketch name "%s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
29+
name))
3230
}
3331
}
3432

@@ -38,9 +36,8 @@ func Test_SketchNameEmpty(t *testing.T) {
3836
SketchName: emptyName,
3937
SketchDir: t.TempDir(),
4038
})
41-
require.NotNil(t, err)
4239

43-
require.Error(t, err, `Can't create sketch: sketch name cannot be empty`)
40+
require.EqualError(t, err, `Can't create sketch: sketch name cannot be empty`)
4441
}
4542

4643
func Test_SketchNameTooLong(t *testing.T) {
@@ -52,11 +49,10 @@ func Test_SketchNameTooLong(t *testing.T) {
5249
SketchName: string(tooLongName),
5350
SketchDir: t.TempDir(),
5451
})
55-
require.NotNil(t, err)
5652

57-
require.Error(t, err, `Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`,
53+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`,
5854
len(tooLongName),
59-
sketchNameMaxLength)
55+
sketchNameMaxLength))
6056
}
6157

6258
func Test_SketchNameOk(t *testing.T) {

‎legacy/builder/phases/core_builder.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
100100
targetArchivedCore = buildCachePath.Join(archivedCoreName, "core.a")
101101
_, buildCacheErr = buildcache.New(buildCachePath).GetOrCreate(archivedCoreName)
102102

103-
if errors.As(buildCacheErr, &buildcache.ErrCreateBaseDir{}) {
103+
if errors.Is(buildCacheErr, buildcache.CreateDirErr) {
104104
return nil, nil, fmt.Errorf(tr("creating core cache folder: %s", err))
105105
}
106106

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /