diff --git a/internal/arduino/builder/builder.go b/internal/arduino/builder/builder.go index 4116b9a4739..b7e415b0865 100644 --- a/internal/arduino/builder/builder.go +++ b/internal/arduino/builder/builder.go @@ -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()) diff --git a/internal/arduino/builder/internal/detector/detector.go b/internal/arduino/builder/internal/detector/detector.go index 17a70ebf359..847c67e9cd2 100644 --- a/internal/arduino/builder/internal/detector/detector.go +++ b/internal/arduino/builder/internal/detector/detector.go @@ -23,6 +23,7 @@ import ( "fmt" "os/exec" "regexp" + "slices" "strings" "time" @@ -59,6 +60,7 @@ type SketchLibrariesDetector struct { logger *logger.BuilderLogger diagnosticStore *diagnostics.Store preRunner *runner.Runner + detectedChangeInLibraries bool } // NewSketchLibrariesDetector todo @@ -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) @@ -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 } @@ -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 }