Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 042f76a

Browse files
authored
[breaking] Fix regression in core caching (#2145)
* Added integration test * Removing useless constants * Fixed regression in core caching * Updated tests
1 parent ea066cc commit 042f76a

File tree

9 files changed

+112
-13
lines changed

9 files changed

+112
-13
lines changed

‎arduino/cores/board.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ func (b *Board) GetConfigOptionValues(option string) *properties.Map {
116116

117117
// GetBuildProperties returns the build properties and the build
118118
// platform for the Board with the configuration passed as parameter.
119-
func (b *Board) GetBuildProperties(userConfigs*properties.Map) (*properties.Map, error) {
119+
func (b *Board) GetBuildProperties(fqbn*FQBN) (*properties.Map, error) {
120120
b.buildConfigOptionsStructures()
121121

122122
// Override default configs with user configs
123123
config := b.defaultConfig.Clone()
124-
config.Merge(userConfigs)
124+
config.Merge(fqbn.Configs)
125125

126126
// Start with board's base properties
127127
buildProperties := b.Properties.Clone()
128-
buildProperties.Set("build.fqbn", b.FQBN())
128+
buildProperties.Set("build.fqbn", fqbn.String())
129129
buildProperties.Set("build.arch", strings.ToUpper(b.PlatformRelease.Platform.Architecture))
130130

131131
// Add all sub-configurations one by one (a config is: option=value)
@@ -157,7 +157,7 @@ func (b *Board) GeneratePropertiesForConfiguration(config string) (*properties.M
157157
if err != nil {
158158
return nil, fmt.Errorf(tr("parsing fqbn: %s"), err)
159159
}
160-
return b.GetBuildProperties(fqbn.Configs)
160+
return b.GetBuildProperties(fqbn)
161161
}
162162

163163
// GetIdentificationProperties calculates and returns a list of properties sets

‎arduino/cores/board_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestBoardOptions(t *testing.T) {
220220
expConf2560.Set("build.board", "AVR_MEGA2560")
221221
expConf2560.Set("build.core", "arduino")
222222
expConf2560.Set("build.f_cpu", "16000000L")
223-
expConf2560.Set("build.fqbn", "arduino:avr:mega")
223+
expConf2560.Set("build.fqbn", "arduino:avr:mega:cpu=atmega2560")
224224
expConf2560.Set("build.mcu", "atmega2560")
225225
expConf2560.Set("build.variant", "mega")
226226
expConf2560.Set("menu.cpu.atmega1280", "ATmega1280")
@@ -281,7 +281,7 @@ func TestBoardOptions(t *testing.T) {
281281
expConf1280.Set("build.board", "AVR_MEGA")
282282
expConf1280.Set("build.core", "arduino")
283283
expConf1280.Set("build.f_cpu", "16000000L")
284-
expConf1280.Set("build.fqbn", "arduino:avr:mega")
284+
expConf1280.Set("build.fqbn", "arduino:avr:mega:cpu=atmega1280")
285285
expConf1280.Set("build.mcu", "atmega1280")
286286
expConf1280.Set("build.variant", "mega")
287287
expConf1280.Set("menu.cpu.atmega1280", "ATmega1280")
@@ -342,7 +342,7 @@ func TestBoardOptions(t *testing.T) {
342342
expWatterott.Set("build.board", "AVR_ATTINY841")
343343
expWatterott.Set("build.core", "tiny841")
344344
expWatterott.Set("build.f_cpu", "8000000L")
345-
expWatterott.Set("build.fqbn", "watterott:avr:attiny841")
345+
expWatterott.Set("build.fqbn", "watterott:avr:attiny841:core=spencekonde,info=info")
346346
expWatterott.Set("build.mcu", "attiny841")
347347
expWatterott.Set("build.variant", "tiny14")
348348
expWatterott.Set("menu.core.arduino", "Standard Arduino")

‎arduino/cores/packagemanager/package_manager.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
303303
fmt.Errorf(tr("board %s not found"), fqbn.StringWithoutConfig())
304304
}
305305

306-
boardBuildProperties, err := board.GetBuildProperties(fqbn.Configs)
306+
boardBuildProperties, err := board.GetBuildProperties(fqbn)
307307
if err != nil {
308308
return targetPackage, boardPlatformRelease, board, nil, nil,
309309
fmt.Errorf(tr("getting build properties for board %[1]s: %[2]s"), board, err)

‎docs/UPGRADING.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
Here you can find a list of migration guides to handle breaking changes between releases of the CLI.
44

5+
## 0.32.2
6+
7+
### golang API: method `github.com/arduino/arduino-cli/arduino/cores/Board.GetBuildProperties` changed signature
8+
9+
The method:
10+
11+
```go
12+
func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map, error) { ... }
13+
```
14+
15+
now requires a full `FQBN` object;
16+
17+
```go
18+
func (b *Board) GetBuildProperties(fqbn *FQBN) (*properties.Map, error) { ... }
19+
```
20+
21+
Existing code may be updated from:
22+
23+
```go
24+
b.GetBuildProperties(fqbn.Configs)
25+
```
26+
27+
to
28+
29+
```
30+
b.GetBuildProperties(fqbn)
31+
```
32+
533
## 0.32.0
634

735
### `arduino-cli` doesn't lookup anymore in the current directory for configuration file.

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ require (
5151
github.com/rogpeppe/go-internal v1.3.0
5252
github.com/xeipuuv/gojsonschema v1.2.0
5353
go.bug.st/testifyjson v1.1.1
54+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
5455
golang.org/x/term v0.6.0
5556
gopkg.in/yaml.v3 v3.0.1
5657
)

‎go.sum‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
155155
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
156156
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
157157
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
158-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
159158
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
159+
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
160160
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
161161
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
162162
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -397,6 +397,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
397397
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
398398
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
399399
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
400+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
401+
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
400402
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
401403
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
402404
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -602,7 +604,6 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
602604
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
603605
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
604606
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
605-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
606607
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
607608
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
608609
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package compile_test
17+
18+
import (
19+
"strings"
20+
"testing"
21+
22+
"github.com/arduino/arduino-cli/internal/integrationtest"
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/stretchr/testify/require"
25+
"golang.org/x/exp/slices"
26+
)
27+
28+
func TestCompileCoreCacheGeneration(t *testing.T) {
29+
// See:
30+
// https://forum.arduino.cc/t/teensy-compile-sketch-fails-clear-out-temp-build-completes/1110104/6
31+
// https://forum.pjrc.com/threads/72572-Teensyduino-1-59-Beta-2?p=324071&viewfull=1#post324071
32+
// https://github.com/arduino/arduino-ide/issues/1990
33+
34+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
35+
defer env.CleanUp()
36+
37+
// Run update-index with our test index
38+
_, _, err := cli.Run("core", "install", "arduino:avr@1.8.5")
39+
require.NoError(t, err)
40+
41+
// Prepare sketch
42+
sketch, err := paths.New("testdata", "bare_minimum").Abs()
43+
require.NoError(t, err)
44+
45+
// Perform two compile that should result in different cached cores
46+
_, _, err = cli.Run("compile", "-b", "arduino:avr:mega", sketch.String())
47+
require.NoError(t, err)
48+
_, _, err = cli.Run("compile", "-b", "arduino:avr:mega:cpu=atmega1280", sketch.String())
49+
require.NoError(t, err)
50+
51+
// Perform the same compile again and track the cached cores
52+
extractCachedCoreFromStdout := func(stdout []byte) string {
53+
prefix := "Using precompiled core: "
54+
lines := strings.Split(string(stdout), "\n")
55+
i := slices.IndexFunc(lines, func(l string) bool {
56+
return strings.Contains(l, prefix)
57+
})
58+
require.NotEqual(t, -1, i, "Could not find precompiled core in output")
59+
return strings.TrimPrefix(lines[i], prefix)
60+
}
61+
stdout, _, err := cli.Run("compile", "-b", "arduino:avr:mega", sketch.String(), "-v")
62+
require.NoError(t, err)
63+
core1 := extractCachedCoreFromStdout(stdout)
64+
stdout, _, err = cli.Run("compile", "-b", "arduino:avr:mega:cpu=atmega1280", sketch.String(), "-v")
65+
require.NoError(t, err)
66+
core2 := extractCachedCoreFromStdout(stdout)
67+
require.NotEqual(t, core1, core2, "Precompile core must be different!")
68+
}

‎legacy/builder/constants/constants.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS = "compiler.c.elf.flags"
2828
const BUILD_PROPERTIES_COMPILER_LDFLAGS = "compiler.ldflags"
2929
const BUILD_PROPERTIES_COMPILER_CPP_FLAGS = "compiler.cpp.flags"
3030
const BUILD_PROPERTIES_COMPILER_WARNING_FLAGS = "compiler.warning_flags"
31-
const BUILD_PROPERTIES_FQBN = "build.fqbn"
3231
const BUILD_PROPERTIES_INCLUDES = "includes"
3332
const BUILD_PROPERTIES_OBJECT_FILE = "object_file"
3433
const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path"

‎legacy/builder/phases/core_builder.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
9595
var targetArchivedCore *paths.Path
9696
var buildCacheErr error
9797
if buildCachePath != nil {
98-
archivedCoreName := GetCachedCoreArchiveDirName(buildProperties.Get(constants.BUILD_PROPERTIES_FQBN),
99-
buildProperties.Get("compiler.optimization_flags"), realCoreFolder)
98+
archivedCoreName := GetCachedCoreArchiveDirName(
99+
buildProperties.Get("build.fqbn"),
100+
buildProperties.Get("compiler.optimization_flags"),
101+
realCoreFolder)
100102
targetArchivedCore = buildCachePath.Join(archivedCoreName, "core.a")
101103
_, buildCacheErr = buildcache.New(buildCachePath).GetOrCreate(archivedCoreName)
102104

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /