Skip to content

Commit

Permalink
Improved {build.*.platform.path} vars enumeration. (#2652)
Browse files Browse the repository at this point in the history
* Improved build.*.platform.path vars enumeration

* Updated docs

* Added tests

* Added a compatibility note
  • Loading branch information
cmaglie authored Jul 26, 2024
1 parent 8b6ad25 commit b8c927b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
15 changes: 11 additions & 4 deletions docs/platform-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ suffixes are `.linux`, `.windows` and `.macosx`.

The following automatically generated properties can be used globally in all configuration files:

- `{runtime.platform.path}`: the absolute path of the [board platform](#platform-terminology) folder (i.e. the folder
containing boards.txt)
- `{runtime.platform.path}`: is the absolute path of the [board platform](#platform-terminology) folder (i.e. the folder
containing boards.txt) unless `{runtime.use_core_platform_path_for_runtime_platform_path}` is set to `true` in this
case, the value is the absolute path of the referenced core platform.
- `{runtime.hardware.path}`: the absolute path of the hardware folder (i.e. the folder containing the
[board platform](#platform-terminology) folder)
- `{runtime.ide.path}`: the absolute path of the Arduino IDE or Arduino CLI folder
Expand Down Expand Up @@ -113,8 +114,11 @@ The following automatically generated properties can be used globally in all con
- `{extra.time.zone}`: local timezone offset without the DST component
- `{extra.time.dst}`: local daylight savings time offset

Compatibility note: Versions before Arduino IDE 1.6.0 only used one digit per version number component in
`{runtime.ide.version}` (so 1.5.9 was `159`, not `10509`).
Compatibility notes:

- Versions before Arduino IDE 1.6.0 only used one digit per version number component in `{runtime.ide.version}` (so
1.5.9 was `159`, not `10509`).
- `{runtime.use_core_platform_path_for_runtime_platform_path}` support is available from Arduino CLI >=1.0.4.

## platform.txt

Expand Down Expand Up @@ -534,6 +538,9 @@ This explains the presence of **{build.mcu}** or **{build.board}** in the platfo
overwritten respectively by **{uno.build.mcu}** and **{uno.build.board}** when the Uno board is selected! Moreover the
following properties are automatically generated:

- `{build.board.platform.path}`: The path to the selected board's platform. (available since Arduino CLI >=1.0.4)
- `{build.core.platform.path}`: The path to the core's platform. It may differ from the board's platform path because
the latter may reference a core from another platform. (available since Arduino CLI >=1.0.4)
- `{build.core.path}`: The path to the selected board's core folder (inside the [core platform](#platform-terminology),
for example hardware/arduino/avr/core/arduino)
- `{build.system.path}`: The path to the [core platform](#platform-terminology)'s system folder if available (for
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
go.bug.st/cleanup v1.0.0
go.bug.st/downloader/v2 v2.2.0
go.bug.st/relaxed-semver v0.12.0
go.bug.st/testifyjson v1.1.1
go.bug.st/testifyjson v1.2.0
golang.org/x/term v0.22.0
golang.org/x/text v0.16.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ go.bug.st/relaxed-semver v0.12.0 h1:se8v3lTdAAFp68+/RS/0Y/nFdnpdzkP5ICY04SPau4E=
go.bug.st/relaxed-semver v0.12.0/go.mod h1:Cpcbiig6Omwlq6bS7i3MQWiqS7W7HDd8CAnZFC40Cl0=
go.bug.st/serial v1.6.1 h1:VSSWmUxlj1T/YlRo2J104Zv3wJFrjHIl/T3NeruWAHY=
go.bug.st/serial v1.6.1/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE=
go.bug.st/testifyjson v1.1.1 h1:nHotIMK151LF3vYsU/b2RaoVaWCgrf2kvQeGNoZkGaA=
go.bug.st/testifyjson v1.1.1/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
go.bug.st/testifyjson v1.2.0 h1:0pAfOUMVCOJ6bb9JcC4UmnACjxwxv2Ojb6Z9chaQBjg=
go.bug.st/testifyjson v1.2.0/go.mod h1:nZyy2icFbv3OE3zW3mGVOnC/GhWgb93LRu+29n2tJlI=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
Expand Down
5 changes: 5 additions & 0 deletions internal/arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,17 @@ func (pme *Explorer) ResolveFQBN(fqbn *cores.FQBN) (

// Add runtime build properties
buildProperties.Merge(boardPlatformRelease.RuntimeProperties())
buildProperties.SetPath("build.board.platform.path", boardPlatformRelease.InstallDir)
buildProperties.SetPath("build.core.platform.path", corePlatformRelease.InstallDir)
buildProperties.SetPath("build.core.path", corePlatformRelease.InstallDir.Join("cores", core))
buildProperties.SetPath("build.system.path", corePlatformRelease.InstallDir.Join("system"))
buildProperties.Set("build.variant.path", "")
if variant != "" {
buildProperties.SetPath("build.variant.path", variantPlatformRelease.InstallDir.Join("variants", variant))
}
if buildProperties.GetBoolean("runtime.use_core_platform_path_for_runtime_platform_path") {
buildProperties.Set("runtime.platform.path", buildProperties.Get("build.core.platform.path"))
}

for _, tool := range pme.GetAllInstalledToolsReleases() {
buildProperties.Merge(tool.RuntimeProperties())
Expand Down
48 changes: 48 additions & 0 deletions internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package core_test
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -1303,3 +1304,50 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
require.Contains(t, lines, []string{"incompatible_vendor:avr", "n/a", "Incompatible", "Boards"})
}
}

func TestReferencedCoreBuildAndRuntimeProperties(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("core", "install", "arduino:[email protected]")
require.NoError(t, err)

testSketchbook, err := paths.New("testdata", "sketchbook_with_extended_platform").Abs()
require.NoError(t, err)

// Install custom platform
err = testSketchbook.Join("hardware").CopyDirTo(cli.SketchbookDir().Join("hardware"))
require.NoError(t, err)

// Determine some useful paths
boardPlatformPath := cli.SketchbookDir().Join("hardware", "test", "avr").String()
corePlatformPath := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6").String()
corePath := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6", "cores", "arduino").String()

jsonEncode := func(in string) string {
enc, err := json.Marshal(in)
require.NoError(t, err)
return string(enc)
}

// Check runtime variables are populated correctly
{
outJson, _, err := cli.Run("board", "details", "-b", "test:avr:test", "--show-properties", "--json")
require.NoError(t, err)
out := requirejson.Parse(t, outJson).Query(".build_properties")
out.ArrayMustContain(jsonEncode("build.board.platform.path=" + boardPlatformPath))
out.ArrayMustContain(jsonEncode("build.core.platform.path=" + corePlatformPath))
out.ArrayMustContain(jsonEncode("build.core.path=" + corePath))
out.ArrayMustContain(jsonEncode("runtime.platform.path=" + boardPlatformPath))
}
{
outJson, _, err := cli.Run("board", "details", "-b", "test:avr:test2", "--show-properties", "--json")
require.NoError(t, err)
out := requirejson.Parse(t, outJson).Query(".build_properties")
out.ArrayMustContain(jsonEncode("build.board.platform.path=" + boardPlatformPath))
out.ArrayMustContain(jsonEncode("build.core.platform.path=" + corePlatformPath))
out.ArrayMustContain(jsonEncode("build.core.path=" + corePath))
// https://github.com/arduino/arduino-cli/issues/2616
out.ArrayMustContain(jsonEncode("runtime.platform.path=" + corePlatformPath))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

test.name=Test Board
test.build.core=arduino:arduino

test2.name=Test 2 Board
test2.build.core=arduino:arduino
test2.runtime.use_core_platform_path_for_runtime_platform_path=true

0 comments on commit b8c927b

Please sign in to comment.