Skip to content

Commit 196caa9

Browse files
committed
If a build path is specified ignore all build caches
The complete build will be performed in the specified build path. The build artifacts in the build path will be reused for the next build.
1 parent 5f01000 commit 196caa9

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

commands/service_compile.go

+33-27
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
162162

163163
// Generate or retrieve build path
164164
var buildPath *paths.Path
165+
isDefaultBuildPath := false
165166
if buildPathArg := req.GetBuildPath(); buildPathArg != "" {
166167
buildPath = paths.New(req.GetBuildPath()).Canonical()
167168
if in, _ := buildPath.IsInsideDir(sk.FullPath); in && buildPath.IsDir() {
@@ -172,42 +173,47 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
172173
}
173174
if buildPath == nil {
174175
buildPath = sk.DefaultBuildPath()
176+
isDefaultBuildPath = true
175177
}
176178
if err = buildPath.MkdirAll(); err != nil {
177179
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build directory"), Cause: err}
178180
}
179-
buildcache.New(buildPath.Parent()).GetOrCreate(buildPath.Base())
180-
// cache is purged after compilation to not remove entries that might be required
181181

182-
defer maybePurgeBuildCache(
183-
s.settings.GetCompilationsBeforeBuildCachePurge(),
184-
s.settings.GetBuildCacheTTL().Abs())
182+
var coreBuildCachePath *paths.Path
183+
var extraCoreBuildCachePaths paths.PathList
184+
if isDefaultBuildPath {
185+
buildcache.New(buildPath.Parent()).GetOrCreate(buildPath.Base())
186+
// cache is purged after compilation to not remove entries that might be required
185187

186-
var buildCachePath *paths.Path
187-
if req.GetBuildCachePath() != "" {
188-
p, err := paths.New(req.GetBuildCachePath()).Abs()
189-
if err != nil {
188+
defer maybePurgeBuildCache(
189+
s.settings.GetCompilationsBeforeBuildCachePurge(),
190+
s.settings.GetBuildCacheTTL().Abs())
191+
192+
var buildCachePath *paths.Path
193+
if req.GetBuildCachePath() != "" {
194+
p, err := paths.New(req.GetBuildCachePath()).Abs()
195+
if err != nil {
196+
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build cache directory"), Cause: err}
197+
}
198+
buildCachePath = p
199+
} else if p, ok := s.settings.GetBuildCachePath(); ok {
200+
buildCachePath = p
201+
} else {
202+
buildCachePath = paths.TempDir().Join("arduino")
203+
}
204+
if err := buildCachePath.MkdirAll(); err != nil {
190205
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build cache directory"), Cause: err}
191206
}
192-
buildCachePath = p
193-
} else if p, ok := s.settings.GetBuildCachePath(); ok {
194-
buildCachePath = p
195-
} else {
196-
buildCachePath = paths.TempDir().Join("arduino")
197-
}
198-
if err := buildCachePath.MkdirAll(); err != nil {
199-
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build cache directory"), Cause: err}
200-
}
201-
coreBuildCachePath := buildCachePath.Join("cores")
207+
coreBuildCachePath = buildCachePath.Join("cores")
202208

203-
var extraCoreBuildCachePaths paths.PathList
204-
if len(req.GetBuildCacheExtraPaths()) == 0 {
205-
extraCoreBuildCachePaths = s.settings.GetBuildCacheExtraPaths()
206-
} else {
207-
extraCoreBuildCachePaths = paths.NewPathList(req.GetBuildCacheExtraPaths()...)
208-
}
209-
for i, p := range extraCoreBuildCachePaths {
210-
extraCoreBuildCachePaths[i] = p.Join("cores")
209+
if len(req.GetBuildCacheExtraPaths()) == 0 {
210+
extraCoreBuildCachePaths = s.settings.GetBuildCacheExtraPaths()
211+
} else {
212+
extraCoreBuildCachePaths = paths.NewPathList(req.GetBuildCacheExtraPaths()...)
213+
}
214+
for i, p := range extraCoreBuildCachePaths {
215+
extraCoreBuildCachePaths[i] = p.Join("cores")
216+
}
211217
}
212218

213219
if _, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform); err != nil {

0 commit comments

Comments
 (0)