Skip to content

Fix core upgrade #291

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 7 commits into from
Jul 19, 2019
Merged

Fix core upgrade #291

merged 7 commits into from
Jul 19, 2019

Conversation

masci
Copy link
Contributor

@masci masci commented Jul 18, 2019

This PR fixes the case where no args are passed to the upgrade command, like:

arduino-cli core upgrade

Now an upgrade will be performed to any core that is up to date. If all the cores are at the latest version, command is a no op and will exit without errors, providing and info message.

Fixes #285 #273

Additional notes

I took the opportunity to review the design of the code that lists all the available cores that was depending on the rpc package for no reason. Also the api of the old PlatformList required a context that was never used.

Other minor improvements are commented inline.

res[i] = n
i++
}
sortutil.CiAsc(res)
return res
}

// GetDepsOfPlatformRelease returns the deps of a specified release of a core.
func (packages Packages) GetDepsOfPlatformRelease(release *PlatformRelease) ([]*ToolRelease, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just moved up in the source module

type Packages struct {
Packages map[string]*Package // Maps packager name to Package
}
type Packages map[string]*Package // Maps packager name to Package
Copy link
Contributor Author

@masci masci Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason for this indirection level that also makes the use of the map awkward by having to repeat packages.Packages, this way "packages is a map" and can be used directly

@@ -44,13 +40,13 @@ type Package struct {
Email string // Email of maintainer.
Platforms map[string]*Platform // The platforms in the system.
Tools map[string]*Tool // The tools in the system.
Packages *Packages `json:"-"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that Packages is aliased to a map, no need to send around a pointer, map is already a reference

@@ -132,27 +152,3 @@ func (tdep ToolDependency) extractRelease(sc Packages) (*ToolRelease, error) {
}
return release, nil
}

// GetDepsOfPlatformRelease returns the deps of a specified release of a core.
func (packages *Packages) GetDepsOfPlatformRelease(release *PlatformRelease) ([]*ToolRelease, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment, this was just moved

@@ -71,7 +77,7 @@ func upgradePlatform(pm *packagemanager.PackageManager, platformRef *packagemana
}
latest := platform.GetLatestRelease()
if !latest.Version.GreaterThan(installed.Version) {
return fmt.Errorf("platform %s is already at the latest version", platformRef)
return ErrAlreadyLatest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way we avoid returning an error if users ask to upgrade a core that's already latest

rpcPlatform := core.PlatformReleaseToRPC(p)
rpcPlatform.Installed = p.Version.String()
installed = append(installed, rpcPlatform)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code was moved here from the core package since here it's legit to depend on rpc

IndexDir: indexDir,
PackagesDir: packagesDir,
DownloadDir: downloadDir,
TempDir: tempDir,
}
}

// Clear FIXMEDOC
func (pm *PackageManager) Clear() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't used anywhere

@mastrolinux
Copy link
Contributor

Affected by the same issue as libs

$ ./arduino-cli core install arduino:[email protected]
Downloading packages...
arduino:arm-none-eabi-gcc@7-2017q4 already downloaded
arduino:[email protected] already downloaded
arduino:[email protected] already downloaded
arduino:[email protected] already downloaded
arduino:[email protected] already downloaded
arduino:[email protected] already downloaded
arduino:[email protected] already downloaded
Installing arduino:arm-none-eabi-gcc@7-2017q4...
arduino:arm-none-eabi-gcc@7-2017q4 installed
Installing arduino:[email protected]...
arduino:[email protected] installed
Installing arduino:[email protected]...
arduino:[email protected] installed
Installing arduino:[email protected]...
arduino:[email protected] installed
Installing arduino:[email protected]...
arduino:[email protected] installed
Installing arduino:[email protected]...
arduino:[email protected] installed
Installing arduino:[email protected]...
arduino:[email protected] installed


$ ls -l ~/.arduino15/staging/packages/
total 198192
-rw-r--r-- 1 luca luca  1974030 Apr 18 18:23 arduinoOTA-1.2.0-linux_amd64.tar.bz2
-rw-r--r-- 1 luca luca  2257689 Jul 18 16:31 arduinoOTA-1.2.1-linux_amd64.tar.bz2
-rw-r--r-- 1 luca luca   207271 Jul 18 16:31 bossac-1.7.0-arduino3-linux64.tar.gz
-rw-r--r-- 1 luca luca    31373 Apr 18 18:25 bossac-1.7.0-x86_64-linux-gnu.tar.gz
-rw-r--r-- 1 luca luca 31525196 Apr 18 17:30 CMSIS-4.5.0.tar.bz2
-rw-r--r-- 1 luca luca  1659108 Apr 18 17:30 CMSIS-Atmel-1.1.0.tar.bz2
-rw-r--r-- 1 luca luca  2221805 Jul 18 16:31 CMSIS-Atmel-1.2.0.tar.bz2
-rw-r--r-- 1 luca luca 51395093 Apr 18 17:53 gcc-arm-none-eabi-4.8.3-2014q1-linux64.tar.gz
-rw-r--r-- 1 luca luca 99857645 Jul 18 16:31 gcc-arm-none-eabi-7-2017-q4-major-linux64.tar.bz2
-rw-r--r-- 1 luca luca  1701581 Jul 18 16:31 openocd-0.10.0-arduino7-static-x86_64-ubuntu12.04-linux-gnu.tar.bz2
-rw-r--r-- 1 luca luca  1394293 Apr 18 18:26 openocd-0.9.0-arduino6-static-x86_64-linux-gnu.tar.bz2
-rw-r--r-- 1 luca luca  2848675 Apr 18 17:51 samd-1.6.21.tar.bz2
-rw-r--r-- 1 luca luca  2894202 Jul 19 10:43 samd-1.8.2.tar.bz2
-rw-r--r-- 1 luca luca  2897712 Jul 18 16:31 samd-1.8.3.tar.bz2


$ ./arduino-cli core uninstall arduino:samd
Uninstalling arduino:[email protected]...
arduino:[email protected] uninstalled
Uninstalling arduino:arm-none-eabi-gcc@7-2017q4, tool is no more required...
arduino:arm-none-eabi-gcc@7-2017q4 uninstalled
Uninstalling arduino:[email protected], tool is no more required...
arduino:[email protected] uninstalled
Uninstalling arduino:[email protected], tool is no more required...
arduino:[email protected] uninstalled
Uninstalling arduino:[email protected], tool is no more required...
arduino:[email protected] uninstalled
Uninstalling arduino:[email protected], tool is no more required...
arduino:[email protected] uninstalled
Uninstalling arduino:[email protected], tool is no more required...
arduino:[email protected] uninstalled

$ ls -l ~/.arduino15/staging/packages/
total 198192
-rw-r--r-- 1 luca luca  1974030 Apr 18 18:23 arduinoOTA-1.2.0-linux_amd64.tar.bz2
-rw-r--r-- 1 luca luca  2257689 Jul 18 16:31 arduinoOTA-1.2.1-linux_amd64.tar.bz2
-rw-r--r-- 1 luca luca   207271 Jul 18 16:31 bossac-1.7.0-arduino3-linux64.tar.gz
-rw-r--r-- 1 luca luca    31373 Apr 18 18:25 bossac-1.7.0-x86_64-linux-gnu.tar.gz
-rw-r--r-- 1 luca luca 31525196 Apr 18 17:30 CMSIS-4.5.0.tar.bz2
-rw-r--r-- 1 luca luca  1659108 Apr 18 17:30 CMSIS-Atmel-1.1.0.tar.bz2
-rw-r--r-- 1 luca luca  2221805 Jul 18 16:31 CMSIS-Atmel-1.2.0.tar.bz2
-rw-r--r-- 1 luca luca 51395093 Apr 18 17:53 gcc-arm-none-eabi-4.8.3-2014q1-linux64.tar.gz
-rw-r--r-- 1 luca luca 99857645 Jul 18 16:31 gcc-arm-none-eabi-7-2017-q4-major-linux64.tar.bz2
-rw-r--r-- 1 luca luca  1701581 Jul 18 16:31 openocd-0.10.0-arduino7-static-x86_64-ubuntu12.04-linux-gnu.tar.bz2
-rw-r--r-- 1 luca luca  1394293 Apr 18 18:26 openocd-0.9.0-arduino6-static-x86_64-linux-gnu.tar.bz2
-rw-r--r-- 1 luca luca  2848675 Apr 18 17:51 samd-1.6.21.tar.bz2
-rw-r--r-- 1 luca luca  2894202 Jul 19 10:43 samd-1.8.2.tar.bz2
-rw-r--r-- 1 luca luca  2897712 Jul 18 16:31 samd-1.8.3.tar.bz2

does not solve #285 either. Everything else LGTM

@masci
Copy link
Contributor Author

masci commented Jul 19, 2019

@mastrolinux my bad, I copypasted the wrong issue number, this is actually for #273 I've fixed PR description

@mastrolinux
Copy link
Contributor

I can confirm that is fixed and I am going to prepare an integration test for it.

@mastrolinux mastrolinux merged commit 721ab25 into master Jul 19, 2019
@masci masci deleted the massi/core-upgrade branch August 8, 2019 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants