@@ -133,6 +133,13 @@ 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 , & arduino.NotFoundError {Message : tr ("Cannot find build path" ), Cause : err }
138
+ } else if in && builderCtx .BuildPath .IsDir () {
139
+ if sk .AdditionalFiles , err = removeBuildFromSketchFiles (sk .AdditionalFiles , builderCtx .BuildPath ); err != nil {
140
+ return nil , err
141
+ }
142
+ }
136
143
}
137
144
if err = builderCtx .BuildPath .MkdirAll (); err != nil {
138
145
return nil , & arduino.PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
@@ -315,3 +322,24 @@ func maybePurgeBuildCache() {
315
322
buildcache .New (paths .TempDir ().Join ("arduino" , "cores" )).Purge (cacheTTL )
316
323
buildcache .New (paths .TempDir ().Join ("arduino" , "sketches" )).Purge (cacheTTL )
317
324
}
325
+
326
+ // removeBuildFromSketchFiles removes the files contained in the build directory from
327
+ // the list of the sketch files
328
+ func removeBuildFromSketchFiles (files paths.PathList , build * paths.Path ) (paths.PathList , error ) {
329
+ var res paths.PathList
330
+ ignored := false
331
+ for _ , file := range files {
332
+ if in , err := file .IsInsideDir (build ); err != nil {
333
+ return nil , & arduino.NotFoundError {Message : tr ("Cannot find build path" ), Cause : err }
334
+ } else if ! in {
335
+ res = append (res , file )
336
+ } else if ! ignored {
337
+ ignored = true
338
+ }
339
+ }
340
+ // log only if at least a file is ignored
341
+ if ignored {
342
+ logrus .Tracef ("Build path %s is a child of sketch path and it is ignored for additional files." , build .String ())
343
+ }
344
+ return res , nil
345
+ }
0 commit comments