@@ -52,7 +52,7 @@ type SketchLibrariesDetector struct {
52
52
librariesManager * librariesmanager.LibrariesManager
53
53
librariesResolver * librariesresolver.Cpp
54
54
useCachedLibrariesResolution bool
55
- cache * includeCache
55
+ cache * detectorCache
56
56
onlyUpdateCompilationDatabase bool
57
57
importedLibraries libraries.List
58
58
librariesResolutionResults map [string ]libraryResolutionResult
@@ -74,6 +74,7 @@ func NewSketchLibrariesDetector(
74
74
librariesManager : lm ,
75
75
librariesResolver : libsResolver ,
76
76
useCachedLibrariesResolution : useCachedLibrariesResolution ,
77
+ cache : newDetectorCache (),
77
78
librariesResolutionResults : map [string ]libraryResolutionResult {},
78
79
importedLibraries : libraries.List {},
79
80
includeFolders : paths.PathList {},
@@ -175,21 +176,10 @@ func (l *SketchLibrariesDetector) IncludeFolders() paths.PathList {
175
176
return l .includeFolders
176
177
}
177
178
178
- // appendIncludeFolder todo should rename this, probably after refactoring the
179
- // container_find_includes command.
180
- // Original comment:
181
- // Append the given folder to the include path and match or append it to
182
- // the cache. sourceFilePath and include indicate the source of this
183
- // include (e.g. what #include line in what file it was resolved from)
184
- // and should be the empty string for the default include folders, like
185
- // the core or variant.
186
- func (l * SketchLibrariesDetector ) appendIncludeFolder (
187
- sourceFilePath * paths.Path ,
188
- include string ,
189
- folder * paths.Path ,
190
- ) {
179
+ // addIncludeFolder add the given folder to the include path.
180
+ func (l * SketchLibrariesDetector ) addIncludeFolder (folder * paths.Path ) {
191
181
l .includeFolders = append (l .includeFolders , folder )
192
- l .cache .ExpectEntry ( sourceFilePath , include , folder )
182
+ l .cache .Expect ( & detectorCacheEntry { AddedIncludePath : folder } )
193
183
}
194
184
195
185
// FindIncludes todo
@@ -245,11 +235,13 @@ func (l *SketchLibrariesDetector) findIncludes(
245
235
}
246
236
247
237
cachePath := buildPath .Join ("includes.cache" )
248
- l .cache = readCache (cachePath )
238
+ if err := l .cache .Load (cachePath ); err != nil {
239
+ l .logger .Warn (i18n .Tr ("Failed to load library discovery cache: %[1]s" , err ))
240
+ }
249
241
250
- l .appendIncludeFolder ( nil , "" , buildCorePath )
242
+ l .addIncludeFolder ( buildCorePath )
251
243
if buildVariantPath != nil {
252
- l .appendIncludeFolder ( nil , "" , buildVariantPath )
244
+ l .addIncludeFolder ( buildVariantPath )
253
245
}
254
246
255
247
sourceFileQueue := & uniqueSourceFileQueue {}
@@ -269,16 +261,15 @@ func (l *SketchLibrariesDetector) findIncludes(
269
261
}
270
262
271
263
for ! sourceFileQueue .Empty () {
272
- err := l .findIncludesUntilDone (ctx , sourceFileQueue , buildProperties , librariesBuildPath , platformArch )
264
+ err := l .findMissingIncludesInCompilationUnit (ctx , sourceFileQueue , buildProperties , librariesBuildPath , platformArch )
273
265
if err != nil {
274
266
cachePath .Remove ()
275
267
return err
276
268
}
277
269
}
278
270
279
271
// Finalize the cache
280
- l .cache .ExpectEnd ()
281
- if err := l .cache .write (cachePath ); err != nil {
272
+ if err := l .cache .Save (cachePath ); err != nil {
282
273
return err
283
274
}
284
275
}
@@ -296,7 +287,7 @@ func (l *SketchLibrariesDetector) findIncludes(
296
287
return nil
297
288
}
298
289
299
- func (l * SketchLibrariesDetector ) findIncludesUntilDone (
290
+ func (l * SketchLibrariesDetector ) findMissingIncludesInCompilationUnit (
300
291
ctx context.Context ,
301
292
sourceFileQueue * uniqueSourceFileQueue ,
302
293
buildProperties * properties.Map ,
@@ -328,7 +319,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
328
319
329
320
first := true
330
321
for {
331
- l .cache .ExpectFile ( sourcePath )
322
+ l .cache .Expect ( & detectorCacheEntry { CompilingSourcePath : sourcePath } )
332
323
333
324
// Libraries may require the "utility" directory to be added to the include
334
325
// search path, but only for the source code of the library, so we temporary
@@ -343,8 +334,8 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
343
334
var preprocFirstResult * runner.Result
344
335
345
336
var missingIncludeH string
346
- if unchanged && l .cache .valid {
347
- missingIncludeH = l . cache . Next (). Include
337
+ if entry := l .cache .Peek (); unchanged && entry != nil && entry . MissingIncludeH != nil {
338
+ missingIncludeH = * entry . MissingIncludeH
348
339
if first && l .logger .VerbosityLevel () == logger .VerbosityVerbose {
349
340
l .logger .Info (i18n .Tr ("Using cached library dependencies for file: %[1]s" , sourcePath ))
350
341
}
@@ -370,9 +361,10 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
370
361
}
371
362
}
372
363
364
+ l .cache .Expect (& detectorCacheEntry {MissingIncludeH : & missingIncludeH })
365
+
373
366
if missingIncludeH == "" {
374
367
// No missing includes found, we're done
375
- l .cache .ExpectEntry (sourcePath , "" , nil )
376
368
return nil
377
369
}
378
370
@@ -405,7 +397,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
405
397
// include path and queue its source files for further
406
398
// include scanning
407
399
l .AppendImportedLibraries (library )
408
- l .appendIncludeFolder ( sourcePath , missingIncludeH , library .SourceDir )
400
+ l .addIncludeFolder ( library .SourceDir )
409
401
410
402
if library .Precompiled && library .PrecompiledWithSources {
411
403
// Fully precompiled libraries should have no dependencies to avoid ABI breakage
0 commit comments