Skip to content

Fix esp32 + esp8266 conflicting tool #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ func (pm *PackageManager) GetAllInstalledToolsReleases() []*cores.ToolRelease {
}

func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.ToolRelease, error) {
// core := board.Properties["build.core"]
pm.Log.Infof("Searching tools required for board %s", board)

// core := board.Properties["build.core"]
platform := board.PlatformRelease

// maps "PACKAGER:TOOL" => ToolRelease
Expand All @@ -368,18 +369,19 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core
for _, tool := range targetPackage.Tools {
rel := tool.GetLatestInstalled()
if rel != nil {
foundTools[rel.Tool.String()] = rel
foundTools[rel.Tool.Name] = rel
}
}
}

// replace the default tools above with the specific required by the current platform
for _, toolDep := range platform.Dependencies {
pm.Log.WithField("tool", toolDep).Infof("Required tool")
tool := pm.FindToolDependency(toolDep)
if tool == nil {
return nil, fmt.Errorf("tool release not found: %s", toolDep)
}
foundTools[tool.Tool.String()] = tool
foundTools[tool.Tool.Name] = tool
}

requiredTools := []*cores.ToolRelease{}
Expand Down
60 changes: 60 additions & 0 deletions arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
package packagemanager_test

import (
"net/url"
"testing"

"go.bug.st/relaxed-semver"

"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/configs"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
"github.com/stretchr/testify/require"
)

var customHardware = paths.New("testdata", "custom_hardware")
var dataDir1 = paths.New("testdata", "data_dir_1")

func TestFindBoardWithFQBN(t *testing.T) {
pm := packagemanager.NewPackageManager(customHardware, customHardware, customHardware, customHardware)
Expand Down Expand Up @@ -79,3 +85,57 @@ func TestBoardOptionsFunctions(t *testing.T) {
require.Equal(t, k, v)
}
}

