Skip to content

Commit 3b11d67

Browse files
author
Luca Bianconi
committed
Merge branch 'master' into feat/purge-build-cache
2 parents b65c37b + 58c6bc3 commit 3b11d67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+259
-316
lines changed

Diff for: arduino/libraries/librariesmanager/install.go

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(name string, version *semve
6464
return nil, err
6565
}
6666

67+
lm.RescanLibraries()
6768
libs := lm.FindByReference(&librariesindex.Reference{Name: name}, installLocation)
6869

6970
if len(libs) > 1 {

Diff for: arduino/libraries/librariesmanager/librariesmanager.go

+7
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *core
132132

133133
// RescanLibraries reload all installed libraries in the system.
134134
func (lm *LibrariesManager) RescanLibraries() []*status.Status {
135+
lm.clearLibraries()
135136
statuses := []*status.Status{}
136137
for _, dir := range lm.LibrariesDir {
137138
if errs := lm.LoadLibrariesFromDir(dir); len(errs) > 0 {
@@ -217,3 +218,9 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in
217218
}
218219
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
219220
}
221+
222+
func (lm *LibrariesManager) clearLibraries() {
223+
for k := range lm.Libraries {
224+
delete(lm.Libraries, k)
225+
}
226+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
package librariesmanager
16+
17+
import (
18+
"testing"
19+
20+
"github.com/arduino/arduino-cli/arduino/libraries"
21+
"github.com/arduino/go-paths-helper"
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
func Test_RescanLibrariesCallClear(t *testing.T) {
26+
baseDir := paths.New(t.TempDir())
27+
lm := NewLibraryManager(baseDir.Join("index_dir"), baseDir.Join("downloads_dir"))
28+
lm.Libraries["testLibA"] = libraries.List{}
29+
lm.Libraries["testLibB"] = libraries.List{}
30+
lm.RescanLibraries()
31+
require.Len(t, lm.Libraries, 0)
32+
}

Diff for: arduino/sketch/sketch.go

+10-16
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import (
3232
type Sketch struct {
3333
Name string
3434
MainFile *paths.Path
35-
FullPath *paths.Path // FullPath is the path to the Sketch folder
36-
BuildPath *paths.Path
35+
FullPath *paths.Path // FullPath is the path to the Sketch folder
3736
OtherSketchFiles paths.PathList // Sketch files that end in .ino other than main file
3837
AdditionalFiles paths.PathList
3938
RootFolderFiles paths.PathList // All files that are in the Sketch root
@@ -81,7 +80,6 @@ func New(path *paths.Path) (*Sketch, error) {
8180
Name: path.Base(),
8281
MainFile: mainFile,
8382
FullPath: path,
84-
BuildPath: GenBuildPath(path),
8583
OtherSketchFiles: paths.PathList{},
8684
AdditionalFiles: paths.PathList{},
8785
RootFolderFiles: paths.PathList{},
@@ -293,19 +291,15 @@ func CheckForPdeFiles(sketch *paths.Path) []*paths.Path {
293291
return files
294292
}
295293

296-
// GenBuildPath generates a suitable name for the build folder.
297-
// The sketchPath, if not nil, is also used to furhter differentiate build paths.
298-
func GenBuildPath(sketchPath *paths.Path) *paths.Path {
299-
path := ""
300-
if sketchPath != nil {
301-
path = sketchPath.String()
302-
}
303-
md5SumBytes := md5.Sum([]byte(path))
304-
md5Sum := strings.ToUpper(hex.EncodeToString(md5SumBytes[:]))
305-
306-
return getSketchesCacheDir().Join(md5Sum)
294+
// DefaultBuildPath generates the default build directory for a given sketch.
295+
// The build path is in a temporary directory and is unique for each sketch.
296+
func (s *Sketch) DefaultBuildPath() *paths.Path {
297+
return paths.TempDir().Join("arduino", "sketches", s.Hash())
307298
}
308299

309-
func getSketchesCacheDir() *paths.Path {
310-
return paths.TempDir().Join("arduino", "sketches").Canonical()
300+
// Hash generate a unique hash for the given sketch.
301+
func (s *Sketch) Hash() string {
302+
path := s.FullPath.String()
303+
md5SumBytes := md5.Sum([]byte(path))
304+
return strings.ToUpper(hex.EncodeToString(md5SumBytes[:]))
311305
}

Diff for: arduino/sketch/sketch_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,8 @@ func TestNewSketchFolderSymlink(t *testing.T) {
287287

288288
func TestGenBuildPath(t *testing.T) {
289289
want := paths.TempDir().Join("arduino", "sketches", "ACBD18DB4CC2F85CEDEF654FCCC4A4D8")
290-
assert.True(t, GenBuildPath(paths.New("foo")).EquivalentTo(want))
291-
292-
want = paths.TempDir().Join("arduino", "sketches", "D41D8CD98F00B204E9800998ECF8427E")
293-
assert.True(t, GenBuildPath(nil).EquivalentTo(want))
290+
assert.True(t, (&Sketch{FullPath: paths.New("foo")}).DefaultBuildPath().EquivalentTo(want))
291+
assert.Equal(t, "ACBD18DB4CC2F85CEDEF654FCCC4A4D8", (&Sketch{FullPath: paths.New("foo")}).Hash())
294292
}
295293

296294
func TestCheckForPdeFiles(t *testing.T) {

Diff for: commands/compile/compile.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
118118
}
119119
builderCtx.UseCachedLibrariesResolution = req.GetSkipLibrariesDiscovery()
120120
builderCtx.FQBN = fqbn
121-
builderCtx.SketchLocation = sk.FullPath
121+
builderCtx.Sketch = sk
122122
builderCtx.ProgressCB = progressCB
123123

124124
// FIXME: This will be redundant when arduino-builder will be part of the cli
@@ -130,7 +130,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
130130
builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir(configuration.Settings))
131131
builderCtx.LibraryDirs = paths.NewPathList(req.Library...)
132132
if req.GetBuildPath() == "" {
133-
builderCtx.BuildPath = sk.BuildPath
133+
builderCtx.BuildPath = sk.DefaultBuildPath()
134134
} else {
135135
builderCtx.BuildPath = paths.New(req.GetBuildPath()).Canonical()
136136
}
@@ -150,7 +150,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
150150

151151
// Optimize for debug
152152
builderCtx.OptimizeForDebug = req.GetOptimizeForDebug()
153-
builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino", "cores")
154153

155154
builderCtx.Jobs = int(req.GetJobs())
156155

@@ -160,12 +159,17 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
160159
builderCtx.CustomBuildProperties = append(req.GetBuildProperties(), "build.warn_data_percentage=75")
161160
builderCtx.CustomBuildProperties = append(req.GetBuildProperties(), securityKeysOverride...)
162161

163-
if req.GetBuildCachePath() != "" {
164-
builderCtx.BuildCachePath = paths.New(req.GetBuildCachePath())
165-
err = builderCtx.BuildCachePath.MkdirAll()
162+
if req.GetBuildCachePath() == "" {
163+
builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino", "cores")
164+
} else {
165+
buildCachePath, err := paths.New(req.GetBuildCachePath()).Abs()
166166
if err != nil {
167167
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build cache directory"), Cause: err}
168168
}
169+
if err := buildCachePath.MkdirAll(); err != nil {
170+
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build cache directory"), Cause: err}
171+
}
172+
builderCtx.CoreBuildCachePath = buildCachePath.Join("core")
169173
}
170174

171175
builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)

Diff for: commands/daemon/daemon.go

-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
343343
resp, err := lib.LibraryDownload(
344344
stream.Context(), req,
345345
func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryDownloadResponse{Progress: p}) },
346-
"",
347346
)
348347
if err != nil {
349348
return convertErrorToRPCStatus(err)
@@ -357,7 +356,6 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
357356
stream.Context(), req,
358357
func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryInstallResponse{Progress: p}) },
359358
func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryInstallResponse{TaskProgress: p}) },
360-
"",
361359
)
362360
if err != nil {
363361
return convertErrorToRPCStatus(err)

Diff for: commands/debug/debug_info.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ func getDebugProperties(req *debug.DebugConfigRequest, pme *packagemanager.Explo
115115
}
116116
}
117117

118-
importPath := sk.BuildPath
118+
var importPath *paths.Path
119119
if importDir := req.GetImportDir(); importDir != "" {
120120
importPath = paths.New(importDir)
121+
} else {
122+
importPath = sk.DefaultBuildPath()
121123
}
122124
if !importPath.Exist() {
123125
return nil, &arduino.NotFoundError{Message: tr("Compiled sketch not found in %s", importPath)}

Diff for: commands/lib/download.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ var tr = i18n.Tr
3232

3333
// LibraryDownload executes the download of the library.
3434
// A DownloadProgressCB callback function must be passed to monitor download progress.
35-
// queryParameter is passed for analysis purposes.
36-
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB, queryParameter string) (*rpc.LibraryDownloadResponse, error) {
35+
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
3736
logrus.Info("Executing `arduino-cli lib download`")
3837

3938
lm := commands.GetLibraryManager(req)
@@ -48,7 +47,7 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downl
4847
return nil, err
4948
}
5049

51-
if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, queryParameter); err != nil {
50+
if err := downloadLibrary(lm, lib, downloadCB, func(*rpc.TaskProgress) {}, "download"); err != nil {
5251
return nil, err
5352
}
5453

Diff for: commands/lib/install.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import (
3131
)
3232

3333
// LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
34-
// queryParameter is passed for analysis purposes and forwarded to the called functions. It is set to "depends" when a dependency is installed
35-
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, queryParameter string) error {
34+
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
3635
lm := commands.GetLibraryManager(req)
3736
if lm == nil {
3837
return &arduino.InvalidInstanceError{}
@@ -98,21 +97,19 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
9897

9998
for libRelease, installTask := range libReleasesToInstall {
10099
// Checks if libRelease is the requested library and not a dependency
100+
downloadReason := "depends"
101101
if libRelease.GetName() == req.Name {
102-
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, queryParameter); err != nil {
103-
return err
104-
}
105-
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
106-
return err
107-
}
108-
} else {
109-
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, "depends"); err != nil {
110-
return err
111-
}
112-
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
113-
return err
102+
downloadReason = "install"
103+
if installTask.ReplacedLib != nil {
104+
downloadReason = "upgrade"
114105
}
115106
}
107+
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloadReason); err != nil {
108+
return err
109+
}
110+
if err := installLibrary(lm, libRelease, installTask, taskCB); err != nil {
111+
return err
112+
}
116113
}
117114

