@@ -162,6 +162,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
162
162
163
163
// Generate or retrieve build path
164
164
var buildPath * paths.Path
165
+ isDefaultBuildPath := false
165
166
if buildPathArg := req .GetBuildPath (); buildPathArg != "" {
166
167
buildPath = paths .New (req .GetBuildPath ()).Canonical ()
167
168
if in , _ := buildPath .IsInsideDir (sk .FullPath ); in && buildPath .IsDir () {
@@ -172,42 +173,47 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
172
173
}
173
174
if buildPath == nil {
174
175
buildPath = sk .DefaultBuildPath ()
176
+ isDefaultBuildPath = true
175
177
}
176
178
if err = buildPath .MkdirAll (); err != nil {
177
179
return & cmderrors.PermissionDeniedError {Message : i18n .Tr ("Cannot create build directory" ), Cause : err }
178
180
}
179
- buildcache .New (buildPath .Parent ()).GetOrCreate (buildPath .Base ())
180
- // cache is purged after compilation to not remove entries that might be required
181
181
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
185
187
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 {
190
205
return & cmderrors.PermissionDeniedError {Message : i18n .Tr ("Cannot create build cache directory" ), Cause : err }
191
206
}
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" )
202
208
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
+ }
211
217
}
212
218
213
219
if _ , err := pme .FindToolsRequiredForBuild (targetPlatform , buildPlatform ); err != nil {
0 commit comments