@@ -144,16 +144,16 @@ func (f *CppIncludesFinder) DetectLibraries() error {
144
144
f .appendIncludeFolder (nil , "" , f .ctx .BuildProperties .GetPath ("build.variant.path" ))
145
145
}
146
146
147
- mergedfile , err := MakeSourceFile (f .ctx , f . sketch , paths .New (f .sketch .MainFile .Name .Base ()+ ".cpp" ))
147
+ mergedfile , err := MakeSourceFile (f .ctx , nil , paths .New (f .sketch .MainFile .Name .Base ()+ ".cpp" ))
148
148
if err != nil {
149
149
return errors .WithStack (err )
150
150
}
151
151
f .queue .Push (mergedfile )
152
152
153
- f .queueSourceFilesFromFolder (f . sketch , f .ctx .SketchBuildPath , false /* recurse */ )
153
+ f .queueSourceFilesFromFolder (nil , f .ctx .SketchBuildPath , false /* recurse */ )
154
154
srcSubfolderPath := f .ctx .SketchBuildPath .Join ("src" )
155
155
if srcSubfolderPath .IsDir () {
156
- f .queueSourceFilesFromFolder (f . sketch , srcSubfolderPath , true /* recurse */ )
156
+ f .queueSourceFilesFromFolder (nil , srcSubfolderPath , true /* recurse */ )
157
157
}
158
158
159
159
for ! f .queue .Empty () {
@@ -332,8 +332,8 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
332
332
f .cache .ExpectFile (sourcePath )
333
333
334
334
includes := f .ctx .IncludeFolders
335
- if library , ok := sourceFile .Origin .( * libraries. Library ); ok && library .UtilityDir != nil {
336
- includes = append (includes , library .UtilityDir )
335
+ if sourceFile .Library != nil && sourceFile . Library .UtilityDir != nil {
336
+ includes = append (includes , sourceFile . Library .UtilityDir )
337
337
}
338
338
var preproc_err error
339
339
var preproc_stderr []byte
@@ -401,7 +401,7 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile SourceFile) error {
401
401
}
402
402
}
403
403
404
- func (f * CppIncludesFinder ) queueSourceFilesFromFolder (origin interface {} , folder * paths.Path , recurse bool ) error {
404
+ func (f * CppIncludesFinder ) queueSourceFilesFromFolder (lib * libraries. Library , folder * paths.Path , recurse bool ) error {
405
405
extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
406
406
407
407
filePaths := []string {}
@@ -411,7 +411,7 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(origin interface{}, folde
411
411
}
412
412
413
413
for _ , filePath := range filePaths {
414
- sourceFile , err := MakeSourceFile (f .ctx , origin , paths .New (filePath ))
414
+ sourceFile , err := MakeSourceFile (f .ctx , lib , paths .New (filePath ))
415
415
if err != nil {
416
416
return errors .WithStack (err )
417
417
}
@@ -422,64 +422,57 @@ func (f *CppIncludesFinder) queueSourceFilesFromFolder(origin interface{}, folde
422
422
}
423
423
424
424
type SourceFile struct {
425
- // Sketch or Library pointer that this source file lives in
426
- Origin interface {}
425
+ // Library pointer that this source file lives in or nil if not part of a library
426
+ Library * libraries.Library
427
+
427
428
// Path to the source file within the sketch/library root folder
428
429
RelativePath * paths.Path
429
430
}
430
431
431
432
// Create a SourceFile containing the given source file path within the
432
433
// given origin. The given path can be absolute, or relative within the
433
434
// origin's root source folder
434
- func MakeSourceFile (ctx * types.Context , origin interface {} , path * paths.Path ) (SourceFile , error ) {
435
+ func MakeSourceFile (ctx * types.Context , lib * libraries. Library , path * paths.Path ) (SourceFile , error ) {
435
436
if path .IsAbs () {
436
437
var err error
437
- path , err = sourceRoot (ctx , origin ).RelTo (path )
438
+ path , err = sourceRoot (ctx , lib ).RelTo (path )
438
439
if err != nil {
439
440
return SourceFile {}, err
440
441
}
441
442
}
442
- return SourceFile {Origin : origin , RelativePath : path }, nil
443
+ return SourceFile {Library : lib , RelativePath : path }, nil
443
444
}
444
445
445
446
// Return the build root for the given origin, where build products will
446
447
// be placed. Any directories inside SourceFile.RelativePath will be
447
448
// appended here.
448
- func buildRoot (ctx * types.Context , origin interface {}) * paths.Path {
449
- switch o := origin .(type ) {
450
- case * types.Sketch :
449
+ func buildRoot (ctx * types.Context , lib * libraries.Library ) * paths.Path {
450
+ if lib == nil {
451
451
return ctx .SketchBuildPath
452
- case * libraries.Library :
453
- return ctx .LibrariesBuildPath .Join (o .Name )
454
- default :
455
- panic ("Unexpected origin for SourceFile: " + fmt .Sprint (origin ))
456
452
}
453
+ return ctx .LibrariesBuildPath .Join (lib .Name )
457
454
}
458
455
459
456
// Return the source root for the given origin, where its source files
460
457
// can be found. Prepending this to SourceFile.RelativePath will give
461
458
// the full path to that source file.
462
- func sourceRoot (ctx * types.Context , origin interface {}) * paths.Path {
463
- switch o := origin .(type ) {
464
- case * types.Sketch :
459
+ func sourceRoot (ctx * types.Context , lib * libraries.Library ) * paths.Path {
460
+ if lib == nil {
465
461
return ctx .SketchBuildPath
466
- case * libraries.Library :
467
- return o .SourceDir
468
- default :
469
- panic ("Unexpected origin for SourceFile: " + fmt .Sprint (origin ))
470
462
}
463
+ return lib .SourceDir
471
464
}
472
465
473
466
func (f * SourceFile ) SourcePath (ctx * types.Context ) * paths.Path {
474
- return sourceRoot (ctx , f .Origin ).JoinPath (f .RelativePath )
467
+ return sourceRoot (ctx , f .Library ).JoinPath (f .RelativePath )
475
468
}
476
469
477
470
func (f * SourceFile ) ObjectPath (ctx * types.Context ) * paths.Path {
478
- return buildRoot (ctx , f .Origin ).Join (f .RelativePath .String () + ".o" )
471
+ return buildRoot (ctx , f .Library ).Join (f .RelativePath .String () + ".o" )
479
472
}
480
473
481
474
func (f * SourceFile ) DepfilePath (ctx * types.Context ) * paths.Path {
482
- return buildRoot (ctx , f .Origin ).Join (f .RelativePath .String () + ".d" )
475
+ return buildRoot (ctx , f .Library ).Join (f .RelativePath .String () + ".d" )
483
476
}
484
477
485
478
type UniqueSourceFileQueue struct {
@@ -509,7 +502,7 @@ func (q *UniqueSourceFileQueue) Empty() bool {
509
502
510
503
func (q * UniqueSourceFileQueue ) Contains (target SourceFile ) bool {
511
504
for _ , elem := range q .queue {
512
- if elem .Origin == target .Origin && elem .RelativePath .EqualsTo (target .RelativePath ) {
505
+ if elem .Library == target .Library && elem .RelativePath .EqualsTo (target .RelativePath ) {
513
506
return true
514
507
}
515
508
}
0 commit comments