From f593a73686d39eca4cafbb304075e3e2bbb043c5 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 18 Nov 2024 12:04:28 +0100 Subject: [PATCH] Allow use of a dependency helper source file during library detection --- .../builder/internal/detector/detector.go | 28 +++++++++++++++---- internal/arduino/libraries/libraries.go | 11 ++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/internal/arduino/builder/internal/detector/detector.go b/internal/arduino/builder/internal/detector/detector.go index 17de9377833..a8d3632535e 100644 --- a/internal/arduino/builder/internal/detector/detector.go +++ b/internal/arduino/builder/internal/detector/detector.go @@ -414,9 +414,14 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone( l.logger.Info(i18n.Tr("Skipping dependencies detection for precompiled library %[1]s", library.Name)) } } else { - for _, sourceDir := range library.SourceDirs() { - l.queueSourceFilesFromFolder(sourceFileQueue, sourceDir.Dir, sourceDir.Recurse, + if helperSource := library.DependencyHelper(); helperSource != nil { + l.queueSourceFile(sourceFileQueue, helperSource, library.SourceDir, librariesBuildPath.Join(library.DirName), library.UtilityDir) + } else { + for _, sourceDir := range library.SourceDirs() { + l.queueSourceFilesFromFolder(sourceFileQueue, sourceDir.Dir, sourceDir.Recurse, + library.SourceDir, librariesBuildPath.Join(library.DirName), library.UtilityDir) + } } } first = false @@ -441,16 +446,29 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder( } for _, filePath := range filePaths { - sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...) - if err != nil { + if err := l.queueSourceFile(sourceFileQueue, filePath, sourceDir, buildDir, extraIncludePath...); err != nil { return err } - sourceFileQueue.push(sourceFile) } return nil } +func (l *SketchLibrariesDetector) queueSourceFile( + sourceFileQueue *uniqueSourceFileQueue, + filePath *paths.Path, + sourceDir *paths.Path, + buildDir *paths.Path, + extraIncludePath ...*paths.Path, +) error { + sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...) + if err != nil { + return err + } + sourceFileQueue.push(sourceFile) + return nil +} + func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error { if len(l.importedLibraries) == 0 { return nil diff --git a/internal/arduino/libraries/libraries.go b/internal/arduino/libraries/libraries.go index 9ffa1e27eea..8fa4c9b5f2f 100644 --- a/internal/arduino/libraries/libraries.go +++ b/internal/arduino/libraries/libraries.go @@ -239,3 +239,14 @@ func (library *Library) SourceHeaders() ([]string, error) { } return library.sourceHeaders, nil } + +// DependencyHelper returns the path to the dependency helper file. +func (library *Library) DependencyHelper() *paths.Path { + if c := library.SourceDir.Join("arduino_deps.c"); c.Exist() { + return c + } + if cpp := library.SourceDir.Join("arduino_deps.cpp"); cpp.Exist() { + return cpp + } + return nil +}