@@ -122,6 +122,19 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
122
122
}
123
123
124
124
func (s * ContainerFindIncludes ) findIncludes (ctx * types.Context ) error {
125
+ librariesResolutionCache := ctx .BuildPath .Join ("libraries.cache" )
126
+ if ctx .UseCachedLibrariesResolution && librariesResolutionCache .Exist () {
127
+ if d , err := librariesResolutionCache .ReadFile (); err != nil {
128
+ return err
129
+ } else if err := json .Unmarshal (d , & ctx .IncludeFolders ); err != nil {
130
+ return err
131
+ }
132
+ if ctx .Verbose {
133
+ ctx .Info ("Using cached library discovery: " + librariesResolutionCache .String ())
134
+ }
135
+ return nil
136
+ }
137
+
125
138
cachePath := ctx .BuildPath .Join ("includes.cache" )
126
139
cache := readCache (cachePath )
127
140
@@ -130,38 +143,44 @@ func (s *ContainerFindIncludes) findIncludes(ctx *types.Context) error {
130
143
appendIncludeFolder (ctx , cache , nil , "" , ctx .BuildProperties .GetPath ("build.variant.path" ))
131
144
}
132
145
133
- sketch := ctx .Sketch
134
- mergedfile , err := types .MakeSourceFile (ctx , sketch , paths .New (sketch .MainFile .Base ()+ ".cpp" ))
135
- if err != nil {
136
- return errors .WithStack (err )
137
- }
138
- ctx .CollectedSourceFiles .Push (mergedfile )
146
+ if ! ctx .UseCachedLibrariesResolution {
147
+ sketch := ctx .Sketch
148
+ mergedfile , err := types .MakeSourceFile (ctx , sketch , paths .New (sketch .MainFile .Base ()+ ".cpp" ))
149
+ if err != nil {
150
+ return errors .WithStack (err )
151
+ }
152
+ ctx .CollectedSourceFiles .Push (mergedfile )
139
153
140
- sourceFilePaths := ctx .CollectedSourceFiles
141
- queueSourceFilesFromFolder (ctx , sourceFilePaths , sketch , ctx .SketchBuildPath , false /* recurse */ )
142
- srcSubfolderPath := ctx .SketchBuildPath .Join ("src" )
143
- if srcSubfolderPath .IsDir () {
144
- queueSourceFilesFromFolder (ctx , sourceFilePaths , sketch , srcSubfolderPath , true /* recurse */ )
145
- }
154
+ sourceFilePaths := ctx .CollectedSourceFiles
155
+ queueSourceFilesFromFolder (ctx , sourceFilePaths , sketch , ctx .SketchBuildPath , false /* recurse */ )
156
+ srcSubfolderPath := ctx .SketchBuildPath .Join ("src" )
157
+ if srcSubfolderPath .IsDir () {
158
+ queueSourceFilesFromFolder (ctx , sourceFilePaths , sketch , srcSubfolderPath , true /* recurse */ )
159
+ }
146
160
147
- for ! sourceFilePaths .Empty () {
148
- err := findIncludesUntilDone (ctx , cache , sourceFilePaths .Pop ())
149
- if err != nil {
150
- cachePath .Remove ()
161
+ for ! sourceFilePaths .Empty () {
162
+ err := findIncludesUntilDone (ctx , cache , sourceFilePaths .Pop ())
163
+ if err != nil {
164
+ cachePath .Remove ()
165
+ return errors .WithStack (err )
166
+ }
167
+ }
168
+
169
+ // Finalize the cache
170
+ cache .ExpectEnd ()
171
+ if err := writeCache (cache , cachePath ); err != nil {
151
172
return errors .WithStack (err )
152
173
}
153
174
}
154
175
155
- // Finalize the cache
156
- cache .ExpectEnd ()
157
- err = writeCache (cache , cachePath )
158
- if err != nil {
176
+ if err := runCommand (ctx , & FailIfImportedLibraryIsWrong {}); err != nil {
159
177
return errors .WithStack (err )
160
178
}
161
179
162
- err = runCommand (ctx , & FailIfImportedLibraryIsWrong {})
163
- if err != nil {
164
- return errors .WithStack (err )
180
+ if d , err := json .Marshal (ctx .IncludeFolders ); err != nil {
181
+ return err
182
+ } else if err := librariesResolutionCache .WriteFile (d ); err != nil {
183
+ return err
165
184
}
166
185
167
186
return nil
0 commit comments