Skip to content

Commit

Permalink
fix: libraries are recompiled if the list of include paths changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Aug 8, 2024
1 parent 8237ac6 commit 87765a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
8 changes: 8 additions & 0 deletions internal/arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ func (b *Builder) preprocess() error {
if err != nil {
return err
}
if b.libsDetector.IncludeFoldersChanged() && b.librariesBuildPath.Exist() {
if b.logger.Verbose() {
b.logger.Info(i18n.Tr("The list of included libraries has been changed... rebuilding all libraries."))
}
if err := b.librariesBuildPath.RemoveAll(); err != nil {
return err
}
}
b.Progress.CompleteStep()

b.warnAboutArchIncompatibleLibraries(b.libsDetector.ImportedLibraries())
Expand Down
28 changes: 21 additions & 7 deletions internal/arduino/builder/internal/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os/exec"
"regexp"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -59,6 +60,7 @@ type SketchLibrariesDetector struct {
logger *logger.BuilderLogger
diagnosticStore *diagnostics.Store
preRunner *runner.Runner
detectedChangeInLibraries bool
}

// NewSketchLibrariesDetector todo
Expand Down Expand Up @@ -174,6 +176,12 @@ func (l *SketchLibrariesDetector) IncludeFolders() paths.PathList {
return l.includeFolders
}

// IncludeFoldersChanged returns true if the include folders list changed
// from the previous compile.
func (l *SketchLibrariesDetector) IncludeFoldersChanged() bool {
return l.detectedChangeInLibraries
}

// addIncludeFolder add the given folder to the include path.
func (l *SketchLibrariesDetector) addIncludeFolder(folder *paths.Path) {
l.includeFolders = append(l.includeFolders, folder)
Expand Down Expand Up @@ -219,17 +227,21 @@ func (l *SketchLibrariesDetector) findIncludes(
platformArch string,
jobs int,
) error {
librariesResolutionCache := buildPath.Join("libraries.cache")
if l.useCachedLibrariesResolution && librariesResolutionCache.Exist() {
d, err := librariesResolutionCache.ReadFile()
librariesResolutionCachePath := buildPath.Join("libraries.cache")
var cachedIncludeFolders paths.PathList
if librariesResolutionCachePath.Exist() {
d, err := librariesResolutionCachePath.ReadFile()
if err != nil {
return err
}
if err := json.Unmarshal(d, &l.includeFolders); err != nil {
if err := json.Unmarshal(d, &cachedIncludeFolders); err != nil {
return err
}
}
if l.useCachedLibrariesResolution && librariesResolutionCachePath.Exist() {
l.includeFolders = cachedIncludeFolders
if l.logger.Verbose() {
l.logger.Info("Using cached library discovery: " + librariesResolutionCache.String())
l.logger.Info("Using cached library discovery: " + librariesResolutionCachePath.String())
}
return nil
}
Expand Down Expand Up @@ -301,10 +313,12 @@ func (l *SketchLibrariesDetector) findIncludes(

if d, err := json.Marshal(l.includeFolders); err != nil {
return err
} else if err := librariesResolutionCache.WriteFile(d); err != nil {
} else if err := librariesResolutionCachePath.WriteFile(d); err != nil {
return err
}

l.detectedChangeInLibraries = !slices.Equal(
cachedIncludeFolders.AsStrings(),
l.includeFolders.AsStrings())
return nil
}

Expand Down

0 comments on commit 87765a4

Please sign in to comment.