Skip to content

Commit 770c49a

Browse files
Handle repeated builds of a sketch when the build path is inside the sketch directory
1 parent e7ba99f commit 770c49a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: commands/compile/compile.go

+18
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
133133
builderCtx.BuildPath = sk.DefaultBuildPath()
134134
} else {
135135
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+
}
136141
}
137142
if err = builderCtx.BuildPath.MkdirAll(); err != nil {
138143
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build directory"), Cause: err}
@@ -315,3 +320,16 @@ func maybePurgeBuildCache() {
315320
buildcache.New(paths.TempDir().Join("arduino", "cores")).Purge(cacheTTL)
316321
buildcache.New(paths.TempDir().Join("arduino", "sketches")).Purge(cacheTTL)
317322
}
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

Comments
 (0)