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