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