Skip to content

Commit 51dab2e

Browse files
author
Luca Bianconi
committed
refactor: cleanup
1 parent 642d816 commit 51dab2e

File tree

7 files changed

+56
-11
lines changed

7 files changed

+56
-11
lines changed

Diff for: buildcache/build_cache.go

+6-6
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
}

Diff for: buildcache/build_cache_test.go

+16-1
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 [email protected].
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())

Diff for: buildcache/directory_cache.go

+16-1
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 [email protected].
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,

Diff for: buildcache/interface.go

+15
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 [email protected].
15+
116
package buildcache
217

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

Diff for: commands/compile/compile.go

+1-1
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 {

Diff for: legacy/builder/phases/core_builder.go

+1-1
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 {

Diff for: legacy/builder/test/builder_test.go

+1-1
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)