@@ -50,10 +50,12 @@ type libraryResolutionResult struct {
5050
5151// SketchLibrariesDetector todo
5252type SketchLibrariesDetector struct {
53+ librariesManager * librariesmanager.LibrariesManager
5354 librariesResolver * librariesresolver.Cpp
5455 useCachedLibrariesResolution bool
5556 cache * detectorCache
5657 onlyUpdateCompilationDatabase bool
58+ alwaysBuildProfileLibs bool
5759 importedLibraries libraries.List
5860 librariesResolutionResults map [string ]libraryResolutionResult
5961 includeFolders paths.PathList
@@ -65,20 +67,24 @@ type SketchLibrariesDetector struct {
6567
6668// NewSketchLibrariesDetector todo
6769func NewSketchLibrariesDetector (
70+ lm * librariesmanager.LibrariesManager ,
6871 libsResolver * librariesresolver.Cpp ,
6972 useCachedLibrariesResolution bool ,
7073 onlyUpdateCompilationDatabase bool ,
74+ alwaysBuildProfileLibs bool ,
7175 logger * logger.BuilderLogger ,
7276 diagnosticStore * diagnostics.Store ,
7377) * SketchLibrariesDetector {
7478 return & SketchLibrariesDetector {
79+ librariesManager : lm ,
7580 librariesResolver : libsResolver ,
7681 useCachedLibrariesResolution : useCachedLibrariesResolution ,
7782 cache : newDetectorCache (),
7883 librariesResolutionResults : map [string ]libraryResolutionResult {},
7984 importedLibraries : libraries.List {},
8085 includeFolders : paths.PathList {},
8186 onlyUpdateCompilationDatabase : onlyUpdateCompilationDatabase ,
87+ alwaysBuildProfileLibs : alwaysBuildProfileLibs ,
8288 logger : logger ,
8389 diagnosticStore : diagnosticStore ,
8490 }
@@ -134,10 +140,25 @@ func (l *SketchLibrariesDetector) ImportedLibraries() libraries.List {
134140 return l .importedLibraries
135141}
136142
137- // AppendImportedLibraries todo should rename this, probably after refactoring the
138- // container_find_includes command .
139- func (l * SketchLibrariesDetector ) AppendImportedLibraries ( library * libraries.Library ) {
143+ // addAndBuildLibrary adds the given library to the imported libraries list and queues its source files
144+ // for further processing .
145+ func (l * SketchLibrariesDetector ) addAndBuildLibrary ( sourceFileQueue * uniqueSourceFileQueue , librariesBuildPath * paths. Path , library * libraries.Library ) {
140146 l .importedLibraries = append (l .importedLibraries , library )
147+ if library .Precompiled && library .PrecompiledWithSources {
148+ // Fully precompiled libraries should have no dependencies to avoid ABI breakage
149+ if l .logger .VerbosityLevel () == logger .VerbosityVerbose {
150+ l .logger .Info (i18n .Tr ("Skipping dependencies detection for precompiled library %[1]s" , library .Name ))
151+ }
152+ } else {
153+ for _ , sourceDir := range library .SourceDirs () {
154+ l .queueSourceFilesFromFolder (
155+ sourceFileQueue ,
156+ sourceDir .Dir , sourceDir .Recurse ,
157+ library .SourceDir ,
158+ librariesBuildPath .Join (library .DirName ),
159+ library .UtilityDir )
160+ }
161+ }
141162}
142163
143164// PrintUsedAndNotUsedLibraries todo
@@ -284,6 +305,16 @@ func (l *SketchLibrariesDetector) findIncludes(
284305 l .queueSourceFilesFromFolder (sourceFileQueue , srcSubfolderPath , true /* recurse */ , sketchBuildPath , sketchBuildPath )
285306 }
286307
308+ if l .alwaysBuildProfileLibs {
309+ for _ , library := range l .librariesManager .FindAllInstalled () {
310+ if library .Location == libraries .User {
311+ l .logger .Info (i18n .Tr ("The library %[1]s has been automatically added from sketch project." , library .Name ))
312+ l .addAndBuildLibrary (sourceFileQueue , librariesBuildPath , library )
313+ l .addIncludeFolder (library .SourceDir )
314+ }
315+ }
316+ }
317+
287318 for ! sourceFileQueue .Empty () {
288319 err := l .findMissingIncludesInCompilationUnit (ctx , sourceFileQueue , buildProperties , librariesBuildPath , platformArch )
289320 if err != nil {
@@ -452,7 +483,7 @@ func (l *SketchLibrariesDetector) findMissingIncludesInCompilationUnit(
452483 // Add this library to the list of libraries, the
453484 // include path and queue its source files for further
454485 // include scanning
455- l .AppendImportedLibraries ( library )
486+ l .addAndBuildLibrary ( sourceFileQueue , librariesBuildPath , library )
456487 l .addIncludeFolder (library .SourceDir )
457488
458489 if library .Precompiled && library .PrecompiledWithSources {
@@ -556,7 +587,7 @@ func LibrariesLoader(
556587 librariesDirs paths.PathList ,
557588 buildPlatform * cores.PlatformRelease ,
558589 targetPlatform * cores.PlatformRelease ,
559- ) (* librariesresolver.Cpp , []byte , error ) {
590+ ) (* librariesmanager. LibrariesManager , * librariesresolver.Cpp , []byte , error ) {
560591 verboseOut := & bytes.Buffer {}
561592 lm := librariesManager
562593 if useCachedLibrariesResolution {
@@ -569,7 +600,7 @@ func LibrariesLoader(
569600
570601 if builtInLibrariesDir != nil {
571602 if err := builtInLibrariesDir .ToAbs (); err != nil {
572- return nil , nil , err
603+ return nil , nil , nil , err
573604 }
574605 lmb .AddLibrariesDir (librariesmanager.LibrariesDir {
575606 Path : builtInLibrariesDir ,
@@ -592,7 +623,7 @@ func LibrariesLoader(
592623
593624 librariesFolders := librariesDirs
594625 if err := librariesFolders .ToAbs (); err != nil {
595- return nil , nil , err
626+ return nil , nil , nil , err
596627 }
597628 for _ , folder := range librariesFolders {
598629 lmb .AddLibrariesDir (librariesmanager.LibrariesDir {
@@ -618,5 +649,5 @@ func LibrariesLoader(
618649
619650 allLibs := lm .FindAllInstalled ()
620651 resolver := librariesresolver .NewCppResolver (allLibs , targetPlatform , buildPlatform )
621- return resolver , verboseOut .Bytes (), nil
652+ return lm , resolver , verboseOut .Bytes (), nil
622653}
0 commit comments