Skip to content

Commit f593a73

Browse files
committed
Allow use of a dependency helper source file during library detection
1 parent 67eb95a commit f593a73

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

internal/arduino/builder/internal/detector/detector.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,14 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
414414
l.logger.Info(i18n.Tr("Skipping dependencies detection for precompiled library %[1]s", library.Name))
415415
}
416416
} else {
417-
for _, sourceDir := range library.SourceDirs() {
418-
l.queueSourceFilesFromFolder(sourceFileQueue, sourceDir.Dir, sourceDir.Recurse,
417+
if helperSource := library.DependencyHelper(); helperSource != nil {
418+
l.queueSourceFile(sourceFileQueue, helperSource,
419419
library.SourceDir, librariesBuildPath.Join(library.DirName), library.UtilityDir)
420+
} else {
421+
for _, sourceDir := range library.SourceDirs() {
422+
l.queueSourceFilesFromFolder(sourceFileQueue, sourceDir.Dir, sourceDir.Recurse,
423+
library.SourceDir, librariesBuildPath.Join(library.DirName), library.UtilityDir)
424+
}
420425
}
421426
}
422427
first = false
@@ -441,16 +446,29 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
441446
}
442447

443448
for _, filePath := range filePaths {
444-
sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...)
445-
if err != nil {
449+
if err := l.queueSourceFile(sourceFileQueue, filePath, sourceDir, buildDir, extraIncludePath...); err != nil {
446450
return err
447451
}
448-
sourceFileQueue.push(sourceFile)
449452
}
450453

451454
return nil
452455
}
453456

457+
func (l *SketchLibrariesDetector) queueSourceFile(
458+
sourceFileQueue *uniqueSourceFileQueue,
459+
filePath *paths.Path,
460+
sourceDir *paths.Path,
461+
buildDir *paths.Path,
462+
extraIncludePath ...*paths.Path,
463+
) error {
464+
sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...)
465+
if err != nil {
466+
return err
467+
}
468+
sourceFileQueue.push(sourceFile)
469+
return nil
470+
}
471+
454472
func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
455473
if len(l.importedLibraries) == 0 {
456474
return nil

internal/arduino/libraries/libraries.go

+11
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,14 @@ func (library *Library) SourceHeaders() ([]string, error) {
239239
}
240240
return library.sourceHeaders, nil
241241
}
242+
243+
// DependencyHelper returns the path to the dependency helper file.
244+
func (library *Library) DependencyHelper() *paths.Path {
245+
if c := library.SourceDir.Join("arduino_deps.c"); c.Exist() {
246+
return c
247+
}
248+
if cpp := library.SourceDir.Join("arduino_deps.cpp"); cpp.Exist() {
249+
return cpp
250+
}
251+
return nil
252+
}

0 commit comments

Comments
 (0)