Skip to content

Commit 8687f9d

Browse files
committed
Added possibility to set extra build-cache dirs for cores
1 parent 8b364d8 commit 8687f9d

File tree

7 files changed

+170
-103
lines changed

7 files changed

+170
-103
lines changed

commands/service_compile.go

+7
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
191191
}
192192
coreBuildCachePath = buildCachePath.Join("core")
193193
}
194+
var extraCoreBuildCachePaths paths.PathList
195+
if len(req.GetBuildCacheExtraPaths()) == 0 {
196+
extraCoreBuildCachePaths = s.settings.GetBuildCacheExtraPaths()
197+
} else {
198+
extraCoreBuildCachePaths = paths.NewPathList(req.GetBuildCacheExtraPaths()...)
199+
}
194200

195201
if _, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform); err != nil {
196202
return err
@@ -229,6 +235,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
229235
buildPath,
230236
req.GetOptimizeForDebug(),
231237
coreBuildCachePath,
238+
extraCoreBuildCachePaths,
232239
int(req.GetJobs()),
233240
req.GetBuildProperties(),
234241
s.settings.HardwareDirectories(),

internal/arduino/builder/builder.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ type Builder struct {
6262
customBuildProperties []string
6363

6464
// core related
65-
coreBuildCachePath *paths.Path
65+
coreBuildCachePath *paths.Path
66+
extraCoreBuildCachePaths paths.PathList
6667

6768
logger *logger.BuilderLogger
6869
clean bool
@@ -121,6 +122,7 @@ func NewBuilder(
121122
buildPath *paths.Path,
122123
optimizeForDebug bool,
123124
coreBuildCachePath *paths.Path,
125+
extraCoreBuildCachePaths paths.PathList,
124126
jobs int,
125127
requestBuildProperties []string,
126128
hardwareDirs, otherLibrariesDirs paths.PathList,
@@ -211,6 +213,7 @@ func NewBuilder(
211213
jobs: jobs,
212214
customBuildProperties: customBuildPropertiesArgs,
213215
coreBuildCachePath: coreBuildCachePath,
216+
extraCoreBuildCachePaths: extraCoreBuildCachePaths,
214217
logger: logger,
215218
clean: clean,
216219
sourceOverrides: sourceOverrides,

internal/arduino/builder/core.go

+14
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
108108
return true
109109
}
110110

111+
// If there is an archived core in the current build cache, use it
111112
if _, err := buildcache.New(b.coreBuildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
112113
return nil, nil, errors.New(i18n.Tr("creating core cache folder: %s", err))
113114
}
@@ -119,6 +120,19 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
119120
}
120121
return targetArchivedCore, variantObjectFiles, nil
121122
}
123+
124+
// Otherwise try the extra build cache paths to see if there is a precompiled core
125+
// that can be used
126+
for _, extraCoreBuildCachePath := range b.extraCoreBuildCachePaths {
127+
extraTargetArchivedCore := extraCoreBuildCachePath.Join(archivedCoreName, "core.a")
128+
if canUseArchivedCore(extraTargetArchivedCore) {
129+
// use archived core
130+
if b.logger.Verbose() {
131+
b.logger.Info(i18n.Tr("Using precompiled core: %[1]s", extraTargetArchivedCore))
132+
}
133+
return extraTargetArchivedCore, variantObjectFiles, nil
134+
}
135+
}
122136
}
123137

124138
coreObjectFiles, err := b.compileFiles(

internal/cli/configuration/build_cache.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
package configuration
1717

18-
import "time"
18+
import (
19+
"time"
20+
21+
"github.com/arduino/go-paths-helper"
22+
)
1923

2024
// GetCompilationsBeforeBuildCachePurge returns the number of compilations before the build cache is purged.
2125
func (s *Settings) GetCompilationsBeforeBuildCachePurge() uint {
@@ -32,3 +36,24 @@ func (s *Settings) GetBuildCacheTTL() time.Duration {
3236
}
3337
return s.Defaults.GetDuration("build_cache.ttl")
3438
}
39+
40+
// GetBuildCachePath returns the path to the build cache.
41+
func (s *Settings) GetBuildCachePath() (*paths.Path, bool) {
42+
p, ok, _ := s.GetStringOk("build_cache.path")
43+
if !ok {
44+
return nil, false
45+
}
46+
return paths.New(p), true
47+
}
48+
49+
// GetBuildCacheExtraPaths returns the extra paths to the core build cache.
50+
// Those paths are visited before the main core build cache to check for cached items.
51+
func (s *Settings) GetBuildCacheExtraPaths() paths.PathList {
52+
var res paths.PathList
53+
if ps, ok, _ := s.GetStringSliceOk("build_cache.extra_paths"); ok {
54+
for _, p := range ps {
55+
res.Add(paths.New(p, "cores"))
56+
}
57+
}
58+
return res
59+
}

internal/cli/configuration/defaults.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func SetDefaults(settings *Settings) {
5252
setDefaultValueAndKeyTypeSchema("sketch.always_export_binaries", false)
5353
setDefaultValueAndKeyTypeSchema("build_cache.ttl", (time.Hour * 24 * 30).String())
5454
setDefaultValueAndKeyTypeSchema("build_cache.compilations_before_purge", uint(10))
55+
setKeyTypeSchema("build_cache.path", "")
56+
setKeyTypeSchema("build_cache.extra_paths", []string{})
5557

5658
// daemon settings
5759
setDefaultValueAndKeyTypeSchema("daemon.port", "50051")

0 commit comments

Comments
 (0)