Skip to content

Commit

Permalink
rename 'incompatible' field to 'compatible'
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Oct 23, 2023
1 parent a335d6a commit 54438fa
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 129 deletions.
14 changes: 7 additions & 7 deletions arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type PlatformRelease struct {
PluggableDiscoveryAware bool `json:"-"` // true if the Platform supports pluggable discovery (no compatibility layer required)
Monitors map[string]*MonitorDependency `json:"-"`
MonitorsDevRecipes map[string]string `json:"-"`
Incompatible bool `json:"-"` // true if at least one ToolDependencies is not available for the current OS/ARCH.
Compatible bool `json:"-"` // true if at all ToolDependencies are available for the current OS/ARCH.
}

// BoardManifest contains information about a board. These metadata are usually
Expand Down Expand Up @@ -238,7 +238,7 @@ func (platform *Platform) GetLatestCompatibleRelease() *PlatformRelease {
}
maximum := &PlatformRelease{Version: &semver.Version{}}
for _, release := range platform.Releases {
if release.Incompatible {
if !release.IsCompatible() {
continue
}
if release.Version.GreaterThan(maximum.Version) {
Expand Down Expand Up @@ -278,7 +278,7 @@ func (platform *Platform) GetAllReleasesVersions() []*semver.Version {
func (platform *Platform) GetAllCompatibleReleasesVersions() []*semver.Version {
versions := []*semver.Version{}
for _, release := range platform.Releases {
if release.Incompatible {
if !release.IsCompatible() {
continue
}
versions = append(versions, release.Version)
Expand Down Expand Up @@ -477,8 +477,8 @@ func (release *PlatformRelease) HasMetadata() bool {
return installedJSONPath.Exist()
}

// IsIncompatible returns true if the PlatformRelease contains tool
// dependencies that are not available in the current OS/ARCH.
func (release *PlatformRelease) IsIncompatible() bool {
return release.Incompatible
// IsCompatible returns true if all the tools dependencies of a PlatformRelease
// are available in the current OS/ARCH.
func (release *PlatformRelease) IsCompatible() bool {
return release.Compatible
}
22 changes: 11 additions & 11 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,37 +121,37 @@ func (pmb *Builder) Build() *PackageManager {
}
}

func (pmb *Builder) calculateIncompatibleVersions() {
// calculates Incompatible PlatformRelease
// calculate Compatible PlatformRelease
func (pmb *Builder) calculateCompatibleReleases() {
for _, op := range pmb.packages {
for _, p := range op.Platforms {
for _, pr := range p.Releases {
platformHasIncompatibleTools := func() bool {
platformHasAllCompatibleTools := func() bool {
for _, td := range pr.ToolDependencies {
if td == nil {
return true
return false
}

_, ok := pmb.packages[td.ToolPackager]
if !ok {
return true
return false
}
tool := pmb.packages[td.ToolPackager].Tools[td.ToolName]
if tool == nil {
return true
return false
}
tr := tool.Releases[td.ToolVersion.NormalizedString()]
if tr == nil {
return true
return false
}

if tr.GetCompatibleFlavour() == nil {
return true
return false
}
}
return false
return true
}
pr.Incompatible = platformHasIncompatibleTools()
pr.Compatible = platformHasAllCompatibleTools()
}
}
}
Expand All @@ -164,7 +164,7 @@ func (pmb *Builder) calculateIncompatibleVersions() {
func (pm *PackageManager) NewBuilder() (builder *Builder, commit func()) {
pmb := NewBuilder(pm.IndexDir, pm.PackagesDir, pm.DownloadDir, pm.tempDir, pm.userAgent)
return pmb, func() {
pmb.calculateIncompatibleVersions()
pmb.calculateCompatibleReleases()
pmb.BuildIntoExistingPackageManager(pm)
}
}
Expand Down
1 change: 1 addition & 0 deletions arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ func TestFindToolsRequiredFromPlatformRelease(t *testing.T) {
func TestFindPlatformReleaseDependencies(t *testing.T) {
pmb := NewBuilder(nil, nil, nil, nil, "test")
pmb.LoadPackageIndexFromFile(paths.New("testdata", "package_tooltest_index.json"))
pmb.calculateCompatibleReleases()
pm := pmb.Build()
pme, release := pm.NewExplorer()
defer release()
Expand Down
2 changes: 1 addition & 1 deletion commands/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.PlatformR
MissingMetadata: missingMetadata,
Type: []string{platformRelease.Category},
Deprecated: platformRelease.Deprecated,
Incompatible: platformRelease.IsIncompatible(),
Compatible: platformRelease.IsCompatible(),
}
}
134 changes: 67 additions & 67 deletions commands/core/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ func TestPlatformSearch(t *testing.T) {
},
Releases: map[string]*rpc.PlatformRelease{
"1.0.5": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
"1.0.6": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
},
InstalledVersion: "",
Expand All @@ -103,13 +103,13 @@ func TestPlatformSearch(t *testing.T) {
},
Releases: map[string]*rpc.PlatformRelease{
"1.0.6": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
},
InstalledVersion: "",
Expand All @@ -136,22 +136,22 @@ func TestPlatformSearch(t *testing.T) {
},
Releases: map[string]*rpc.PlatformRelease{
"1.0.5": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
"1.0.6": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
},
InstalledVersion: "",
Expand All @@ -178,22 +178,22 @@ func TestPlatformSearch(t *testing.T) {
},
Releases: map[string]*rpc.PlatformRelease{
"1.0.5": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
"1.0.6": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
},
InstalledVersion: "",
Expand All @@ -220,22 +220,22 @@ func TestPlatformSearch(t *testing.T) {
},
Releases: map[string]*rpc.PlatformRelease{
"1.0.5": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.5",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
"1.0.6": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Incompatible: true,
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
},
InstalledVersion: "",
Expand Down Expand Up @@ -294,8 +294,8 @@ func TestPlatformSearch(t *testing.T) {
{Name: "Arduino Industrial 101"},
{Name: "Linino One"},
},
Help: &rpc.HelpResources{Online: "http://www.arduino.cc/en/Reference/HomePage"},
Incompatible: true,
Help: &rpc.HelpResources{Online: "http://www.arduino.cc/en/Reference/HomePage"},
Compatible: false,
},
},
InstalledVersion: "",
Expand Down Expand Up @@ -354,8 +354,8 @@ func TestPlatformSearch(t *testing.T) {
{Name: "Arduino Industrial 101"},
{Name: "Linino One"},
},
Help: &rpc.HelpResources{Online: "http://www.arduino.cc/en/Reference/HomePage"},
Incompatible: true,
Help: &rpc.HelpResources{Online: "http://www.arduino.cc/en/Reference/HomePage"},
Compatible: false,
},
},
InstalledVersion: "",
Expand Down
6 changes: 3 additions & 3 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Here you can find a list of migration guides to handle breaking changes between

### The gRPC `cc.arduino.cli.commands.v1.PlatformRelease` has been changed.

We've added a new field called `incompatible`. This field indicates if the current platform release is installable or
not. It may happen that a platform doesn't have a dependency available for an OS, in such cases, if we try to install
the platform it will fail. The new field can be used to know upfront if a specific release is installable.
We've added a new field called `compatible`. This field indicates if the current platform release is installable or not.
It may happen that a platform doesn't have a dependency available for an OS, in such cases, if we try to install the
platform it will fail. The new field can be used to know upfront if a specific release is installable.

### The gRPC `cc.arduino.cli.commands.v1.PlatformSummary` has been changed.

Expand Down
4 changes: 2 additions & 2 deletions internal/cli/feedback/result/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewPlatformReleaseResult(in *rpc.PlatformRelease) *PlatformRelease {
Help: help,
MissingMetadata: in.MissingMetadata,
Deprecated: in.Deprecated,
Incompatible: in.Incompatible,
Compatible: in.Compatible,
}
return res
}
Expand All @@ -115,7 +115,7 @@ type PlatformRelease struct {
Help *HelpResource `json:"help,omitempty"`
MissingMetadata bool `json:"missing_metadata,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Incompatible bool `json:"incompatible,omitempty"`
Compatible bool `json:"compatible"`
}

// Board maps a rpc.Board
Expand Down
10 changes: 5 additions & 5 deletions internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,19 +1174,19 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) {
stdout, _, err = cli.Run("core", "search", "--all", "--format", "json", additionalURLs)
require.NoError(t, err)
requirejson.Query(t, stdout,
`[.[] | select(.id == "foo_vendor:avr") | .releases | map(.) | .[] | {version: .version, incompatible: .incompatible}] | sort_by(.version)`,
`[.[] | select(.id == "foo_vendor:avr") | .releases | map(.) | .[] | {version: .version, compatible: .compatible}] | sort_by(.version)`,
`[
{"incompatible":null,"version":"1.0.0"},
{"incompatible":null,"version":"1.0.1"},
{"incompatible":true,"version":"1.0.2"}
{"compatible":true,"version":"1.0.0"},
{"compatible":true,"version":"1.0.1"},
{"compatible":false,"version":"1.0.2"}
]`,
)

// Core search shows latest compatible version even if incompatible
stdout, _, err = cli.Run("core", "search", "--format", "json", additionalURLs)
require.NoError(t, err)
requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest_version`, `"1.0.2"`)
requirejson.Query(t, stdout, `.[] | select(.id == "incompatible_vendor:avr") | .releases[.latest_version].incompatible`, `true`)
requirejson.Query(t, stdout, `.[] | select(.id == "incompatible_vendor:avr") | .releases[.latest_version].compatible`, `false`)

// In text mode, core search doesn't show any version if no compatible one are present
stdout, _, err = cli.Run("core", "search", additionalURLs)
Expand Down
Loading

0 comments on commit 54438fa

Please sign in to comment.