Skip to content

Commit 765d01d

Browse files
committed
Merge branch 'master' into fix/postinstall-output
2 parents 1a71de8 + 2f5b767 commit 765d01d

24 files changed

+219
-210
lines changed

Diff for: arduino/cores/board.go

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ func (b *Board) GetBuildProperties(userConfigs *properties.Map) (*properties.Map
125125

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

129131
// Add all sub-configurations one by one (a config is: option=value)
130132
// Check for residual invalid options...

Diff for: arduino/cores/board_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,11 @@ func TestBoardOptions(t *testing.T) {
216216
expConf2560.Set("bootloader.low_fuses", "0xFF")
217217
expConf2560.Set("bootloader.tool", "avrdude")
218218
expConf2560.Set("bootloader.unlock_bits", "0x3F")
219+
expConf2560.Set("build.arch", "AVR")
219220
expConf2560.Set("build.board", "AVR_MEGA2560")
220221
expConf2560.Set("build.core", "arduino")
221222
expConf2560.Set("build.f_cpu", "16000000L")
223+
expConf2560.Set("build.fqbn", "arduino:avr:mega")
222224
expConf2560.Set("build.mcu", "atmega2560")
223225
expConf2560.Set("build.variant", "mega")
224226
expConf2560.Set("menu.cpu.atmega1280", "ATmega1280")
@@ -275,9 +277,11 @@ func TestBoardOptions(t *testing.T) {
275277
expConf1280.Set("bootloader.low_fuses", "0xFF")
276278
expConf1280.Set("bootloader.tool", "avrdude")
277279
expConf1280.Set("bootloader.unlock_bits", "0x3F")
280+
expConf1280.Set("build.arch", "AVR")
278281
expConf1280.Set("build.board", "AVR_MEGA")
279282
expConf1280.Set("build.core", "arduino")
280283
expConf1280.Set("build.f_cpu", "16000000L")
284+
expConf1280.Set("build.fqbn", "arduino:avr:mega")
281285
expConf1280.Set("build.mcu", "atmega1280")
282286
expConf1280.Set("build.variant", "mega")
283287
expConf1280.Set("menu.cpu.atmega1280", "ATmega1280")
@@ -334,9 +338,11 @@ func TestBoardOptions(t *testing.T) {
334338
expWatterott.Set("bootloader.low_fuses", "0xE2")
335339
expWatterott.Set("bootloader.tool", "avrdude")
336340
expWatterott.Set("bootloader.unlock_bits", "0xFF")
341+
expWatterott.Set("build.arch", "AVR")
337342
expWatterott.Set("build.board", "AVR_ATTINY841")
338343
expWatterott.Set("build.core", "tiny841")
339344
expWatterott.Set("build.f_cpu", "8000000L")
345+
expWatterott.Set("build.fqbn", "watterott:avr:attiny841")
340346
expWatterott.Set("build.mcu", "attiny841")
341347
expWatterott.Set("build.variant", "tiny14")
342348
expWatterott.Set("menu.core.arduino", "Standard Arduino")

Diff for: arduino/cores/cores.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ func (release *PlatformRelease) RequiresToolRelease(toolRelease *ToolRelease) bo
336336
func (release *PlatformRelease) RuntimeProperties() *properties.Map {
337337
res := properties.NewMap()
338338
if release.InstallDir != nil {
339-
res.Set("runtime.platform.path", release.InstallDir.String())
340-
res.Set("runtime.hardware.path", release.InstallDir.Join("..").String())
339+
res.SetPath("runtime.platform.path", release.InstallDir)
340+
res.SetPath("runtime.hardware.path", release.InstallDir.Join(".."))
341341
}
342342

343343
return res

Diff for: arduino/cores/packagemanager/package_manager.go

+121-25
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ package packagemanager
1818
import (
1919
"fmt"
2020
"net/url"
21+
"os"
2122
"path"
23+
"path/filepath"
24+
"strconv"
2225
"strings"
2326
"sync"
27+
"time"
2428

2529
"github.com/arduino/arduino-cli/arduino/cores"
2630
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
@@ -29,6 +33,7 @@ import (
2933
"github.com/arduino/arduino-cli/i18n"
3034
paths "github.com/arduino/go-paths-helper"
3135
properties "github.com/arduino/go-properties-orderedmap"
36+
"github.com/arduino/go-timeutils"
3237
"github.com/sirupsen/logrus"
3338
semver "go.bug.st/relaxed-semver"
3439
)
@@ -275,50 +280,141 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (
275280
return targetPackage, nil, nil, nil, nil,
276281
fmt.Errorf(tr("unknown platform %s:%s"), targetPackage, fqbn.PlatformArch)
277282
}
278-
platformRelease := pme.GetInstalledPlatformRelease(platform)
279-
if platformRelease == nil {
283+
boardPlatformRelease := pme.GetInstalledPlatformRelease(platform)
284+
if boardPlatformRelease == nil {
280285
return targetPackage, nil, nil, nil, nil,
281286
fmt.Errorf(tr("platform %s is not installed"), platform)
282287
}
283288

284289
// Find board
285-
board := platformRelease.Boards[fqbn.BoardID]
290+
board := boardPlatformRelease.Boards[fqbn.BoardID]
286291
if board == nil {
287-
return targetPackage, platformRelease, nil, nil, nil,
292+
return targetPackage, boardPlatformRelease, nil, nil, nil,
288293
fmt.Errorf(tr("board %s not found"), fqbn.StringWithoutConfig())
289294
}
290295

291-
buildProperties, err := board.GetBuildProperties(fqbn.Configs)
296+
boardBuildProperties, err := board.GetBuildProperties(fqbn.Configs)
292297
if err != nil {
293-
return targetPackage, platformRelease, board, nil, nil,
298+
return targetPackage, boardPlatformRelease, board, nil, nil,
294299
fmt.Errorf(tr("getting build properties for board %[1]s: %[2]s"), board, err)
295300
}
296301

297-
// Determine the platform used for the build (in case the board refers
302+
// Determine the platform used for the build and the variant (in case the board refers
298303
// to a core contained in another platform)
299-
buildPlatformRelease := platformRelease
300-
coreParts := strings.Split(buildProperties.Get("build.core"), ":")
301-
if len(coreParts) > 1 {
302-
referredPackage := coreParts[0]
303-
buildPackage := pme.packages[referredPackage]
304-
if buildPackage == nil {
305-
return targetPackage, platformRelease, board, buildProperties, nil,
306-
fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackage, fqbn)
304+
core, corePlatformRelease, variant, variantPlatformRelease, err := pme.determineReferencedPlatformRelease(boardBuildProperties, boardPlatformRelease, fqbn)
305+
if err != nil {
306+
return targetPackage, boardPlatformRelease, board, nil, nil, err
307+
}
308+
309+
// Create the build properties map by overlaying the properties of the
310+
// referenced platform propeties, the board platform properties and the
311+
// board specific properties.
312+
buildProperties := properties.NewMap()
313+
buildProperties.Merge(variantPlatformRelease.Properties)
314+
buildProperties.Merge(corePlatformRelease.Properties)
315+
buildProperties.Merge(boardPlatformRelease.Properties)
316+
buildProperties.Merge(boardBuildProperties)
317+
318+
// Add runtime build properties
319+
buildProperties.Merge(boardPlatformRelease.RuntimeProperties())
320+
buildProperties.SetPath("build.core.path", corePlatformRelease.InstallDir.Join("cores", core))
321+
buildProperties.SetPath("build.system.path", corePlatformRelease.InstallDir.Join("system"))
322+
buildProperties.Set("build.variant.path", "")
323+
if variant != "" {
324+
buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant))
325+
}
326+
327+
for _, tool := range pme.GetAllInstalledToolsReleases() {
328+
buildProperties.Merge(tool.RuntimeProperties())
329+
}
330+
requiredTools, err := pme.FindToolsRequiredForBuild(boardPlatformRelease, corePlatformRelease)
331+
if err != nil {
332+
return targetPackage, boardPlatformRelease, board, buildProperties, corePlatformRelease, err
333+
}
334+
for _, tool := range requiredTools {
335+
buildProperties.Merge(tool.RuntimeProperties())
336+
}
337+
now := time.Now()
338+
buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10))
339+
buildProperties.Set("extra.time.local", strconv.FormatInt(timeutils.LocalUnix(now), 10))
340+
buildProperties.Set("extra.time.zone", strconv.Itoa(timeutils.TimezoneOffsetNoDST(now)))
341+
buildProperties.Set("extra.time.dst", strconv.Itoa(timeutils.DaylightSavingsOffset(now)))
342+
343+
if !buildProperties.ContainsKey("runtime.ide.path") {
344+
if ex, err := os.Executable(); err == nil {
345+
buildProperties.Set("runtime.ide.path", filepath.Dir(ex))
346+
} else {
347+
buildProperties.Set("runtime.ide.path", "")
307348
}
308-
buildPlatform := buildPackage.Platforms[fqbn.PlatformArch]
309-
if buildPlatform == nil {
310-
return targetPackage, platformRelease, board, buildProperties, nil,
311-
fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackage, fqbn.PlatformArch, fqbn)
349+
}
350+
buildProperties.Set("runtime.os", properties.GetOSSuffix())
351+
buildProperties.Set("build.library_discovery_phase", "0")
352+
// Deprecated properties
353+
buildProperties.Set("ide_version", "10607")
354+
buildProperties.Set("runtime.ide.version", "10607")
355+
if !buildProperties.ContainsKey("software") {
356+
buildProperties.Set("software", "ARDUINO")
357+
}
358+
359+
buildProperties.Merge(pme.GetCustomGlobalProperties())
360+
361+
return targetPackage, boardPlatformRelease, board, buildProperties, corePlatformRelease, nil
362+
}
363+
364+
func (pme *Explorer) determineReferencedPlatformRelease(boardBuildProperties *properties.Map, boardPlatformRelease *cores.PlatformRelease, fqbn *cores.FQBN) (string, *cores.PlatformRelease, string, *cores.PlatformRelease, error) {
365+
core := boardBuildProperties.Get("build.core")
366+
referredCore := ""
367+
if split := strings.Split(core, ":"); len(split) > 1 {
368+
referredCore, core = split[0], split[1]
369+
}
370+
371+
variant := boardBuildProperties.Get("build.variant")
372+
referredVariant := ""
373+
if split := strings.Split(variant, ":"); len(split) > 1 {
374+
referredVariant, variant = split[0], split[1]
375+
}
376+
377+
// core and variant cannot refer to two different platforms
378+
if referredCore != "" && referredVariant != "" && referredCore != referredVariant {
379+
return "", nil, "", nil,
380+
fmt.Errorf(tr("'build.core' and 'build.variant' refer to different platforms: %[1]s and %[2]s"), referredCore+":"+core, referredVariant+":"+variant)
381+
}
382+
383+
// extract the referred platform
384+
var referredPlatformRelease *cores.PlatformRelease
385+
referredPackageName := referredCore
386+
if referredPackageName == "" {
387+
referredPackageName = referredVariant
388+
}
389+
if referredPackageName != "" {
390+
referredPackage := pme.packages[referredPackageName]
391+
if referredPackage == nil {
392+
return "", nil, "", nil,
393+
fmt.Errorf(tr("missing package %[1]s referenced by board %[2]s"), referredPackageName, fqbn)
394+
}
395+
referredPlatform := referredPackage.Platforms[fqbn.PlatformArch]
396+
if referredPlatform == nil {
397+
return "", nil, "", nil,
398+
fmt.Errorf(tr("missing platform %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn)
312399
}
313-
buildPlatformRelease = pme.GetInstalledPlatformRelease(buildPlatform)
314-
if buildPlatformRelease == nil {
315-
return targetPackage, platformRelease, board, buildProperties, nil,
316-
fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackage, fqbn.PlatformArch, fqbn)
400+
referredPlatformRelease = pme.GetInstalledPlatformRelease(referredPlatform)
401+
if referredPlatformRelease == nil {
402+
return "", nil, "", nil,
403+
fmt.Errorf(tr("missing platform release %[1]s:%[2]s referenced by board %[3]s"), referredPackageName, fqbn.PlatformArch, fqbn)
317404
}
318405
}
319406

320-
// No errors... phew!
321-
return targetPackage, platformRelease, board, buildProperties, buildPlatformRelease, nil
407+
corePlatformRelease := boardPlatformRelease
408+
if referredCore != "" {
409+
corePlatformRelease = referredPlatformRelease
410+
}
411+
412+
variantPlatformRelease := boardPlatformRelease
413+
if referredVariant != "" {
414+
variantPlatformRelease = referredPlatformRelease
415+
}
416+
417+
return core, corePlatformRelease, variant, variantPlatformRelease, nil
322418
}
323419

324420
// LoadPackageIndex loads a package index by looking up the local cached file from the specified URL

Diff for: arduino/cores/packagemanager/package_manager_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestResolveFQBN(t *testing.T) {
147147
require.Equal(t, platformRelease.Platform.String(), "referenced:avr")
148148
require.NotNil(t, board)
149149
require.Equal(t, board.Name(), "Referenced dummy with invalid package")
150-
require.NotNil(t, props)
150+
require.Nil(t, props)
151151
require.Nil(t, buildPlatformRelease)
152152

153153
// Test a board referenced from a non-existent platform/architecture
@@ -162,7 +162,7 @@ func TestResolveFQBN(t *testing.T) {
162162
require.Equal(t, platformRelease.Platform.String(), "referenced:avr")
163163
require.NotNil(t, board)
164164
require.Equal(t, board.Name(), "Referenced dummy with invalid platform")
165-
require.NotNil(t, props)
165+
require.Nil(t, props)
166166
require.Nil(t, buildPlatformRelease)
167167

168168
// Test a board referenced from a non-existent core

Diff for: commands/compile/compile.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
133133
builderCtx.BuildPath = sk.DefaultBuildPath()
134134
} else {
135135
builderCtx.BuildPath = paths.New(req.GetBuildPath()).Canonical()
136+
if in, err := builderCtx.BuildPath.IsInsideDir(sk.FullPath); err != nil {
137+
return nil, &arduino.NotFoundError{Message: tr("Cannot find build path"), Cause: err}
138+
} else if in && builderCtx.BuildPath.IsDir() {
139+
if sk.AdditionalFiles, err = removeBuildFromSketchFiles(sk.AdditionalFiles, builderCtx.BuildPath); err != nil {
140+
return nil, err
141+
}
142+
}
136143
}
137144
if err = builderCtx.BuildPath.MkdirAll(); err != nil {
138145
return nil, &arduino.PermissionDeniedError{Message: tr("Cannot create build directory"), Cause: err}
@@ -174,9 +181,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
174181

175182
builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)
176183

177-
// Will be deprecated.
178-
builderCtx.ArduinoAPIVersion = "10607"
179-
180184
builderCtx.Stdout = outStream
181185
builderCtx.Stderr = errStream
182186
builderCtx.Clean = req.GetClean()
@@ -315,3 +319,24 @@ func maybePurgeBuildCache() {
315319
buildcache.New(paths.TempDir().Join("arduino", "cores")).Purge(cacheTTL)
316320
buildcache.New(paths.TempDir().Join("arduino", "sketches")).Purge(cacheTTL)
317321
}
322+
323+
// removeBuildFromSketchFiles removes the files contained in the build directory from
324+
// the list of the sketch files
325+
func removeBuildFromSketchFiles(files paths.PathList, build *paths.Path) (paths.PathList, error) {
326+
var res paths.PathList
327+
ignored := false
328+
for _, file := range files {
329+
if in, err := file.IsInsideDir(build); err != nil {
330+
return nil, &arduino.NotFoundError{Message: tr("Cannot find build path"), Cause: err}
331+
} else if !in {
332+
res = append(res, file)
333+
} else if !ignored {
334+
ignored = true
335+
}
336+
}
337+
// log only if at least a file is ignored
338+
if ignored {
339+
logrus.Tracef("Build path %s is a child of sketch path and it is ignored for additional files.", build.String())
340+
}
341+
return res, nil
342+
}

Diff for: commands/upload/upload.go

-14
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,6 @@ func runProgramAction(pme *packagemanager.Explorer,
292292
uploadProperties.Merge(programmer.Properties)
293293
}
294294

295-
for _, tool := range pme.GetAllInstalledToolsReleases() {
296-
uploadProperties.Merge(tool.RuntimeProperties())
297-
}
298-
if requiredTools, err := pme.FindToolsRequiredForBuild(boardPlatform, buildPlatform); err == nil {
299-
for _, requiredTool := range requiredTools {
300-
logrus.WithField("tool", requiredTool).Info("Tool required for upload")
301-
if requiredTool.IsInstalled() {
302-
uploadProperties.Merge(requiredTool.RuntimeProperties())
303-
} else {
304-
errStream.Write([]byte(tr("Warning: tool '%s' is not installed. It might not be available for your OS.", requiredTool)))
305-
}
306-
}
307-
}
308-
309295
// Certain tools require the user to provide custom fields at run time,
310296
// if they've been provided set them
311297
// For more info:

Diff for: internal/integrationtest/compile_3/compile_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,27 @@ func TestRuntimeToolPropertiesGeneration(t *testing.T) {
7272
require.True(t, res.GetPath("runtime.tools.avrdude.path").EquivalentTo(hardwareDir.Join("arduino", "tools", "avrdude", "6.3.0-arduino17")))
7373
}
7474
}
75+
76+
func TestCompileBuildPathInsideSketch(t *testing.T) {
77+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
78+
defer env.CleanUp()
79+
80+
_, _, err := cli.Run("core", "update-index")
81+
require.NoError(t, err)
82+
83+
_, _, err = cli.Run("core", "install", "arduino:avr")
84+
require.NoError(t, err)
85+
86+
sketch := "sketchSimple"
87+
_, _, err = cli.Run("sketch", "new", sketch)
88+
require.NoError(t, err)
89+
90+
cli.SetWorkingDir(cli.WorkingDir().Join(sketch))
91+
// Compile the sketch creating the build directory inside the sketch directory
92+
_, _, err = cli.Run("compile", "-b", "arduino:avr:mega", "--build-path", "build-mega")
93+
require.NoError(t, err)
94+
95+
// Compile again using the same build path
96+
_, _, err = cli.Run("compile", "-b", "arduino:avr:mega", "--build-path", "build-mega")
97+
require.NoError(t, err)
98+
}

Diff for: legacy/builder/builder.go

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var tr = i18n.Tr
3131

3232
const DEFAULT_DEBUG_LEVEL = 5
3333
const DEFAULT_WARNINGS_LEVEL = "none"
34-
const DEFAULT_SOFTWARE = "ARDUINO"
3534

3635
type Builder struct{}
3736

0 commit comments

Comments
 (0)