|
30 | 30 | package test
|
31 | 31 |
|
32 | 32 | import (
|
33 |
| - "arduino.cc/builder" |
34 |
| - "arduino.cc/builder/constants" |
35 |
| - "arduino.cc/builder/types" |
36 |
| - "github.com/stretchr/testify/require" |
37 | 33 | "os"
|
38 | 34 | "os/exec"
|
39 | 35 | "path/filepath"
|
40 | 36 | "testing"
|
| 37 | + "time" |
| 38 | + |
| 39 | + "arduino.cc/builder" |
| 40 | + "arduino.cc/builder/builder_utils" |
| 41 | + "arduino.cc/builder/constants" |
| 42 | + "arduino.cc/builder/types" |
| 43 | + "github.com/stretchr/testify/require" |
41 | 44 | )
|
42 | 45 |
|
43 | 46 | func TestBuilderEmptySketch(t *testing.T) {
|
@@ -410,3 +413,52 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
|
410 | 413 | err = command.Run(ctx)
|
411 | 414 | NoError(t, err)
|
412 | 415 | }
|
| 416 | + |
| 417 | +func TestBuilderCacheCoreAFile(t *testing.T) { |
| 418 | + DownloadCoresAndToolsAndLibraries(t) |
| 419 | + |
| 420 | + ctx := &types.Context{ |
| 421 | + HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}, |
| 422 | + ToolsFolders: []string{"downloaded_tools"}, |
| 423 | + BuiltInLibrariesFolders: []string{"downloaded_libraries"}, |
| 424 | + OtherLibrariesFolders: []string{"libraries"}, |
| 425 | + SketchLocation: filepath.Join("sketch1", "sketch.ino"), |
| 426 | + FQBN: "arduino:avr:uno", |
| 427 | + ArduinoAPIVersion: "10801", |
| 428 | + } |
| 429 | + SetupBuildPath(t, ctx) |
| 430 | + defer os.RemoveAll(ctx.BuildPath) |
| 431 | + |
| 432 | + // Cleanup cached core |
| 433 | + coreFile := builder_utils.GetCoreArchivePath(ctx.FQBN) |
| 434 | + os.Remove(coreFile) |
| 435 | + |
| 436 | + // Run build |
| 437 | + bldr := builder.Builder{} |
| 438 | + err := bldr.Run(ctx) |
| 439 | + NoError(t, err) |
| 440 | + coreStatBefore, err := os.Stat(coreFile) |
| 441 | + require.NoError(t, err) |
| 442 | + |
| 443 | + // Run build again, to verify that the builder skips rebuilding core.a |
| 444 | + err = bldr.Run(ctx) |
| 445 | + NoError(t, err) |
| 446 | + |
| 447 | + coreStatAfterRebuild, err := os.Stat(coreFile) |
| 448 | + require.NoError(t, err) |
| 449 | + require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime()) |
| 450 | + |
| 451 | + // Touch a file of the core and check if the builder invalidate the cache |
| 452 | + time.Sleep(time.Second) |
| 453 | + now := time.Now().Local() |
| 454 | + err = os.Chtimes(filepath.Join("downloaded_hardware", "arduino", "avr", "cores", "arduino", "Arduino.h"), now, now) |
| 455 | + require.NoError(t, err) |
| 456 | + |
| 457 | + // Run build again, to verify that the builder rebuilds core.a |
| 458 | + err = bldr.Run(ctx) |
| 459 | + NoError(t, err) |
| 460 | + |
| 461 | + coreStatAfterTouch, err := os.Stat(coreFile) |
| 462 | + require.NoError(t, err) |
| 463 | + require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime()) |
| 464 | +} |
0 commit comments