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

Appearance settings

Commit 51dab2e

Browse filesBrowse files
author
Luca Bianconi
committed
refactor: cleanup
1 parent 642d816 commit 51dab2e
Copy full SHA for 51dab2e

File tree

Expand file treeCollapse file tree

7 files changed

+56
-11
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+56
-11
lines changed

‎buildcache/build_cache.go

Copy file name to clipboardExpand all lines: buildcache/build_cache.go
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ import (
2121
"github.com/arduino/go-paths-helper"
2222
)
2323

24-
// UpdateLastUsedTime registers the last used time in the cache hold file
25-
func UpdateLastUsedTime(dir *paths.Path) error {
26-
_, err := newLastUsedDirCache(dir.Parent().String(), time.Hour).
24+
// GetOrCreate registers the .last-used time in the directory
25+
func GetOrCreate(dir *paths.Path) error {
26+
unusedTTL := time.Hour
27+
_, err := newDirectoryCache(dir.Parent().String(), unusedTTL).
2728
GetOrCreate(dir.Base(), time.Now())
2829
return err
2930
}
3031

3132
// Purge removes all cache directories within baseDir that have expired
3233
// To know how long ago a directory has been last used
33-
// it checks into the last used file. If the file does not exist
34-
// then the directory is purged.
34+
// it checks into the .last-used file.
3535
func Purge(baseDir *paths.Path, ttl time.Duration) {
36-
newLastUsedDirCache(baseDir.String(), ttl).Purge()
36+
newDirectoryCache(baseDir.String(), ttl).Purge()
3737
}

‎buildcache/build_cache_test.go

Copy file name to clipboardExpand all lines: buildcache/build_cache_test.go
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
package buildcache
217

318
import (
@@ -34,7 +49,7 @@ func Test_UpdateLastUsedFileExisting(t *testing.T) {
3449
}
3550

3651
func requireCorrectUpdate(t *testing.T, dir *paths.Path, prevModTime time.Time) {
37-
err := UpdateLastUsedTime(dir)
52+
err := GetOrCreate(dir)
3853
require.Nil(t, err)
3954
expectedFile := dir.Join(lastUsedFileName)
4055
fileInfo, err := os.Stat(expectedFile.String())

‎buildcache/directory_cache.go

Copy file name to clipboardExpand all lines: buildcache/directory_cache.go
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
package buildcache
217

318
import (
@@ -72,7 +87,7 @@ func (dc *directoryCache) Purge() error {
7287
return nil
7388
}
7489

75-
func newLastUsedDirCache(baseDir string, ttl time.Duration) cache[string, time.Time] {
90+
func newDirectoryCache(baseDir string, ttl time.Duration) cache[string, time.Time] {
7691
return &directoryCache{
7792
baseDir: baseDir,
7893
ttl: ttl,

‎buildcache/interface.go

Copy file name to clipboardExpand all lines: buildcache/interface.go
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
package buildcache
217

318
type cache[K comparable, V any] interface {

‎commands/compile/compile.go

Copy file name to clipboardExpand all lines: commands/compile/compile.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
216216
r.UsedLibraries = importedLibs
217217
}()
218218

219-
defer buildcache.UpdateLastUsedTime(builderCtx.BuildPath)
219+
defer buildcache.GetOrCreate(builderCtx.BuildPath)
220220

221221
// if it's a regular build, go on...
222222
if err := builder.RunBuilder(builderCtx); err != nil {

‎legacy/builder/phases/core_builder.go

Copy file name to clipboardExpand all lines: legacy/builder/phases/core_builder.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
123123

124124
// archive core.a
125125
if targetArchivedCore != nil && !ctx.OnlyUpdateCompilationDatabase {
126-
defer buildcache.UpdateLastUsedTime(targetArchivedCore)
126+
defer buildcache.GetOrCreate(targetArchivedCore)
127127
targetArchivedCoreDir.MkdirAll()
128128
err := archiveFile.CopyTo(targetArchivedCore)
129129
if ctx.Verbose {

‎legacy/builder/test/builder_test.go

Copy file name to clipboardExpand all lines: legacy/builder/test/builder_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func TestBuilderCacheCoreAFile(t *testing.T) {
381381
// Pick timestamp of cached core
382382
coreFolder := paths.New("downloaded_hardware", "arduino", "avr")
383383
coreFileName := phases.GetCachedCoreArchiveDirName(ctx.FQBN.String(), ctx.OptimizationFlags, coreFolder)
384-
cachedCoreFile := ctx.CoreBuildCachePath.Join(coreFileName)
384+
cachedCoreFile := ctx.CoreBuildCachePath.Join(coreFileName, "core.a")
385385
coreStatBefore, err := cachedCoreFile.Stat()
386386
require.NoError(t, err)
387387

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.