Skip to content

Archive compiled core and use on subsequent compilations #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test for core caching
Signed-off-by: Cristian Maglie <c.maglie@arduino.cc>
  • Loading branch information
cmaglie committed Mar 2, 2017
commit 61a81f97341bd847c8051894e72cbcbb82d6fb2c
60 changes: 56 additions & 4 deletions src/arduino.cc/builder/test/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@
package test

import (
"arduino.cc/builder"
"arduino.cc/builder/constants"
"arduino.cc/builder/types"
"github.com/stretchr/testify/require"
"os"
"os/exec"
"path/filepath"
"testing"
"time"

"arduino.cc/builder"
"arduino.cc/builder/builder_utils"
"arduino.cc/builder/constants"
"arduino.cc/builder/types"
"github.com/stretchr/testify/require"
)

func TestBuilderEmptySketch(t *testing.T) {
Expand Down Expand Up @@ -410,3 +413,52 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
err = command.Run(ctx)
NoError(t, err)
}

func TestBuilderCacheCoreAFile(t *testing.T) {
DownloadCoresAndToolsAndLibraries(t)

ctx := &types.Context{
HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"},
ToolsFolders: []string{"downloaded_tools"},
BuiltInLibrariesFolders: []string{"downloaded_libraries"},
OtherLibrariesFolders: []string{"libraries"},
SketchLocation: filepath.Join("sketch1", "sketch.ino"),
FQBN: "arduino:avr:uno",
ArduinoAPIVersion: "10801",
}
SetupBuildPath(t, ctx)
defer os.RemoveAll(ctx.BuildPath)

// Cleanup cached core
coreFile := builder_utils.GetCoreArchivePath(ctx.FQBN)
os.Remove(coreFile)

// Run build
bldr := builder.Builder{}
err := bldr.Run(ctx)
NoError(t, err)
coreStatBefore, err := os.Stat(coreFile)
require.NoError(t, err)

// Run build again, to verify that the builder skips rebuilding core.a
err = bldr.Run(ctx)
NoError(t, err)

coreStatAfterRebuild, err := os.Stat(coreFile)
require.NoError(t, err)
require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime())

// Touch a file of the core and check if the builder invalidate the cache
time.Sleep(time.Second)
now := time.Now().Local()
err = os.Chtimes(filepath.Join("downloaded_hardware", "arduino", "avr", "cores", "arduino", "Arduino.h"), now, now)
require.NoError(t, err)

// Run build again, to verify that the builder rebuilds core.a
err = bldr.Run(ctx)
NoError(t, err)

coreStatAfterTouch, err := os.Stat(coreFile)
require.NoError(t, err)
require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime())
}