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 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

‎arduino/libraries/librariesmanager/install.go‎

Lines changed: 1 addition & 0 deletions
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 {

‎arduino/libraries/librariesmanager/librariesmanager.go‎

Lines changed: 7 additions & 0 deletions
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+
}
Lines changed: 32 additions & 0 deletions
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 license@arduino.cc.
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+
}

‎arduino/sketch/sketch.go‎

Lines changed: 10 additions & 16 deletions
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
}

‎arduino/sketch/sketch_test.go‎

Lines changed: 2 additions & 4 deletions
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) {

‎commands/compile/compile.go‎

Lines changed: 10 additions & 6 deletions
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)

‎commands/daemon/daemon.go‎

Lines changed: 0 additions & 2 deletions
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)

‎commands/debug/debug_info.go‎

Lines changed: 3 additions & 1 deletion
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+
varimportPath *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)}

‎commands/lib/download.go‎

Lines changed: 2 additions & 3 deletions
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

‎commands/lib/install.go‎

Lines changed: 11 additions & 14 deletions
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 {

0 commit comments

Comments
(0)

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