@@ -122,6 +122,19 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
122122}
123123
124124func (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+
125138 cachePath := ctx .BuildPath .Join ("includes.cache" )
126139 cache := readCache (cachePath )
127140
@@ -130,38 +143,44 @@ func (s *ContainerFindIncludes) findIncludes(ctx *types.Context) error {
130143 appendIncludeFolder (ctx , cache , nil , "" , ctx .BuildProperties .GetPath ("build.variant.path" ))
131144 }
132145
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 )
139153
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+ }
146160
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 {
151172 return errors .WithStack (err )
152173 }
153174 }
154175
155- // Finalize the cache
156- cache .ExpectEnd ()
157- err = writeCache (cache , cachePath )
158- if err != nil {
176+ if err := runCommand (ctx , & FailIfImportedLibraryIsWrong {}); err != nil {
159177 return errors .WithStack (err )
160178 }
161179
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
165184 }
166185
167186 return nil
0 commit comments