118115
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {

Diff for: commands/lib/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.Downlo
7373
NoDeps: false,
7474
NoOverwrite: false,
7575
}
76-
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB, "upgrade")
76+
err := LibraryInstall(context.Background(), libInstallReq, downloadCB, taskCB)
7777
if err != nil {
7878
return err
7979
}

Diff for: commands/upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func determineBuildPathAndSketchName(importFile, importDir string, sk *sketch.Sk
575575

576576
// Case 4: only sketch specified. In this case we use the generated build path
577577
// and the given sketch name.
578-
return sk.BuildPath, sk.Name + sk.MainFile.Ext(), nil
578+
return sk.DefaultBuildPath(), sk.Name + sk.MainFile.Ext(), nil
579579
}
580580

581581
func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) {

Diff for: commands/upload/upload_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
7979
// 03: error: used both importPath and importFile
8080
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", nil, nil, "<nil>", ""},
8181
// 04: only sketch without FQBN
82-
{"", "", blonk, nil, sketch.GenBuildPath(blonk.FullPath).String(), "Blonk.ino"},
82+
{"", "", blonk, nil, blonk.DefaultBuildPath().String(), "Blonk.ino"},
8383
// 05: use importFile to detect build.path and project_name, sketch is ignored.
8484
{"testdata/build_path_2/Blink.ino.hex", "", blonk, nil, "testdata/build_path_2", "Blink.ino"},
8585
// 06: use importPath as build.path and Blink as project name, ignore the sketch Blonk
@@ -95,7 +95,7 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
9595
// 11: error: used both importPath and importFile
9696
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", nil, fqbn, "<nil>", ""},
9797
// 12: use sketch to determine project name and sketch+fqbn to determine build path
98-
{"", "", blonk, fqbn, sketch.GenBuildPath(blonk.FullPath).String(), "Blonk.ino"},
98+
{"", "", blonk, fqbn, blonk.DefaultBuildPath().String(), "Blonk.ino"},
9999
// 13: use importFile to detect build.path and project_name, sketch+fqbn is ignored.
100100
{"testdata/build_path_2/Blink.ino.hex", "", blonk, fqbn, "testdata/build_path_2", "Blink.ino"},
101101
// 14: use importPath as build.path and Blink as project name, ignore the sketch Blonk, ignore fqbn

Diff for: docs/UPGRADING.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## 0.30.0
66

7+
### `daemon` CLI command's `--ip` flag removal
8+
9+
The `daemon` CLI command no longer allows to set a custom ip for the gRPC communication. Currently there is not enough
10+
bandwith to support this feature. For this reason, the `--ip` flag has been removed.
11+
712
### `board attach` CLI command changed behaviour
813

914
The `board attach` CLI command has changed behaviour: now it just pick whatever port and FQBN is passed as parameter and

Diff for: i18n/data/ar.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ msgid "Error installing tool %s"
871871
msgstr "خطأ اثناء تثبيت الاداة %s"
872872

873873
#: cli/lib/list.go:79
874-
msgid "Error listing Libraries: %v"
874+
msgid "Error listing libraries: %v"
875875
msgstr "خطا اثناء انشاء قائمة المكتبات : %v"
876876

877877
#: cli/board/listall.go:64
@@ -953,7 +953,7 @@ msgid "Error searching boards: %v"
953953
msgstr "خطا اثناء البحث عن اللوحات : %v"
954954

955955
#: cli/lib/search.go:78
956-
msgid "Error searching for Libraries: %v"
956+
msgid "Error searching for libraries: %v"
957957
msgstr ""
958958

959959
#: cli/core/search.go:87

Diff for: i18n/data/de.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ msgid "Error installing tool %s"
863863
msgstr "Fehler beim Installieren des Werkzeugs %s"
864864

865865
#: cli/lib/list.go:79
866-
msgid "Error listing Libraries: %v"
866+
msgid "Error listing libraries: %v"
867867
msgstr "Fehler beim Auflisten von Bibliotheken: %v"
868868

869869
#: cli/board/listall.go:64
@@ -944,7 +944,7 @@ msgid "Error searching boards: %v"
944944
msgstr "Fehler bei der Suche nach Platinen: %v"
945945

946946
#: cli/lib/search.go:78
947-
msgid "Error searching for Libraries: %v"
947+
msgid "Error searching for libraries: %v"
948948
msgstr ""
949949

950950
#: cli/core/search.go:87

Diff for: i18n/data/en.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ msgid "Error installing tool %s"
814814
msgstr "Error installing tool %s"
815815

816816
#: cli/lib/list.go:76
817-
msgid "Error listing Libraries: %v"
818-
msgstr "Error listing Libraries: %v"
817+
msgid "Error listing libraries: %v"
818+
msgstr "Error listing libraries: %v"
819819

820820
#: cli/board/listall.go:64
821821
msgid "Error listing boards: %v"

Diff for: i18n/data/es.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ msgid "Error installing tool %s"
869869
msgstr "Error instalando la herramienta %s"
870870

871871
#: cli/lib/list.go:79
872-
msgid "Error listing Libraries: %v"
872+
msgid "Error listing libraries: %v"
873873
msgstr "Error listando las librerías: %v"
874874

875875
#: cli/board/listall.go:64
@@ -950,7 +950,7 @@ msgid "Error searching boards: %v"
950950
msgstr "Error en la búsqueda de placas: %v"
951951

952952
#: cli/lib/search.go:78
953-
msgid "Error searching for Libraries: %v"
953+
msgid "Error searching for libraries: %v"
954954
msgstr ""
955955

956956
#: cli/core/search.go:87

Diff for: i18n/data/fr.po

+2-2
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ msgid "Error installing tool %s"
849849
msgstr "Erreur lors de l’installation de l'outil %s."
850850

851851
#: cli/lib/list.go:79
852-
msgid "Error listing Libraries: %v"
852+
msgid "Error listing libraries: %v"
853853
msgstr "Erreur lors du listage des librairies : %v"
854854

855855
#: cli/board/listall.go:64
@@ -930,7 +930,7 @@ msgid "Error searching boards: %v"
930930
msgstr ""
931931

932932
#: cli/lib/search.go:78
933-
msgid "Error searching for Libraries: %v"
933+
msgid "Error searching for libraries: %v"
934934
msgstr ""
935935

936936
#: cli/core/search.go:87

0 commit comments

Comments
 (0)