|
16 | 16 | package compile_test
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "crypto/md5" |
| 20 | + "encoding/hex" |
| 21 | + "strings" |
19 | 22 | "testing"
|
20 | 23 |
|
21 | 24 | "github.com/arduino/arduino-cli/internal/integrationtest"
|
| 25 | + "github.com/arduino/go-paths-helper" |
22 | 26 | "github.com/stretchr/testify/require"
|
23 | 27 | "gopkg.in/src-d/go-git.v4"
|
24 | 28 | "gopkg.in/src-d/go-git.v4/plumbing"
|
@@ -116,3 +120,61 @@ func TestCompileWithLibraryPriority(t *testing.T) {
|
116 | 120 | }
|
117 | 121 | require.Contains(t, string(stdout), expectedOutput[0]+"\n"+expectedOutput[1]+"\n"+expectedOutput[2]+"\n")
|
118 | 122 | }
|
| 123 | + |
| 124 | +func TestRecompileWithDifferentLibrary(t *testing.T) { |
| 125 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 126 | + defer env.CleanUp() |
| 127 | + |
| 128 | + _, _, err := cli.Run("update") |
| 129 | + require.NoError(t, err) |
| 130 | + |
| 131 | + _, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") |
| 132 | + require.NoError(t, err) |
| 133 | + |
| 134 | + sketchName := "RecompileCompileSketchWithDifferentLibrary" |
| 135 | + sketchPath := cli.SketchbookDir().Join(sketchName) |
| 136 | + fqbn := "arduino:avr:uno" |
| 137 | + |
| 138 | + // Install library |
| 139 | + _, _, err = cli.Run("lib", "install", "WiFi101") |
| 140 | + require.NoError(t, err) |
| 141 | + |
| 142 | + // Manually installs a library |
| 143 | + gitUrl := "https://github.com/arduino-libraries/WiFi101.git" |
| 144 | + manuallyInstalledLibPath := cli.SketchbookDir().Join("my-libraries", "WiFi101") |
| 145 | + _, err = git.PlainClone(manuallyInstalledLibPath.String(), false, &git.CloneOptions{ |
| 146 | + URL: gitUrl, |
| 147 | + ReferenceName: plumbing.NewTagReferenceName("0.16.1"), |
| 148 | + }) |
| 149 | + require.NoError(t, err) |
| 150 | + |
| 151 | + // Create new sketch and add library include |
| 152 | + _, _, err = cli.Run("sketch", "new", sketchPath.String()) |
| 153 | + require.NoError(t, err) |
| 154 | + sketchFile := sketchPath.Join(sketchName + ".ino") |
| 155 | + lines, err := sketchFile.ReadFileAsLines() |
| 156 | + require.NoError(t, err) |
| 157 | + lines = append([]string{"#include <WiFi101.h>\n"}, lines...) |
| 158 | + var data []byte |
| 159 | + for _, l := range lines { |
| 160 | + data = append(data, []byte(l)...) |
| 161 | + } |
| 162 | + err = sketchFile.WriteFile(data) |
| 163 | + require.NoError(t, err) |
| 164 | + |
| 165 | + md5 := md5.Sum(([]byte(sketchPath.String()))) |
| 166 | + sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) |
| 167 | + require.NotEmpty(t, sketchPathMd5) |
| 168 | + buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) |
| 169 | + |
| 170 | + // Compile sketch using library not managed by CLI |
| 171 | + stdout, _, err := cli.Run("compile", "-b", fqbn, "--library", manuallyInstalledLibPath.String(), sketchPath.String(), "-v") |
| 172 | + require.NoError(t, err) |
| 173 | + objPath := buildDir.Join("libraries", "WiFi101", "WiFi.cpp.o") |
| 174 | + require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String()) |
| 175 | + |
| 176 | + // Compile again using library installed from CLI |
| 177 | + stdout, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "-v") |
| 178 | + require.NoError(t, err) |
| 179 | + require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String()) |
| 180 | +} |
0 commit comments