Skip to content

Commit 799e3a5

Browse files
WIP
1 parent e7a8321 commit 799e3a5

File tree

21 files changed

+507
-218
lines changed

21 files changed

+507
-218
lines changed

Diff for: arduino/cores/cores.go

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Platform struct {
4444
Package *Package `json:"-"`
4545
ManuallyInstalled bool // true if the Platform has been installed without the CLI
4646
Deprecated bool // true if the Platform has been deprecated
47+
Indexed bool
4748
}
4849

4950
// PlatformReleaseHelp represents the help URL for this Platform release
@@ -409,3 +410,16 @@ func (release *PlatformRelease) MarshalJSON() ([]byte, error) {
409410
Name: release.Platform.Name,
410411
})
411412
}
413+
414+
// HasMetadata returns true if the PlatformRelease installation dir contains the installed.json file
415+
func (release *PlatformRelease) HasMetadata() bool {
416+
if release.InstallDir == nil {
417+
return false
418+
}
419+
420+
installedJSONPath := release.InstallDir.Join("installed.json")
421+
if installedJSONPath == nil {
422+
return false
423+
}
424+
return installedJSONPath.Exist()
425+
}

Diff for: arduino/cores/packageindex/index.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ import (
3333
//
3434
//easyjson:json
3535
type Index struct {
36-
Packages []*indexPackage `json:"packages"`
37-
IsTrusted bool
36+
Packages []*indexPackage `json:"packages"`
37+
IsTrusted bool
38+
isInstalledJSON bool
3839
}
3940

4041
// indexPackage represents a single entry from package_index.json file.
@@ -144,7 +145,7 @@ var tr = i18n.Tr
144145
// with the existing contents of the cores.Packages passed as parameter.
145146
func (index Index) MergeIntoPackages(outPackages cores.Packages) {
146147
for _, inPackage := range index.Packages {
147-
inPackage.extractPackageIn(outPackages, index.IsTrusted)
148+
inPackage.extractPackageIn(outPackages, index.IsTrusted, index.isInstalledJSON)
148149
}
149150
}
150151

@@ -243,7 +244,7 @@ func IndexFromPlatformRelease(pr *cores.PlatformRelease) Index {
243244
}
244245
}
245246

246-
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trusted bool) {
247+
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trusted bool, isInstallJSON bool) {
247248
outPackage := outPackages.GetOrCreatePackage(inPackage.Name)
248249
outPackage.Maintainer = inPackage.Maintainer
249250
outPackage.WebsiteURL = inPackage.WebsiteURL
@@ -256,15 +257,19 @@ func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trust
256257
}
257258

258259
for _, inPlatform := range inPackage.Platforms {
259-
inPlatform.extractPlatformIn(outPackage, trusted)
260+
inPlatform.extractPlatformIn(outPackage, trusted, isInstallJSON)
260261
}
261262
}
262263

263-
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package, trusted bool) error {
264+
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package, trusted bool, isInstallJSON bool) error {
264265
outPlatform := outPackage.GetOrCreatePlatform(inPlatformRelease.Architecture)
265266
// FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease?
266267
outPlatform.Name = inPlatformRelease.Name
267268
outPlatform.Category = inPlatformRelease.Category
269+
// If the variable `isInstallJSON` is false it means that the index we're reading is coming from the additional-urls.
270+
// Therefore, the `outPlatform.Indexed` will be set at `true`.
271+
outPlatform.Indexed = outPlatform.Indexed || !isInstallJSON
272+
268273
// If the Platform is installed before deprecation installed.json file does not include "deprecated" field.
269274
// The installed.json is read during loading phase of an installed Platform, if the deprecated field is not found
270275
// the package_index.json field would be overwritten and the deprecation info would be lost.
@@ -398,6 +403,11 @@ func LoadIndex(jsonIndexFile *paths.Path) (*Index, error) {
398403
} else {
399404
logrus.WithField("index", jsonIndexFile).Infof("Missing signature file")
400405
}
406+
407+
if jsonIndexFile.Base() == "installed.json" {
408+
index.isInstalledJSON = true
409+
}
410+
401411
return &index, nil
402412
}
403413

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/board/listall.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
6262
Website: platform.Package.WebsiteURL,
6363
Email: platform.Package.Email,
6464
ManuallyInstalled: platform.ManuallyInstalled,
65+
Indexed: platform.Indexed,
66+
MissingMetadata: !installedPlatformRelease.HasMetadata(),
6567
}
6668

6769
toTest := []string{

Diff for: commands/board/search.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
5454
Website: platform.Package.WebsiteURL,
5555
Email: platform.Package.Email,
5656
ManuallyInstalled: platform.ManuallyInstalled,
57+
Indexed: platform.Indexed,
5758
}
5859

5960
if latestPlatformRelease != nil {
6061
rpcPlatform.Latest = latestPlatformRelease.Version.String()
6162
}
6263
if installedPlatformRelease != nil {
6364
rpcPlatform.Installed = installedPlatformRelease.Version.String()
65+
rpcPlatform.MissingMetadata = !installedPlatformRelease.HasMetadata()
6466
}
6567

6668
// Platforms that are not installed don't have a list of boards

Diff for: commands/core.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform
6262
ManuallyInstalled: platformRelease.Platform.ManuallyInstalled,
6363
Deprecated: platformRelease.Platform.Deprecated,
6464
Type: []string{platformRelease.Platform.Category},
65+
Indexed: platformRelease.Platform.Indexed,
66+
MissingMetadata: !platformRelease.HasMetadata(),
6567
}
6668

6769
return result

0 commit comments

Comments
 (0)