1616package phases
1717
1818import (
19+ "fmt"
1920 "os"
2021 "strings"
2122
@@ -92,11 +93,13 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
9293 realCoreFolder := coreFolder .Parent ().Parent ()
9394
9495 var targetArchivedCore * paths.Path
96+ var buildCacheErr error
9597 if buildCachePath != nil {
9698 archivedCoreName := GetCachedCoreArchiveDirName (buildProperties .Get (constants .BUILD_PROPERTIES_FQBN ),
9799 buildProperties .Get ("compiler.optimization_flags" ), realCoreFolder )
98- buildcache .GetOrCreate (buildCachePath .Join (archivedCoreName ))
99100 targetArchivedCore = buildCachePath .Join (archivedCoreName , "core.a" )
101+ _ , buildCacheErr = buildcache .GetOrCreate (targetArchivedCore .Parent ())
102+
100103 canUseArchivedCore := ! ctx .OnlyUpdateCompilationDatabase &&
101104 ! ctx .Clean &&
102105 ! builder_utils .CoreOrReferencedCoreHasChanged (realCoreFolder , targetCoreFolder , targetArchivedCore )
@@ -122,6 +125,11 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
122125
123126 // archive core.a
124127 if targetArchivedCore != nil && ! ctx .OnlyUpdateCompilationDatabase {
128+ if buildCacheErr != nil {
129+ if err := targetArchivedCore .Parent ().Mkdir (); err != nil {
130+ return nil , nil , fmt .Errorf (tr ("creating core cache folder: %s" , err ))
131+ }
132+ }
125133 err := archiveFile .CopyTo (targetArchivedCore )
126134 if ctx .Verbose {
127135 if err == nil {
0 commit comments