-
-
Notifications
You must be signed in to change notification settings - Fork 404
Enhances tracking of installed platforms #998
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
724e8c9
Add Help field to PlatformRelease struct
silvanocerza 7e059cf
Boards are now extracted from index file when creating PlatformRelease
silvanocerza 88e0ad6
Changed some packageindex structs visibility
silvanocerza a1baefc
Installing a Platform saves a json file with all its info
silvanocerza 68d37eb
Platform's installed.json is now loaded if found
silvanocerza f2bd18a
Fix issue with board listall
silvanocerza 8bfdfc3
Reverted packageindex structs visibility
silvanocerza ad59b73
Reworked tests
silvanocerza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,13 @@ | |
package packagemanager | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"runtime" | ||
"strconv" | ||
|
||
"github.com/arduino/arduino-cli/arduino/cores" | ||
"github.com/arduino/arduino-cli/arduino/cores/packageindex" | ||
"github.com/arduino/arduino-cli/executils" | ||
"github.com/pkg/errors" | ||
) | ||
|
@@ -39,6 +42,98 @@ func (pm *PackageManager) InstallPlatform(platformRelease *cores.PlatformRelease | |
} else { | ||
return err | ||
} | ||
if err := pm.cacheInstalledJSON(platformRelease); err != nil { | ||
return errors.Errorf("creating installed.json in %s: %s", platformRelease.InstallDir, err) | ||
} | ||
return nil | ||
} | ||
|
||
func platformReleaseToIndex(pr *cores.PlatformRelease) packageindex.IndexPlatformRelease { | ||
boards := []packageindex.IndexBoard{} | ||
for _, manifest := range pr.BoardsManifest { | ||
board := packageindex.IndexBoard{ | ||
Name: manifest.Name, | ||
} | ||
for _, id := range manifest.ID { | ||
if id.USB != "" { | ||
board.ID = []packageindex.IndexBoardID{{USB: id.USB}} | ||
} | ||
} | ||
boards = append(boards, board) | ||
} | ||
|
||
tools := []packageindex.IndexToolDependency{} | ||
for _, t := range pr.Dependencies { | ||
tools = append(tools, packageindex.IndexToolDependency{ | ||
Packager: t.ToolPackager, | ||
Name: t.ToolName, | ||
Version: t.ToolVersion, | ||
}) | ||
} | ||
return packageindex.IndexPlatformRelease{ | ||
Name: pr.Platform.Name, | ||
Architecture: pr.Platform.Architecture, | ||
Version: pr.Version, | ||
Category: pr.Platform.Category, | ||
URL: pr.Resource.URL, | ||
ArchiveFileName: pr.Resource.ArchiveFileName, | ||
Checksum: pr.Resource.Checksum, | ||
Size: json.Number(strconv.FormatInt(pr.Resource.Size, 10)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't a |
||
Boards: boards, | ||
Help: packageindex.IndexHelp{Online: pr.Help.Online}, | ||
ToolDependencies: tools, | ||
} | ||
} | ||
|
||
func packageToolsToIndex(tools map[string]*cores.Tool) []*packageindex.IndexToolRelease { | ||
ret := []*packageindex.IndexToolRelease{} | ||
for name, tool := range tools { | ||
for _, toolRelease := range tool.Releases { | ||
flavours := []packageindex.IndexToolReleaseFlavour{} | ||
for _, flavour := range toolRelease.Flavors { | ||
flavours = append(flavours, packageindex.IndexToolReleaseFlavour{ | ||
OS: flavour.OS, | ||
URL: flavour.Resource.URL, | ||
ArchiveFileName: flavour.Resource.ArchiveFileName, | ||
Size: json.Number(strconv.FormatInt(flavour.Resource.Size, 10)), | ||
Checksum: flavour.Resource.Checksum, | ||
}) | ||
} | ||
ret = append(ret, &packageindex.IndexToolRelease{ | ||
Name: name, | ||
Version: toolRelease.Version, | ||
Systems: flavours, | ||
}) | ||
} | ||
} | ||
return ret | ||
} | ||
|
||
func (pm *PackageManager) cacheInstalledJSON(platformRelease *cores.PlatformRelease) error { | ||
indexPlatformRelease := platformReleaseToIndex(platformRelease) | ||
indexPackageToolReleases := packageToolsToIndex(platformRelease.Platform.Package.Tools) | ||
|
||
index := packageindex.Index{ | ||
IsTrusted: platformRelease.IsTrusted, | ||
Packages: []*packageindex.IndexPackage{ | ||
{ | ||
Name: platformRelease.Platform.Package.Name, | ||
Maintainer: platformRelease.Platform.Package.Maintainer, | ||
WebsiteURL: platformRelease.Platform.Package.WebsiteURL, | ||
URL: platformRelease.Platform.Package.URL, | ||
Email: platformRelease.Platform.Package.Email, | ||
Platforms: []*packageindex.IndexPlatformRelease{&indexPlatformRelease}, | ||
Tools: indexPackageToolReleases, | ||
Help: packageindex.IndexHelp{Online: platformRelease.Platform.Package.Help.Online}, | ||
}, | ||
}, | ||
} | ||
platformJSON, err := json.MarshalIndent(index, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
installedJSON := platformRelease.InstallDir.Join("installed.json") | ||
installedJSON.WriteFile(platformJSON) | ||
return nil | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this function into
arduino/cores/packageindex
and avoid to make thepackageindex
structs public?