Unverified Commit b8c927b5 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Improved `{build.*.platform.path}` vars enumeration. (#2652)

* Improved build.*.platform.path vars enumeration

* Updated docs

* Added tests

* Added a compatibility note
parent 8b6ad258
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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())
......
......@@ -18,6 +18,7 @@ package core_test
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"path/filepath"
......@@ -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:avr@1.8.6")
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))
}
}
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment