Skip to content

Commit

Permalink
Allow use of a dependency helper source file during library detection
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Nov 18, 2024
1 parent 67eb95a commit f593a73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
28 changes: 23 additions & 5 deletions internal/arduino/builder/internal/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions internal/arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit f593a73

Please sign in to comment.