@@ -146,11 +146,6 @@ func (l *SketchLibrariesDetector) AppendImportedLibraries(library *libraries.Lib
146
146
l .importedLibraries = append (l .importedLibraries , library )
147
147
}
148
148
149
- // UseCachedLibrariesResolution todo
150
- func (l * SketchLibrariesDetector ) UseCachedLibrariesResolution () bool {
151
- return l .useCachedLibrariesResolution
152
- }
153
-
154
149
// PrintUsedAndNotUsedLibraries todo
155
150
func (l * SketchLibrariesDetector ) PrintUsedAndNotUsedLibraries (sketchError bool ) {
156
151
// Print this message:
@@ -182,20 +177,21 @@ func (l *SketchLibrariesDetector) PrintUsedAndNotUsedLibraries(sketchError bool)
182
177
time .Sleep (100 * time .Millisecond )
183
178
}
184
179
180
+ // IncludeFolders fixdoc
185
181
func (l * SketchLibrariesDetector ) IncludeFolders () paths.PathList {
186
182
// TODO should we do a deep copy?
187
183
return l .includeFolders
188
184
}
189
185
190
- // AppendIncludeFolder todo should rename this, probably after refactoring the
186
+ // appendIncludeFolder todo should rename this, probably after refactoring the
191
187
// container_find_includes command.
192
188
// Original comment:
193
189
// Append the given folder to the include path and match or append it to
194
190
// the cache. sourceFilePath and include indicate the source of this
195
191
// include (e.g. what #include line in what file it was resolved from)
196
192
// and should be the empty string for the default include folders, like
197
193
// the core or variant.
198
- func (l * SketchLibrariesDetector ) AppendIncludeFolder (
194
+ func (l * SketchLibrariesDetector ) appendIncludeFolder (
199
195
cache * includeCache ,
200
196
sourceFilePath * paths.Path ,
201
197
include string ,
@@ -242,13 +238,13 @@ func (l *SketchLibrariesDetector) findIncludes(
242
238
) error {
243
239
librariesResolutionCache := buildPath .Join ("libraries.cache" )
244
240
if l .useCachedLibrariesResolution && librariesResolutionCache .Exist () {
245
- if d , err := librariesResolutionCache .ReadFile (); err != nil {
241
+ d , err := librariesResolutionCache .ReadFile ()
242
+ if err != nil {
243
+ return err
244
+ }
245
+ includeFolders := l .includeFolders
246
+ if err := json .Unmarshal (d , & includeFolders ); err != nil {
246
247
return err
247
- } else {
248
- includeFolders := l .includeFolders
249
- if err := json .Unmarshal (d , & includeFolders ); err != nil {
250
- return err
251
- }
252
248
}
253
249
if l .verbose {
254
250
l .verboseInfoFn ("Using cached library discovery: " + librariesResolutionCache .String ())
@@ -259,28 +255,28 @@ func (l *SketchLibrariesDetector) findIncludes(
259
255
cachePath := buildPath .Join ("includes.cache" )
260
256
cache := readCache (cachePath )
261
257
262
- l .AppendIncludeFolder (cache , nil , "" , buildCorePath )
258
+ l .appendIncludeFolder (cache , nil , "" , buildCorePath )
263
259
if buildVariantPath != nil {
264
- l .AppendIncludeFolder (cache , nil , "" , buildVariantPath )
260
+ l .appendIncludeFolder (cache , nil , "" , buildVariantPath )
265
261
}
266
262
267
- sourceFileQueue := & UniqueSourceFileQueue {}
263
+ sourceFileQueue := & uniqueSourceFileQueue {}
268
264
269
265
if ! l .useCachedLibrariesResolution {
270
266
sketch := sketch
271
- mergedfile , err := MakeSourceFile (sketchBuildPath , librariesBuildPath , sketch , paths .New (sketch .MainFile .Base ()+ ".cpp" ))
267
+ mergedfile , err := makeSourceFile (sketchBuildPath , librariesBuildPath , sketch , paths .New (sketch .MainFile .Base ()+ ".cpp" ))
272
268
if err != nil {
273
269
return errors .WithStack (err )
274
270
}
275
- sourceFileQueue .Push (mergedfile )
271
+ sourceFileQueue .push (mergedfile )
276
272
277
273
l .queueSourceFilesFromFolder (sketchBuildPath , librariesBuildPath , sourceFileQueue , sketch , sketchBuildPath , false /* recurse */ )
278
274
srcSubfolderPath := sketchBuildPath .Join ("src" )
279
275
if srcSubfolderPath .IsDir () {
280
276
l .queueSourceFilesFromFolder (sketchBuildPath , librariesBuildPath , sourceFileQueue , sketch , srcSubfolderPath , true /* recurse */ )
281
277
}
282
278
283
- for ! sourceFileQueue .Empty () {
279
+ for ! sourceFileQueue .empty () {
284
280
err := l .findIncludesUntilDone (cache , sourceFileQueue , buildProperties , sketchBuildPath , librariesBuildPath , platformArch )
285
281
if err != nil {
286
282
cachePath .Remove ()
@@ -310,13 +306,13 @@ func (l *SketchLibrariesDetector) findIncludes(
310
306
311
307
func (l * SketchLibrariesDetector ) findIncludesUntilDone (
312
308
cache * includeCache ,
313
- sourceFileQueue * UniqueSourceFileQueue ,
309
+ sourceFileQueue * uniqueSourceFileQueue ,
314
310
buildProperties * properties.Map ,
315
311
sketchBuildPath * paths.Path ,
316
312
librariesBuildPath * paths.Path ,
317
313
platformArch string ,
318
314
) error {
319
- sourceFile := sourceFileQueue .Pop ()
315
+ sourceFile := sourceFileQueue .pop ()
320
316
sourcePath := sourceFile .SourcePath ()
321
317
targetFilePath := paths .NullPath ()
322
318
depPath := sourceFile .DepfilePath ()
@@ -414,7 +410,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
414
410
// include path and queue its source files for further
415
411
// include scanning
416
412
l .AppendImportedLibraries (library )
417
- l .AppendIncludeFolder (cache , sourcePath , missingIncludeH , library .SourceDir )
413
+ l .appendIncludeFolder (cache , sourcePath , missingIncludeH , library .SourceDir )
418
414
419
415
if library .Precompiled && library .PrecompiledWithSources {
420
416
// Fully precompiled libraries should have no dependencies to avoid ABI breakage
@@ -433,7 +429,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
433
429
func (l * SketchLibrariesDetector ) queueSourceFilesFromFolder (
434
430
sketchBuildPath * paths.Path ,
435
431
librariesBuildPath * paths.Path ,
436
- sourceFileQueue * UniqueSourceFileQueue ,
432
+ sourceFileQueue * uniqueSourceFileQueue ,
437
433
origin interface {},
438
434
folder * paths.Path ,
439
435
recurse bool ,
@@ -448,11 +444,11 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
448
444
}
449
445
450
446
for _ , filePath := range filePaths {
451
- sourceFile , err := MakeSourceFile (sketchBuildPath , librariesBuildPath , origin , filePath )
447
+ sourceFile , err := makeSourceFile (sketchBuildPath , librariesBuildPath , origin , filePath )
452
448
if err != nil {
453
449
return errors .WithStack (err )
454
450
}
455
- sourceFileQueue .Push (sourceFile )
451
+ sourceFileQueue .push (sourceFile )
456
452
}
457
453
458
454
return nil
@@ -484,10 +480,12 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
484
480
return nil
485
481
}
486
482
487
- var INCLUDE_REGEXP = regexp .MustCompile ("(?ms)^\\ s*#[ \t ]*include\\ s*[<\" ](\\ S+)[\" >]" )
483
+ // includeRegexp fixdoc
484
+ var includeRegexp = regexp .MustCompile ("(?ms)^\\ s*#[ \t ]*include\\ s*[<\" ](\\ S+)[\" >]" )
488
485
486
+ // IncludesFinderWithRegExp fixdoc
489
487
func IncludesFinderWithRegExp (source string ) string {
490
- match := INCLUDE_REGEXP .FindStringSubmatch (source )
488
+ match := includeRegexp .FindStringSubmatch (source )
491
489
if match != nil {
492
490
return strings .TrimSpace (match [1 ])
493
491
}
@@ -507,7 +505,7 @@ func findIncludeForOldCompilers(source string) string {
507
505
return ""
508
506
}
509
507
510
- type SourceFile struct {
508
+ type sourceFile struct {
511
509
// Path to the source file within the sketch/library root folder
512
510
relativePath * paths.Path
513
511
@@ -528,22 +526,23 @@ type SourceFile struct {
528
526
buildRoot * paths.Path
529
527
}
530
528
531
- func (f * SourceFile ) Equals (g * SourceFile ) bool {
529
+ // Equals fixdoc
530
+ func (f * sourceFile ) Equals (g * sourceFile ) bool {
532
531
return f .relativePath .EqualsTo (g .relativePath ) &&
533
532
f .buildRoot .EqualsTo (g .buildRoot ) &&
534
533
f .sourceRoot .EqualsTo (g .sourceRoot )
535
534
}
536
535
537
- // Create a SourceFile containing the given source file path within the
536
+ // makeSourceFile containing the given source file path within the
538
537
// given origin. The given path can be absolute, or relative within the
539
538
// origin's root source folder
540
- func MakeSourceFile (
539
+ func makeSourceFile (
541
540
sketchBuildPath * paths.Path ,
542
541
librariesBuildPath * paths.Path ,
543
542
origin interface {},
544
543
path * paths.Path ,
545
- ) (* SourceFile , error ) {
546
- res := & SourceFile {}
544
+ ) (* sourceFile , error ) {
545
+ res := & sourceFile {}
547
546
548
547
switch o := origin .(type ) {
549
548
case * sketch.Sketch :
@@ -568,19 +567,23 @@ func MakeSourceFile(
568
567
return res , nil
569
568
}
570
569
571
- func (f * SourceFile ) ExtraIncludePath () * paths.Path {
570
+ // ExtraIncludePath fixdoc
571
+ func (f * sourceFile ) ExtraIncludePath () * paths.Path {
572
572
return f .extraIncludePath
573
573
}
574
574
575
- func (f * SourceFile ) SourcePath () * paths.Path {
575
+ // SourcePath fixdoc
576
+ func (f * sourceFile ) SourcePath () * paths.Path {
576
577
return f .sourceRoot .JoinPath (f .relativePath )
577
578
}
578
579
579
- func (f * SourceFile ) ObjectPath () * paths.Path {
580
+ // ObjectPath fixdoc
581
+ func (f * sourceFile ) ObjectPath () * paths.Path {
580
582
return f .buildRoot .Join (f .relativePath .String () + ".o" )
581
583
}
582
584
583
- func (f * SourceFile ) DepfilePath () * paths.Path {
585
+ // DepfilePath fixdoc
586
+ func (f * sourceFile ) DepfilePath () * paths.Path {
584
587
return f .buildRoot .Join (f .relativePath .String () + ".d" )
585
588
}
586
589
@@ -658,21 +661,19 @@ func LibrariesLoader(
658
661
return lm , resolver , verboseOut .Bytes (), nil
659
662
}
660
663
661
- func (l * SketchLibrariesDetector ) OnlyUpdateCompilationDatabase () bool {
662
- return l .onlyUpdateCompilationDatabase
663
- }
664
-
665
664
type includeCacheEntry struct {
666
665
Sourcefile * paths.Path
667
666
Include string
668
667
Includepath * paths.Path
669
668
}
670
669
670
+ // String fixdoc
671
671
func (entry * includeCacheEntry ) String () string {
672
672
return fmt .Sprintf ("SourceFile: %s; Include: %s; IncludePath: %s" ,
673
673
entry .Sourcefile , entry .Include , entry .Includepath )
674
674
}
675
675
676
+ // Equals fixdoc
676
677
func (entry * includeCacheEntry ) Equals (other * includeCacheEntry ) bool {
677
678
return entry .String () == other .String ()
678
679
}
@@ -686,14 +687,14 @@ type includeCache struct {
686
687
entries []* includeCacheEntry
687
688
}
688
689
689
- // Return the next cache entry. Should only be called when the cache is
690
+ // Next Return the next cache entry. Should only be called when the cache is
690
691
// valid and a next entry is available (the latter can be checked with
691
692
// ExpectFile). Does not advance the cache.
692
693
func (cache * includeCache ) Next () * includeCacheEntry {
693
694
return cache .entries [cache .next ]
694
695
}
695
696
696
- // Check that the next cache entry is about the given file. If it is
697
+ // ExpectFile check that the next cache entry is about the given file. If it is
697
698
// not, or no entry is available, the cache is invalidated. Does not
698
699
// advance the cache.
699
700
func (cache * includeCache ) ExpectFile (sourcefile * paths.Path ) {
@@ -703,7 +704,7 @@ func (cache *includeCache) ExpectFile(sourcefile *paths.Path) {
703
704
}
704
705
}
705
706
706
- // Check that the next entry matches the given values. If so, advance
707
+ // ExpectEntry check that the next entry matches the given values. If so, advance
707
708
// the cache. If not, the cache is invalidated. If the cache is
708
709
// invalidated, or was already invalid, an entry with the given values
709
710
// is appended.
@@ -723,7 +724,7 @@ func (cache *includeCache) ExpectEntry(sourcefile *paths.Path, include string, l
723
724
}
724
725
}
725
726
726
- // Check that the cache is completely consumed. If not, the cache is
727
+ // ExpectEnd check that the cache is completely consumed. If not, the cache is
727
728
// invalidated.
728
729
func (cache * includeCache ) ExpectEnd () {
729
730
if cache .valid && cache .next < len (cache .entries ) {
@@ -771,25 +772,25 @@ func writeCache(cache *includeCache, path *paths.Path) error {
771
772
return nil
772
773
}
773
774
774
- type UniqueSourceFileQueue []* SourceFile
775
+ type uniqueSourceFileQueue []* sourceFile
775
776
776
- func (queue * UniqueSourceFileQueue ) Push (value * SourceFile ) {
777
- if ! queue .Contains (value ) {
777
+ func (queue * uniqueSourceFileQueue ) push (value * sourceFile ) {
778
+ if ! queue .contains (value ) {
778
779
* queue = append (* queue , value )
779
780
}
780
781
}
781
782
782
- func (queue UniqueSourceFileQueue ) Contains (target * SourceFile ) bool {
783
+ func (queue uniqueSourceFileQueue ) contains (target * sourceFile ) bool {
783
784
return slices .ContainsFunc (queue , target .Equals )
784
785
}
785
786
786
- func (queue * UniqueSourceFileQueue ) Pop () * SourceFile {
787
+ func (queue * uniqueSourceFileQueue ) pop () * sourceFile {
787
788
old := * queue
788
789
x := old [0 ]
789
790
* queue = old [1 :]
790
791
return x
791
792
}
792
793
793
- func (queue UniqueSourceFileQueue ) Empty () bool {
794
+ func (queue uniqueSourceFileQueue ) empty () bool {
794
795
return len (queue ) == 0
795
796
}
0 commit comments