@@ -17,6 +17,7 @@ package phases
17
17
18
18
import (
19
19
"os"
20
+ "strings"
20
21
21
22
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
22
23
"github.com/arduino/arduino-cli/legacy/builder/constants"
@@ -90,7 +91,8 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
90
91
91
92
var targetArchivedCore * paths.Path
92
93
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 )
94
96
targetArchivedCore = buildCachePath .Join (archivedCoreName )
95
97
canUseArchivedCore := ! builder_utils .CoreOrReferencedCoreHasChanged (realCoreFolder , targetCoreFolder , targetArchivedCore )
96
98
@@ -129,3 +131,20 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
129
131
130
132
return archiveFile , variantObjectFiles , nil
131
133
}
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