@@ -55,6 +55,7 @@ func prepareBuilderTestContext(sketchPath, fqbn string) *types.Context {
55
55
Verbose : false ,
56
56
}
57
57
}
58
+
58
59
func TestBuilderEmptySketch (t * testing.T ) {
59
60
DownloadCoresAndToolsAndLibraries (t )
60
61
@@ -64,11 +65,6 @@ func TestBuilderEmptySketch(t *testing.T) {
64
65
buildPath := SetupBuildPath (t , ctx )
65
66
defer os .RemoveAll (buildPath )
66
67
67
- // Cleanup cached core
68
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
69
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
70
- os .Remove (coreFile )
71
-
72
68
// Run builder
73
69
command := builder.Builder {}
74
70
err := command .Run (ctx )
@@ -94,11 +90,6 @@ func TestBuilderBridge(t *testing.T) {
94
90
buildPath := SetupBuildPath (t , ctx )
95
91
defer os .RemoveAll (buildPath )
96
92
97
- // Cleanup cached core
98
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
99
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
100
- os .Remove (coreFile )
101
-
102
93
// Run builder
103
94
command := builder.Builder {}
104
95
err := command .Run (ctx )
@@ -126,11 +117,6 @@ func TestBuilderSketchWithConfig(t *testing.T) {
126
117
buildPath := SetupBuildPath (t , ctx )
127
118
defer os .RemoveAll (buildPath )
128
119
129
- // Cleanup cached core
130
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
131
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
132
- os .Remove (coreFile )
133
-
134
120
// Run builder
135
121
command := builder.Builder {}
136
122
err := command .Run (ctx )
@@ -158,11 +144,6 @@ func TestBuilderBridgeTwice(t *testing.T) {
158
144
buildPath := SetupBuildPath (t , ctx )
159
145
defer os .RemoveAll (buildPath )
160
146
161
- // Cleanup cached core
162
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
163
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
164
- os .Remove (coreFile )
165
-
166
147
// Run builder
167
148
command := builder.Builder {}
168
149
err := command .Run (ctx )
@@ -191,17 +172,11 @@ func TestBuilderBridgeSAM(t *testing.T) {
191
172
DownloadCoresAndToolsAndLibraries (t )
192
173
193
174
ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "arduino:sam:arduino_due_x_dbg" )
175
+ ctx .WarningsLevel = "all"
194
176
195
177
buildPath := SetupBuildPath (t , ctx )
196
178
defer os .RemoveAll (buildPath )
197
179
198
- ctx .WarningsLevel = "all"
199
-
200
- // Cleanup cached core
201
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "sam" )
202
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
203
- os .Remove (coreFile )
204
-
205
180
// Run builder
206
181
command := builder.Builder {}
207
182
err := command .Run (ctx )
@@ -236,14 +211,10 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
236
211
ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "RedBearLab:avr:blend" )
237
212
ctx .HardwareFolders = append (ctx .HardwareFolders , "downloaded_board_manager_stuff" )
238
213
ctx .ToolsFolders = append (ctx .ToolsFolders , "downloaded_board_manager_stuff" )
214
+
239
215
buildPath := SetupBuildPath (t , ctx )
240
216
defer os .RemoveAll (buildPath )
241
217
242
- // Cleanup cached core
243
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
244
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
245
- os .Remove (coreFile )
246
-
247
218
// Run builder
248
219
command := builder.Builder {}
249
220
err := command .Run (ctx )
@@ -273,6 +244,7 @@ func TestBuilderSketchNoFunctions(t *testing.T) {
273
244
buildPath := SetupBuildPath (t , ctx )
274
245
defer os .RemoveAll (buildPath )
275
246
247
+ // Run builder
276
248
command := builder.Builder {}
277
249
err := command .Run (ctx )
278
250
require .Error (t , err )
@@ -288,6 +260,7 @@ func TestBuilderSketchWithBackup(t *testing.T) {
288
260
buildPath := SetupBuildPath (t , ctx )
289
261
defer os .RemoveAll (buildPath )
290
262
263
+ // Run builder
291
264
command := builder.Builder {}
292
265
err := command .Run (ctx )
293
266
NoError (t , err )
@@ -301,6 +274,7 @@ func TestBuilderSketchWithOldLib(t *testing.T) {
301
274
buildPath := SetupBuildPath (t , ctx )
302
275
defer os .RemoveAll (buildPath )
303
276
277
+ // Run builder
304
278
command := builder.Builder {}
305
279
err := command .Run (ctx )
306
280
NoError (t , err )
@@ -314,6 +288,7 @@ func TestBuilderSketchWithSubfolders(t *testing.T) {
314
288
buildPath := SetupBuildPath (t , ctx )
315
289
defer os .RemoveAll (buildPath )
316
290
291
+ // Run builder
317
292
command := builder.Builder {}
318
293
err := command .Run (ctx )
319
294
NoError (t , err )
@@ -329,6 +304,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin
329
304
330
305
NoError (t , os .MkdirAll (filepath .Join (buildPath , constants .FOLDER_LIBRARIES , "SPI" ), os .FileMode (0755 )))
331
306
307
+ // Run builder
332
308
command := builder.Builder {}
333
309
err := command .Run (ctx )
334
310
NoError (t , err )
@@ -350,19 +326,11 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
350
326
NoError (t , err )
351
327
defer os .RemoveAll (ctx .BuildPath )
352
328
353
- // Cleanup cached core
354
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
355
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
356
- os .Remove (coreFile )
357
-
358
329
// Run build
359
330
command := builder.Builder {}
360
331
err = command .Run (ctx )
361
332
NoError (t , err )
362
333
363
- // Cleanup cached core
364
- os .Remove (coreFile )
365
-
366
334
// Run build twice, to verify the build still works when the
367
335
// build directory is present at the start
368
336
err = command .Run (ctx )
@@ -376,24 +344,26 @@ func TestBuilderCacheCoreAFile(t *testing.T) {
376
344
377
345
SetupBuildPath (t , ctx )
378
346
defer os .RemoveAll (ctx .BuildPath )
379
-
380
- // Cleanup cached core
381
- coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
382
- coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
383
- os .Remove (coreFile )
347
+ SetupBuildCachePath (t , ctx )
348
+ defer os .RemoveAll (ctx .BuildCachePath )
384
349
385
350
// Run build
386
351
bldr := builder.Builder {}
387
352
err := bldr .Run (ctx )
388
353
NoError (t , err )
389
- coreStatBefore , err := os .Stat (coreFile )
354
+
355
+ // Pick timestamp of cached core
356
+ coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
357
+ coreFileName := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
358
+ cachedCoreFile := filepath .Join (ctx .CoreBuildCachePath , coreFileName )
359
+ coreStatBefore , err := os .Stat (cachedCoreFile )
390
360
require .NoError (t , err )
391
361
392
362
// Run build again, to verify that the builder skips rebuilding core.a
393
363
err = bldr .Run (ctx )
394
364
NoError (t , err )
395
365
396
- coreStatAfterRebuild , err := os .Stat (coreFile )
366
+ coreStatAfterRebuild , err := os .Stat (cachedCoreFile )
397
367
require .NoError (t , err )
398
368
require .Equal (t , coreStatBefore .ModTime (), coreStatAfterRebuild .ModTime ())
399
369
@@ -407,7 +377,7 @@ func TestBuilderCacheCoreAFile(t *testing.T) {
407
377
err = bldr .Run (ctx )
408
378
NoError (t , err )
409
379
410
- coreStatAfterTouch , err := os .Stat (coreFile )
380
+ coreStatAfterTouch , err := os .Stat (cachedCoreFile )
411
381
require .NoError (t , err )
412
382
require .NotEqual (t , coreStatBefore .ModTime (), coreStatAfterTouch .ModTime ())
413
383
}
0 commit comments