Skip to content

Commit 0a2d2a7

Browse files
return the Platform struct from the PlatformUpgrade commands
1 parent f38d30f commit 0a2d2a7

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,35 @@ func (pme *Explorer) DownloadAndInstallPlatformUpgrades(
3838
downloadCB rpc.DownloadProgressCB,
3939
taskCB rpc.TaskProgressCB,
4040
skipPostInstall bool,
41-
) error {
41+
) (*cores.PlatformRelease, error) {
4242
if platformRef.PlatformVersion != nil {
43-
return &arduino.InvalidArgumentError{Message: tr("Upgrade doesn't accept parameters with version")}
43+
return nil, &arduino.InvalidArgumentError{Message: tr("Upgrade doesn't accept parameters with version")}
4444
}
4545

4646
// Search the latest version for all specified platforms
4747
platform := pme.FindPlatform(platformRef)
4848
if platform == nil {
49-
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
49+
return nil, &arduino.PlatformNotFoundError{Platform: platformRef.String()}
5050
}
5151
installed := pme.GetInstalledPlatformRelease(platform)
5252
if installed == nil {
53-
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
53+
return nil, &arduino.PlatformNotFoundError{Platform: platformRef.String()}
5454
}
5555
latest := platform.GetLatestRelease()
5656
if !latest.Version.GreaterThan(installed.Version) {
57-
return &arduino.PlatformAlreadyAtTheLatestVersionError{}
57+
return latest, &arduino.PlatformAlreadyAtTheLatestVersionError{Platform: platformRef.String()}
5858
}
5959
platformRef.PlatformVersion = latest.Version
6060

6161
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(platformRef)
6262
if err != nil {
63-
return &arduino.PlatformNotFoundError{Platform: platformRef.String()}
63+
return platformRelease, &arduino.PlatformNotFoundError{Platform: platformRef.String()}
6464
}
6565
if err := pme.DownloadAndInstallPlatformAndTools(platformRelease, tools, downloadCB, taskCB, skipPostInstall); err != nil {
66-
return err
66+
return platformRelease, err
6767
}
6868

69-
return nil
69+
return platformRelease, nil
7070
}
7171

7272
// DownloadAndInstallPlatformAndTools runs a full installation process for the given platform and tools.

Diff for: commands/core/upgrade.go

+17-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package core
1717

1818
import (
1919
"context"
20+
"github.com/arduino/arduino-cli/arduino/cores"
2021

2122
"github.com/arduino/arduino-cli/arduino"
2223
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
@@ -26,10 +27,10 @@ import (
2627

2728
// PlatformUpgrade FIXMEDOC
2829
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) {
29-
upgrade := func() error {
30+
upgrade := func() (*cores.PlatformRelease, error) {
3031
pme, release := commands.GetPackageManagerExplorer(req)
3132
if pme == nil {
32-
return &arduino.InvalidInstanceError{}
33+
return nil, &arduino.InvalidInstanceError{}
3334
}
3435
defer release()
3536

@@ -38,18 +39,26 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downl
3839
Package: req.PlatformPackage,
3940
PlatformArchitecture: req.Architecture,
4041
}
41-
if err := pme.DownloadAndInstallPlatformUpgrades(ref, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
42-
return err
42+
platform, err := pme.DownloadAndInstallPlatformUpgrades(ref, downloadCB, taskCB, req.GetSkipPostInstall())
43+
if err != nil {
44+
return platform, err
4345
}
4446

45-
return nil
47+
return platform, nil
4648
}
4749

48-
if err := upgrade(); err != nil {
49-
return nil, err
50+
var rpcPlatform *rpc.Platform
51+
52+
platformRelease, err := upgrade()
53+
if platformRelease != nil {
54+
rpcPlatform = commands.PlatformReleaseToRPC(platformRelease)
55+
}
56+
if err != nil {
57+
return &rpc.PlatformUpgradeResponse{Platform: rpcPlatform}, err
5058
}
5159
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
5260
return nil, err
5361
}
54-
return &rpc.PlatformUpgradeResponse{}, nil
62+
63+
return &rpc.PlatformUpgradeResponse{Platform: rpcPlatform}, nil
5564
}

Diff for: internal/cli/core/upgrade.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
7878
}
7979
}
8080

81+
warningMissingIndex := func(response *rpc.PlatformUpgradeResponse) {
82+
if response == nil || response.Platform == nil {
83+
return
84+
}
85+
if !response.Platform.Indexed || (response.Platform.MissingMetadata && !response.Platform.Indexed) {
86+
feedback.Warning(tr("missing package index for %s, future updates cannot be guaranteed", response.Platform.Id))
87+
}
88+
}
89+
8190
// proceed upgrading, if anything is upgradable
8291
platformsRefs, err := arguments.ParseReferences(args)
8392
if err != nil {
@@ -98,7 +107,9 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
98107
Architecture: platformRef.Architecture,
99108
SkipPostInstall: skipPostInstall,
100109
}
101-
if _, err := core.PlatformUpgrade(context.Background(), r, feedback.ProgressBar(), feedback.TaskProgress()); err != nil {
110+
response, err := core.PlatformUpgrade(context.Background(), r, feedback.ProgressBar(), feedback.TaskProgress())
111+
warningMissingIndex(response)
112+
if err != nil {
102113
if errors.Is(err, &arduino.PlatformAlreadyAtTheLatestVersionError{}) {
103114
feedback.Print(err.Error())
104115
continue

Diff for: internal/integrationtest/core/core_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -1026,3 +1026,31 @@ func TestCoreBrokenDependency(t *testing.T) {
10261026
require.Error(t, err)
10271027
require.Contains(t, string(stderr), "try contacting [email protected]")
10281028
}
1029+
1030+
func TestCoreUpgradeWarningWithPackageInstalledButNotIndexed(t *testing.T) {
1031+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
1032+
defer env.CleanUp()
1033+
1034+
url := env.HTTPServeFile(8000, paths.New("..", "testdata", "test_index.json")).String()
1035+
1036+
t.Run("missing additional-urls", func(t *testing.T) {
1037+
// update index
1038+
_, _, err := cli.Run("core", "update-index", "--additional-urls="+url)
1039+
require.NoError(t, err)
1040+
// install 3rd-party core outdated version
1041+
_, _, err = cli.Run("core", "install", "test:[email protected]", "--additional-urls="+url)
1042+
require.NoError(t, err)
1043+
//upgrade without index fires a warning
1044+
_, jsonStderr, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
1045+
requirejson.Query(t, jsonStderr, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
1046+
})
1047+
1048+
// removing installed.json
1049+
installedJson := cli.DataDir().Join("packages", "test", "hardware", "x86", "1.0.0", "installed.json")
1050+
require.NoError(t, os.Remove(installedJson.String()))
1051+
1052+
t.Run("missing both installed.json and additional-urls", func(t *testing.T) {
1053+
_, jsonStderr, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
1054+
requirejson.Query(t, jsonStderr, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
1055+
})
1056+
}

0 commit comments

Comments
 (0)