@@ -116,9 +116,16 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
116
116
if variantPath := ctx .BuildProperties .GetPath ("build.variant.path" ); variantPath != nil {
117
117
finder .UseIncludeDir (variantPath )
118
118
}
119
+ finder .AddSourceFile (ctx .SketchBuildPath , ctx .SketchBuildPath , paths .New (ctx .Sketch .MainFile .Name .Base ()+ ".cpp" ))
120
+ finder .AddSourceDir (ctx .SketchBuildPath , ctx .SketchBuildPath , false /* recurse */ )
121
+ if srcSubfolderPath := ctx .SketchBuildPath .Join ("src" ); srcSubfolderPath .IsDir () {
122
+ finder .AddSourceDir (srcSubfolderPath , ctx .SketchBuildPath , true /* recurse */ )
123
+ }
124
+
119
125
if err := finder .DetectLibraries (); err != nil {
120
126
return err
121
127
}
128
+
122
129
ctx .IncludeFolders .AddAllMissing (finder .IncludeDirsFound )
123
130
if err := runCommand (ctx , & FailIfImportedLibraryIsWrong {}); err != nil {
124
131
return errors .WithStack (err )
@@ -134,19 +141,17 @@ type CppIncludesFinder struct {
134
141
IncludeDirsFound paths.PathList
135
142
ctx * types.Context
136
143
cache * includeCache
137
- sketch * types.Sketch
138
144
queue * UniqueSourceFileQueue
139
145
log * logrus.Entry
140
146
}
141
147
142
148
// NewCppIncludesFinder create a new include
143
149
func NewCppIncludesFinder (ctx * types.Context ) * CppIncludesFinder {
144
150
return & CppIncludesFinder {
145
- ctx : ctx ,
146
- cache : loadCacheFrom (ctx .BuildPath .Join ("includes.cache" )),
147
- sketch : ctx .Sketch ,
148
- queue : & UniqueSourceFileQueue {},
149
- log : logrus .WithField ("task" , "DetectingLibraries" ),
151
+ ctx : ctx ,
152
+ cache : loadCacheFrom (ctx .BuildPath .Join ("includes.cache" )),
153
+ queue : & UniqueSourceFileQueue {},
154
+ log : logrus .WithField ("task" , "DetectingLibraries" ),
150
155
}
151
156
}
152
157
@@ -157,19 +162,6 @@ func (f *CppIncludesFinder) DetectLibraries() error {
157
162
f .cache .AddAndCheckEntry (nil , "" , includeDir )
158
163
}
159
164
160
- mergedfile , err := MakeSourceFile (f .ctx .SketchBuildPath , f .ctx .SketchBuildPath , paths .New (f .sketch .MainFile .Name .Base ()+ ".cpp" ))
161
- if err != nil {
162
- return errors .WithStack (err )
163
- }
164
- f .log .Debugf ("Queueing merged sketch: %s" , mergedfile )
165
- f .queue .Push (mergedfile )
166
-
167
- f .queueSourceFilesFromFolder (f .ctx .SketchBuildPath , f .ctx .SketchBuildPath , false /* recurse */ )
168
- srcSubfolderPath := f .ctx .SketchBuildPath .Join ("src" )
169
- if srcSubfolderPath .IsDir () {
170
- f .queueSourceFilesFromFolder (srcSubfolderPath , f .ctx .SketchBuildPath , true /* recurse */ )
171
- }
172
-
173
165
for ! f .queue .Empty () {
174
166
if err := f .findIncludesUntilDone (f .queue .Pop ()); err != nil {
175
167
f .cache .Remove ()
@@ -190,6 +182,38 @@ func (f *CppIncludesFinder) UseIncludeDir(includeDir *paths.Path) {
190
182
f .IncludeDirsFound .Add (includeDir )
191
183
}
192
184
185
+ // AddSourceFile adds a source file to be examined to look for library imports
186
+ func (f * CppIncludesFinder ) AddSourceFile (sourceRoot , buildRoot , srcPath * paths.Path ) error {
187
+ if file , err := MakeSourceFile (sourceRoot , buildRoot , srcPath ); err == nil {
188
+ f .log .Debugf ("Queueing source file: %s" , file )
189
+ f .queue .Push (file )
190
+ } else {
191
+ return errors .WithStack (err )
192
+ }
193
+ return nil
194
+ }
195
+
196
+ // AddSourceDir adds a directory of source file to be examined to look for library imports
197
+ func (f * CppIncludesFinder ) AddSourceDir (srcDir , buildDir * paths.Path , recurse bool ) error {
198
+ extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
199
+ f .log .Debugf (" Queueing source files from %s (recurse %v)" , srcDir , recurse )
200
+ filePaths , err := utils .FindFilesInFolder (srcDir .String (), extensions , recurse )
201
+ if err != nil {
202
+ return errors .WithStack (err )
203
+ }
204
+
205
+ for _ , filePath := range filePaths {
206
+ sourceFile , err := MakeSourceFile (srcDir , buildDir , paths .New (filePath ))
207
+ if err != nil {
208
+ return errors .WithStack (err )
209
+ }
210
+ f .log .Debugf (" Queuing %s" , sourceFile )
211
+ f .queue .Push (sourceFile )
212
+ }
213
+
214
+ return nil
215
+ }
216
+
193
217
func runCommand (ctx * types.Context , command types.Command ) error {
194
218
PrintRingNameIfDebug (ctx , command )
195
219
err := command .Run (ctx )
@@ -426,32 +450,12 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile *SourceFile) error
426
450
sourceDirs := library .SourceDirs ()
427
451
buildDir := f .ctx .LibrariesBuildPath .Join (library .Name )
428
452
for _ , sourceDir := range sourceDirs {
429
- f .queueSourceFilesFromFolder (buildDir , sourceDir .Dir , sourceDir .Recurse )
453
+ f .AddSourceDir (buildDir , sourceDir .Dir , sourceDir .Recurse )
430
454
}
431
455
first = false
432
456
}
433
457
}
434
458
435
- func (f * CppIncludesFinder ) queueSourceFilesFromFolder (srcDir , buildDir * paths.Path , recurse bool ) error {
436
- extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
437
- f .log .Debugf (" Queueing source files from %s (recurse %v)" , srcDir , recurse )
438
- filePaths , err := utils .FindFilesInFolder (srcDir .String (), extensions , recurse )
439
- if err != nil {
440
- return errors .WithStack (err )
441
- }
442
-
443
- for _ , filePath := range filePaths {
444
- sourceFile , err := MakeSourceFile (srcDir , buildDir , paths .New (filePath ))
445
- if err != nil {
446
- return errors .WithStack (err )
447
- }
448
- f .log .Debugf (" Queuing %s" , sourceFile )
449
- f .queue .Push (sourceFile )
450
- }
451
-
452
- return nil
453
- }
454
-
455
459
// SourceFile represent a source file, it keeps a reference to the root source
456
460
// directory and the corresponding build root directory.
457
461
type SourceFile struct {
0 commit comments