Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[breaking] Fix behaviour of lib commands when a library is installed multiple times #1878

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 12 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Name instead of CanonicalName in LibraryList
This fixes also `lib list` and `lib examples`.
  • Loading branch information
cmaglie committed Sep 16, 2022
commit f1e5094b65be1bb9afbec865b58cb24c55d8fa8c
21 changes: 11 additions & 10 deletions 21 commands/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library

nameFilter := strings.ToLower(req.GetName())

installedLibs := []*rpc.InstalledLibrary{}
res := listLibraries(lm, req.GetUpdatable(), req.GetAll())
allLibs := listLibraries(lm, req.GetUpdatable(), req.GetAll())
if f := req.GetFqbn(); f != "" {
fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil {
Expand All @@ -61,15 +60,16 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
}

filteredRes := map[string]*installedLib{}
for _, lib := range res {
for _, lib := range allLibs {
if cp := lib.Library.ContainerPlatform; cp != nil {
if cp != boardPlatform && cp != refBoardPlatform {
// Filter all libraries from extraneous platforms
continue
}
}
if latest, has := filteredRes[lib.Library.CanonicalName]; has {
if latest, has := filteredRes[lib.Library.Name]; has {
if latest.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) >= lib.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) {
// Pick library with the best priority
continue
}
}
Expand All @@ -86,17 +86,18 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
f: compatible,
}

filteredRes[lib.Library.CanonicalName] = lib
filteredRes[lib.Library.Name] = lib
}

res = []*installedLib{}
allLibs = []*installedLib{}
for _, lib := range filteredRes {
res = append(res, lib)
allLibs = append(allLibs, lib)
}
}

for _, lib := range res {
if nameFilter != "" && strings.ToLower(lib.Library.CanonicalName) != nameFilter {
installedLibs := []*rpc.InstalledLibrary{}
for _, lib := range allLibs {
if nameFilter != "" && strings.ToLower(lib.Library.Name) != nameFilter {
continue
}
var release *rpc.LibraryRelease
Expand All @@ -105,7 +106,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
}
rpcLib, err := lib.Library.ToRPCLibrary()
if err != nil {
return nil, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Library.CanonicalName), Cause: err}
return nil, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Library.Name), Cause: err}
}
installedLibs = append(installedLibs, &rpc.InstalledLibrary{
Library: rpcLib,
Expand Down
16 changes: 16 additions & 0 deletions 16 internal/integrationtest/lib/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ func TestLibUpgradeCommand(t *testing.T) {
requirejson.Query(t, stdOut, `.[].library | select(.name=="Servo") | .version`, servoVersion)
}

func TestLibCommandsUsingNameInsteadOfCanonicalName(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("lib", "install", "Robot Motor")
require.NoError(t, err)

jsonOut, _, err := cli.Run("lib", "examples", "Robot Motor", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, jsonOut, 1, "Library 'Robot Motor' not matched in lib examples command.")

jsonOut, _, err = cli.Run("lib", "list", "Robot Motor", "--format", "json")
require.NoError(t, err)
requirejson.Len(t, jsonOut, 1, "Library 'Robot Motor' not matched in lib list command.")
}

func TestLibInstallMultipleSameLibrary(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.