func TestFindToolsRequiredForBoard(t *testing.T) {
pm := packagemanager.NewPackageManager(
dataDir1,
dataDir1.Join("packages"),
dataDir1.Join("staging"),
dataDir1)
conf := &configs.Configuration{
DataDir: dataDir1,
}
loadIndex := func(addr string) {
res, err := url.Parse(addr)
require.NoError(t, err)
require.NoError(t, pm.LoadPackageIndex(res))
}
loadIndex("https://dl.espressif.com/dl/package_esp32_index.json")
loadIndex("http://arduino.esp8266.com/stable/package_esp8266com_index.json")
require.NoError(t, pm.LoadHardware(conf))
esp32, err := pm.FindBoardWithFQBN("esp32:esp32:esp32")
require.NoError(t, err)
esptool231 := pm.FindToolDependency(&cores.ToolDependency{
ToolPackager: "esp32",
ToolName: "esptool",
ToolVersion: semver.ParseRelaxed("2.3.1"),
})
require.NotNil(t, esptool231)
esptool0413 := pm.FindToolDependency(&cores.ToolDependency{
ToolPackager: "esp8266",
ToolName: "esptool",
ToolVersion: semver.ParseRelaxed("0.4.13"),
})
require.NotNil(t, esptool0413)

testConflictingToolsInDifferentPackages := func() {
tools, err := pm.FindToolsRequiredForBoard(esp32)
require.NoError(t, err)
require.Contains(t, tools, esptool231)
require.NotContains(t, tools, esptool0413)
}

// As seen in https://github.com/arduino/arduino-cli/issues/73 the map randomess
// may make the function fail half of the times. Repeating the test 10 times
// greatly increases the chances to trigger the bad case.
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
testConflictingToolsInDifferentPackages()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"packages": [
{
"name": "esp32",
"maintainer": "Espressif Systems",
"websiteURL": "https://github.com/espressif/arduino-esp32",
"email": "[email protected]",
"help": {
"online": "http://esp32.com"
},
"platforms": [
{
"name": "esp32",
"architecture": "esp32",
"version": "1.0.0",
"category": "ESP32",
"url": "https://github.com/espressif/arduino-esp32/releases/download/1.0.0/esp32-1.0.0.zip",
"archiveFileName": "esp32-1.0.0.zip",
"checksum": "SHA-256:94d586174f103e2014be590ab307c5cdda6fa2ec70204c7f121882ace5e05c80",
"size": "26381887",
"help": {
"online": ""
},
"boards": [
{
"name": "ESP32 Dev Module"
},
{
"name": "WEMOS LoLin32"
}
],
"toolsDependencies": [
{
"packager": "esp32",
"name": "xtensa-esp32-elf-gcc",
"version": "1.22.0-80-g6c4433a-5.2.0"
},
{
"packager": "esp32",
"name": "esptool",
"version": "2.3.1"
},
{
"packager": "esp32",
"name": "mkspiffs",
"version": "0.2.3"
}
]
}
],
"tools": [
{
"name": "xtensa-esp32-elf-gcc",
"version": "1.22.0-80-g6c4433a-5.2.0",
"systems": [
{
"host": "i686-mingw32",
"url": "https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip",
"archiveFileName": "xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip",
"checksum": "SHA-256:f217fccbeaaa8c92db239036e0d6202458de4488b954a3a38f35ac2ec48058a4",
"size": "125719261"
},
{
"host": "x86_64-apple-darwin",
"url": "https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz",
"archiveFileName": "xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz",
"checksum": "SHA-256:a4307a97945d2f2f2745f415fbe80d727750e19f91f9a1e7e2f8a6065652f9da",
"size": "46517409"
},
{
"host": "x86_64-pc-linux-gnu",
"url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz",
"archiveFileName": "xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz",
"checksum": "SHA-256:3fe96c151d46c1d4e5edc6ed690851b8e53634041114bad04729bc16b0445156",
"size": "44219107"
},
{
"host": "i686-pc-linux-gnu",
"url": "https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz",
"archiveFileName": "xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz",
"checksum": "SHA-256:b4055695ffc2dfc0bcb6dafdc2572a6e01151c4179ef5fa972b3fcb2183eb155",
"size": "45566336"
}
]
},
{
"name": "esptool",
"version": "2.3.1",
"systems": [
{
"host": "i686-mingw32",
"url": "https://dl.espressif.com/dl/esptool-2.3.1-windows.zip",
"archiveFileName": "esptool-2.3.1-windows.zip",
"checksum": "SHA-256:c187763d0faac7da7c30a292a23c759bbc256fcd084dc8846ed284000cb0fe29",
"size": "3396085"
},
{
"host": "x86_64-apple-darwin",
"url": "https://dl.espressif.com/dl/esptool-2.3.1-macos.tar.gz",
"archiveFileName": "esptool-2.3.1-macos.tar.gz",
"checksum": "SHA-256:cd922418f02e0ca11dc066b36a22646a1b441da00d762b4464ca598c902c5ecb",
"size": "3810932"
},
{
"host": "x86_64-pc-linux-gnu",
"url": "https://dl.espressif.com/dl/esptool-2.3.1-linux.tar.gz",
"archiveFileName": "esptool-2.3.1-linux.tar.gz",
"checksum": "SHA-256:cff30841dad80ed5d7d2d58a31843b63afa57528979a9c839806568167691d8e",
"size": "39563"
},
{
"host": "i686-pc-linux-gnu",
"url": "https://dl.espressif.com/dl/esptool-2.3.1-linux.tar.gz",
"archiveFileName": "esptool-2.3.1-linux.tar.gz",
"checksum": "SHA-256:cff30841dad80ed5d7d2d58a31843b63afa57528979a9c839806568167691d8e",
"size": "39563"
},
{
"host": "arm-linux-gnueabihf",
"url": "https://dl.espressif.com/dl/esptool-2.3.1-linux.tar.gz",
"archiveFileName": "esptool-2.3.1-linux.tar.gz",
"checksum": "SHA-256:cff30841dad80ed5d7d2d58a31843b63afa57528979a9c839806568167691d8e",
"size": "39563"
}
]
},
{
"name": "mkspiffs",
"version": "0.2.3",
"systems": [
{
"host": "i686-mingw32",
"url": "https://github.com/igrr/mkspiffs/releases/download/0.2.3/mkspiffs-0.2.3-arduino-esp32-win32.zip",
"archiveFileName": "mkspiffs-0.2.3-arduino-esp32-win32.zip",
"checksum": "SHA-256:b647f2c2efe6949819c85ea9404271b55c7c9c25bcb98d3b98a1d0ba771adf56",
"size": "249809"
},
{
"host": "x86_64-apple-darwin",
"url": "https://github.com/igrr/mkspiffs/releases/download/0.2.3/mkspiffs-0.2.3-arduino-esp32-osx.tar.gz",
"archiveFileName": "mkspiffs-0.2.3-arduino-esp32-osx.tar.gz",
"checksum": "SHA-256:9f43fc74a858cf564966b5035322c3e5e61c31a647c5a1d71b388ed6efc48423",
"size": "130270"
},
{
"host": "i386-apple-darwin",
"url": "https://github.com/igrr/mkspiffs/releases/download/0.2.3/mkspiffs-0.2.3-arduino-esp32-osx.tar.gz",
"archiveFileName": "mkspiffs-0.2.3-arduino-esp32-osx.tar.gz",
"checksum": "SHA-256:9f43fc74a858cf564966b5035322c3e5e61c31a647c5a1d71b388ed6efc48423",
"size": "130270"
},
{
"host": "x86_64-pc-linux-gnu",
"url": "https://github.com/igrr/mkspiffs/releases/download/0.2.3/mkspiffs-0.2.3-arduino-esp32-linux64.tar.gz",
"archiveFileName": "mkspiffs-0.2.3-arduino-esp32-linux64.tar.gz",
"checksum": "SHA-256:5e1a4ff41385e842f389f6b5254102a547e566a06b49babeffa93ef37115cb5d",
"size": "50646"
},
{
"host": "i686-pc-linux-gnu",
"url": "https://github.com/igrr/mkspiffs/releases/download/0.2.3/mkspiffs-0.2.3-arduino-esp32-linux32.tar.gz",
"archiveFileName": "mkspiffs-0.2.3-arduino-esp32-linux32.tar.gz",
"checksum": "SHA-256:464463a93e8833209cdc29ba65e1a12fec31718dc10075c195a2445b2c3f6cb0",
"size": "48751"
},
{
"host": "arm-linux-gnueabihf",
"url": "https://github.com/igrr/mkspiffs/releases/download/0.2.3/mkspiffs-0.2.3-arduino-esp32-linux-armhf.tar.gz",
"archiveFileName": "mkspiffs-0.2.3-arduino-esp32-linux-armhf.tar.gz",
"checksum": "SHA-256:ade3dc00117912ac08a1bdbfbfe76b12d21a34bc5fa1de0cfc45fe7a8d0a0185",
"size": "40665"
}
]
}
]
}
]
}
Loading