Skip to content

Commit ca9f34d

Browse files
committed
Cached core.a filename now depends on core path too
Signed-off-by: Cristian Maglie <[email protected]>
1 parent 61a81f9 commit ca9f34d

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

src/arduino.cc/builder/builder_utils/utils.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,14 @@ func CopyFile(src, dst string) (err error) {
462462
return
463463
}
464464

465-
func GetCoreArchivePath(fqbn string) string {
465+
// GetCachedCoreArchiveFileName returns the filename to be used to store
466+
// the global cached core.a.
467+
func GetCachedCoreArchiveFileName(fqbn, coreFolder string) string {
466468
fqbnToUnderscore := strings.Replace(fqbn, ":", "_", -1)
467469
fqbnToUnderscore = strings.Replace(fqbnToUnderscore, "=", "_", -1)
468-
return os.TempDir() + "/core_" + fqbnToUnderscore + ".a"
470+
if absCoreFolder, err := filepath.Abs(coreFolder); err == nil {
471+
coreFolder = absCoreFolder
472+
} // silently continue if absolute path can't be detected
473+
hash := utils.MD5Sum([]byte(coreFolder))
474+
return os.TempDir() + "/core_" + fqbnToUnderscore + "_" + hash + ".a"
469475
}

src/arduino.cc/builder/phases/core_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func compileCore(buildPath string, buildProperties properties.Map, verbose bool,
8989
// Recreate the archive if ANY of the core files (including platform.txt) has changed
9090
realCoreFolder := utils.GetParentFolder(coreFolder, 2)
9191

92-
targetArchivedCore := builder_utils.GetCoreArchivePath(buildProperties[constants.BUILD_PROPERTIES_FQBN])
92+
targetArchivedCore := builder_utils.GetCachedCoreArchiveFileName(buildProperties[constants.BUILD_PROPERTIES_FQBN], realCoreFolder)
9393
canUseArchivedCore := !builder_utils.CoreOrReferencedCoreHasChanged(realCoreFolder, targetCoreFolder, targetArchivedCore)
9494

9595
if canUseArchivedCore {

src/arduino.cc/builder/test/builder_test.go

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func TestBuilderEmptySketch(t *testing.T) {
6262

6363
ctx.DebugLevel = 10
6464

65+
// Cleanup cached core
66+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
67+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
68+
os.Remove(coreFile)
69+
70+
// Run builder
6571
command := builder.Builder{}
6672
err := command.Run(ctx)
6773
NoError(t, err)
@@ -95,6 +101,12 @@ func TestBuilderBridge(t *testing.T) {
95101
buildPath := SetupBuildPath(t, ctx)
96102
defer os.RemoveAll(buildPath)
97103

104+
// Cleanup cached core
105+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
106+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
107+
os.Remove(coreFile)
108+
109+
// Run builder
98110
command := builder.Builder{}
99111
err := command.Run(ctx)
100112
NoError(t, err)
@@ -129,14 +141,16 @@ func TestBuilderSketchWithConfig(t *testing.T) {
129141
buildPath := SetupBuildPath(t, ctx)
130142
defer os.RemoveAll(buildPath)
131143

144+
// Cleanup cached core
145+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
146+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
147+
os.Remove(coreFile)
148+
149+
// Run builder
132150
command := builder.Builder{}
133151
err := command.Run(ctx)
134152
NoError(t, err)
135153

136-
// Cleanup cached core
137-
coreFile := builder_utils.GetCoreArchivePath(ctx.FQBN)
138-
os.Remove(coreFile)
139-
140154
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
141155
NoError(t, err)
142156
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
@@ -167,18 +181,21 @@ func TestBuilderBridgeTwice(t *testing.T) {
167181
buildPath := SetupBuildPath(t, ctx)
168182
defer os.RemoveAll(buildPath)
169183

184+
// Cleanup cached core
185+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
186+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
187+
os.Remove(coreFile)
188+
189+
// Run builder
170190
command := builder.Builder{}
171191
err := command.Run(ctx)
172192
NoError(t, err)
173193

194+
// Run builder again
174195
command = builder.Builder{}
175196
err = command.Run(ctx)
176197
NoError(t, err)
177198

178-
// Cleanup cached core
179-
coreFile := builder_utils.GetCoreArchivePath(ctx.FQBN)
180-
os.Remove(coreFile)
181-
182199
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_CORE, "HardwareSerial.cpp.o"))
183200
NoError(t, err)
184201
_, err = os.Stat(filepath.Join(buildPath, constants.FOLDER_PREPROC, constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E))
@@ -211,6 +228,12 @@ func TestBuilderBridgeSAM(t *testing.T) {
211228

212229
ctx.WarningsLevel = "all"
213230

231+
// Cleanup cached core
232+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "sam")
233+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
234+
os.Remove(coreFile)
235+
236+
// Run builder
214237
command := builder.Builder{}
215238
err := command.Run(ctx)
216239
NoError(t, err)
@@ -254,6 +277,12 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
254277
buildPath := SetupBuildPath(t, ctx)
255278
defer os.RemoveAll(buildPath)
256279

280+
// Cleanup cached core
281+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
282+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
283+
os.Remove(coreFile)
284+
285+
// Run builder
257286
command := builder.Builder{}
258287
err := command.Run(ctx)
259288
NoError(t, err)
@@ -404,10 +433,19 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
404433
NoError(t, err)
405434
defer os.RemoveAll(ctx.BuildPath)
406435

436+
// Cleanup cached core
437+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
438+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
439+
os.Remove(coreFile)
440+
441+
// Run build
407442
command := builder.Builder{}
408443
err = command.Run(ctx)
409444
NoError(t, err)
410445

446+
// Cleanup cached core
447+
os.Remove(coreFile)
448+
411449
// Run build twice, to verify the build still works when the
412450
// build directory is present at the start
413451
err = command.Run(ctx)
@@ -430,7 +468,8 @@ func TestBuilderCacheCoreAFile(t *testing.T) {
430468
defer os.RemoveAll(ctx.BuildPath)
431469

432470
// Cleanup cached core
433-
coreFile := builder_utils.GetCoreArchivePath(ctx.FQBN)
471+
coreFolder := filepath.Join("downloaded_hardware", "arduino", "avr")
472+
coreFile := builder_utils.GetCachedCoreArchiveFileName(ctx.FQBN, coreFolder)
434473
os.Remove(coreFile)
435474

436475
// Run build
@@ -451,7 +490,7 @@ func TestBuilderCacheCoreAFile(t *testing.T) {
451490
// Touch a file of the core and check if the builder invalidate the cache
452491
time.Sleep(time.Second)
453492
now := time.Now().Local()
454-
err = os.Chtimes(filepath.Join("downloaded_hardware", "arduino", "avr", "cores", "arduino", "Arduino.h"), now, now)
493+
err = os.Chtimes(filepath.Join(coreFolder, "cores", "arduino", "Arduino.h"), now, now)
455494
require.NoError(t, err)
456495

457496
// Run build again, to verify that the builder rebuilds core.a

0 commit comments

Comments
 (0)