@@ -133,6 +133,11 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
133
133
builderCtx .BuildPath = sk .DefaultBuildPath ()
134
134
} else {
135
135
builderCtx .BuildPath = paths .New (req .GetBuildPath ()).Canonical ()
136
+ if in , err := builderCtx .BuildPath .IsInsideDir (sk .FullPath ); err != nil {
137
+ return nil , err
138
+ } else if in && builderCtx .BuildPath .Exist () {
139
+ sk .AdditionalFiles = removeBuildFromSketchFiles (sk .AdditionalFiles , builderCtx .BuildPath )
140
+ }
136
141
}
137
142
if err = builderCtx .BuildPath .MkdirAll (); err != nil {
138
143
return nil , & arduino.PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
@@ -315,3 +320,16 @@ func maybePurgeBuildCache() {
315
320
buildcache .New (paths .TempDir ().Join ("arduino" , "cores" )).Purge (cacheTTL )
316
321
buildcache .New (paths .TempDir ().Join ("arduino" , "sketches" )).Purge (cacheTTL )
317
322
}
323
+
324
+ // removeBuildFromSketchFiles removes the files contained in the build directory from
325
+ // the list of the sketch files
326
+ func removeBuildFromSketchFiles (files paths.PathList , build * paths.Path ) paths.PathList {
327
+ var res paths.PathList
328
+ logrus .Tracef ("Build path %s is a child of sketch path and ignored for additional files." , build .String ())
329
+ for _ , file := range files {
330
+ if in , err := file .IsInsideDir (build ); ! in && err == nil {
331
+ res = append (res , file )
332
+ }
333
+ }
334
+ return res
335
+ }
0 commit comments