@@ -264,16 +264,16 @@ func (l *SketchLibrariesDetector) findIncludes(
264264
265265 if ! l .useCachedLibrariesResolution {
266266 sketch := sketch
267- mergedfile , err := makeSourceFile (sketchBuildPath , librariesBuildPath , sketch , paths .New (sketch .MainFile .Base ()+ ".cpp" ))
267+ mergedfile , err := makeSourceFile (sketchBuildPath , sketchBuildPath , paths .New (sketch .MainFile .Base ()+ ".cpp" ))
268268 if err != nil {
269269 return errors .WithStack (err )
270270 }
271271 sourceFileQueue .push (mergedfile )
272272
273- l .queueSourceFilesFromFolder (sketchBuildPath , librariesBuildPath , sourceFileQueue , sketch , sketchBuildPath , false /* recurse */ )
273+ l .queueSourceFilesFromFolder (sourceFileQueue , sketchBuildPath , false /* recurse */ , sketchBuildPath , sketchBuildPath )
274274 srcSubfolderPath := sketchBuildPath .Join ("src" )
275275 if srcSubfolderPath .IsDir () {
276- l .queueSourceFilesFromFolder (sketchBuildPath , librariesBuildPath , sourceFileQueue , sketch , srcSubfolderPath , true /* recurse */ )
276+ l .queueSourceFilesFromFolder (sourceFileQueue , srcSubfolderPath , true /* recurse */ , sketchBuildPath , sketchBuildPath )
277277 }
278278
279279 for ! sourceFileQueue .empty () {
@@ -419,20 +419,21 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
419419 }
420420 } else {
421421 for _ , sourceDir := range library .SourceDirs () {
422- l .queueSourceFilesFromFolder (sketchBuildPath , librariesBuildPath , sourceFileQueue , library , sourceDir .Dir , sourceDir .Recurse )
422+ l .queueSourceFilesFromFolder (sourceFileQueue , sourceDir .Dir , sourceDir .Recurse ,
423+ library .SourceDir , librariesBuildPath .Join (library .DirName ), library .UtilityDir )
423424 }
424425 }
425426 first = false
426427 }
427428}
428429
429430func (l * SketchLibrariesDetector ) queueSourceFilesFromFolder (
430- sketchBuildPath * paths.Path ,
431- librariesBuildPath * paths.Path ,
432431 sourceFileQueue * uniqueSourceFileQueue ,
433- origin interface {},
434432 folder * paths.Path ,
435433 recurse bool ,
434+ sourceDir * paths.Path ,
435+ buildDir * paths.Path ,
436+ extraIncludePath ... * paths.Path ,
436437) error {
437438 sourceFileExtensions := []string {}
438439 for k := range globals .SourceFilesValidExtensions {
@@ -444,7 +445,7 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
444445 }
445446
446447 for _ , filePath := range filePaths {
447- sourceFile , err := makeSourceFile (sketchBuildPath , librariesBuildPath , origin , filePath )
448+ sourceFile , err := makeSourceFile (sourceDir , buildDir , filePath , extraIncludePath ... )
448449 if err != nil {
449450 return errors .WithStack (err )
450451 }
@@ -537,33 +538,42 @@ func (f *sourceFile) Equals(g *sourceFile) bool {
537538// given origin. The given path can be absolute, or relative within the
538539// origin's root source folder
539540func makeSourceFile (
540- sketchBuildPath * paths.Path ,
541- librariesBuildPath * paths.Path ,
542- origin interface {} ,
543- path * paths.Path ,
541+ sourceDir * paths.Path ,
542+ buildDir * paths.Path ,
543+ sourceFilePath * paths. Path ,
544+ extraIncludePath ... * paths.Path ,
544545) (* sourceFile , error ) {
545- res := & sourceFile {}
546-
547- switch o := origin .(type ) {
548- case * sketch.Sketch :
549- res .buildRoot = sketchBuildPath
550- res .sourceRoot = sketchBuildPath
551- case * libraries.Library :
552- res .buildRoot = librariesBuildPath .Join (o .DirName )
553- res .sourceRoot = o .SourceDir
554- res .extraIncludePath = o .UtilityDir
555- default :
556- panic ("Unexpected origin for SourceFile: " + fmt .Sprint (origin ))
557- }
558-
559- if path .IsAbs () {
546+ res := & sourceFile {
547+ buildRoot : buildDir ,
548+ sourceRoot : sourceDir ,
549+ }
550+
551+ if len (extraIncludePath ) > 1 {
552+ panic ("only one extra include path allowed" )
553+ }
554+ if len (extraIncludePath ) > 0 {
555+ res .extraIncludePath = extraIncludePath [0 ]
556+ }
557+ // switch o := origin.(type) {
558+ // case *sketch.Sketch:
559+ // res.buildRoot = sketchBuildPath
560+ // res.sourceRoot = sketchBuildPath
561+ // case *libraries.Library:
562+ // res.buildRoot = librariesBuildPath.Join(o.DirName)
563+ // res.sourceRoot = o.SourceDir
564+ // res.extraIncludePath = o.UtilityDir
565+ // default:
566+ // panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
567+ // }
568+
569+ if sourceFilePath .IsAbs () {
560570 var err error
561- path , err = res .sourceRoot .RelTo (path )
571+ sourceFilePath , err = res .sourceRoot .RelTo (sourceFilePath )
562572 if err != nil {
563573 return nil , err
564574 }
565575 }
566- res .relativePath = path
576+ res .relativePath = sourceFilePath
567577 return res , nil
568578}
569579
0 commit comments