@@ -17,6 +17,7 @@ package phases
1717
1818import (
1919 "os"
20+ "strings"
2021
2122 "github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2223 "github.com/arduino/arduino-cli/legacy/builder/constants"
@@ -90,7 +91,8 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
9091
9192 var targetArchivedCore * paths.Path
9293 if buildCachePath != nil {
93- archivedCoreName := builder_utils .GetCachedCoreArchiveFileName (buildProperties .Get (constants .BUILD_PROPERTIES_FQBN ), realCoreFolder )
94+ archivedCoreName := getCachedCoreArchiveFileName (buildProperties .Get (constants .BUILD_PROPERTIES_FQBN ),
95+ buildProperties .Get ("compiler.optimization_flags" ), realCoreFolder )
9496 targetArchivedCore = buildCachePath .Join (archivedCoreName )
9597 canUseArchivedCore := ! builder_utils .CoreOrReferencedCoreHasChanged (realCoreFolder , targetCoreFolder , targetArchivedCore )
9698
@@ -129,3 +131,20 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
129131
130132 return archiveFile , variantObjectFiles , nil
131133}
134+
135+ // GetCachedCoreArchiveFileName returns the filename to be used to store
136+ // the global cached core.a.
137+ func getCachedCoreArchiveFileName (fqbn string , optimizationFlags string , coreFolder * paths.Path ) string {
138+ fqbnToUnderscore := strings .Replace (fqbn , ":" , "_" , - 1 )
139+ fqbnToUnderscore = strings .Replace (fqbnToUnderscore , "=" , "_" , - 1 )
140+ if absCoreFolder , err := coreFolder .Abs (); err == nil {
141+ coreFolder = absCoreFolder
142+ } // silently continue if absolute path can't be detected
143+ hash := utils .MD5Sum ([]byte (coreFolder .String () + optimizationFlags ))
144+ realName := "core_" + fqbnToUnderscore + "_" + hash + ".a"
145+ if len (realName ) > 100 {
146+ // avoid really long names, simply hash the final part
147+ realName = "core_" + utils .MD5Sum ([]byte (fqbnToUnderscore + "_" + hash )) + ".a"
148+ }
149+ return realName
150+ }
0 commit comments