Skip to content

Commit b0c7c08

Browse files
committed
Build dir cleanup keeps lib-discovery output files
1 parent 237f0cc commit b0c7c08

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

internal/arduino/builder/builder.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"sort"
2526
"strings"
2627

2728
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/compilation"
@@ -330,7 +331,7 @@ func (b *Builder) preprocess() error {
330331
if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
331332
b.logger.Info(i18n.Tr("The list of included libraries has been changed... rebuilding all libraries."))
332333
}
333-
if err := b.librariesBuildPath.RemoveAll(); err != nil {
334+
if err := b.removeBuildPathExecptLibsdiscoveryFiles(b.librariesBuildPath); err != nil {
334335
return err
335336
}
336337
}
@@ -543,3 +544,28 @@ func (b *Builder) execCommand(command *paths.Process) error {
543544

544545
return command.Wait()
545546
}
547+
548+
func (b *Builder) removeBuildPathExecptLibsdiscoveryFiles(pathToRemove *paths.Path) error {
549+
filesToRemove, err := pathToRemove.ReadDirRecursiveFiltered(nil,
550+
paths.FilterOutDirectories(),
551+
paths.FilterOutSuffixes(".libsdetect.d"))
552+
if err != nil {
553+
return err
554+
}
555+
for _, f := range filesToRemove {
556+
if err := f.Remove(); err != nil {
557+
return err
558+
}
559+
}
560+
561+
dirsToRemove, err := pathToRemove.ReadDirRecursiveFiltered(nil, paths.FilterDirectories())
562+
if err != nil {
563+
return err
564+
}
565+
// Remove directories in reverse order (deepest first)
566+
sort.Slice(dirsToRemove, func(i, j int) bool { return len(dirsToRemove[i].String()) > len(dirsToRemove[j].String()) })
567+
for _, d := range dirsToRemove {
568+
_ = d.Remove()
569+
}
570+
return nil
571+
}

0 commit comments

Comments
 (0)