Skip to content

Commit edf0c50

Browse files
author
rsora
committed
Calculate precompiled core path usign also build optimization flags
1 parent a0e0951 commit edf0c50

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

legacy/builder/builder_utils/utils.go

-17
Original file line numberDiff line numberDiff line change
@@ -519,20 +519,3 @@ func PrepareCommandForRecipe(ctx *types.Context, buildProperties *properties.Map
519519

520520
return command, nil
521521
}
522-
523-
// GetCachedCoreArchiveFileName returns the filename to be used to store
524-
// the global cached core.a.
525-
func GetCachedCoreArchiveFileName(fqbn string, coreFolder *paths.Path) string {
526-
fqbnToUnderscore := strings.Replace(fqbn, ":", "_", -1)
527-
fqbnToUnderscore = strings.Replace(fqbnToUnderscore, "=", "_", -1)
528-
if absCoreFolder, err := coreFolder.Abs(); err == nil {
529-
coreFolder = absCoreFolder
530-
} // silently continue if absolute path can't be detected
531-
hash := utils.MD5Sum([]byte(coreFolder.String()))
532-
realName := "core_" + fqbnToUnderscore + "_" + hash + ".a"
533-
if len(realName) > 100 {
534-
// avoid really long names, simply hash the final part
535-
realName = "core_" + utils.MD5Sum([]byte(fqbnToUnderscore+"_"+hash)) + ".a"
536-
}
537-
return realName
538-
}

legacy/builder/phases/core_builder.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package phases
1717

1818
import (
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

Comments
 (0)