Skip to content
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

Fix resolution of library names when checking for upgrades #1725

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion arduino/libraries/librariesindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (idx *Index) FindRelease(ref *Reference) *Release {
// FindIndexedLibrary search an indexed library that matches the provided
// installed library or nil if not found
func (idx *Index) FindIndexedLibrary(lib *libraries.Library) *Library {
return idx.Libraries[lib.Name]
return idx.Libraries[lib.RealName]
}

// FindLibraryUpdate check if an installed library may be updated using
Expand Down
10 changes: 5 additions & 5 deletions arduino/libraries/librariesindex/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ func TestIndexer(t *testing.T) {
})
require.Nil(t, rtcInexistent)

rtc := index.FindIndexedLibrary(&libraries.Library{Name: "RTCZero"})
rtc := index.FindIndexedLibrary(&libraries.Library{RealName: "RTCZero"})
require.NotNil(t, rtc)
require.Equal(t, "RTCZero", rtc.Name)

rtcUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("1.0.0")})
rtcUpdate := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: semver.MustParse("1.0.0")})
require.NotNil(t, rtcUpdate)
require.Equal(t, "RTCZero@1.6.0", rtcUpdate.String())

rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: nil})
rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: nil})
require.NotNil(t, rtcUpdateNoVersion)
require.Equal(t, "RTCZero@1.6.0", rtcUpdateNoVersion.String())

rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("3.0.0")})
rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: semver.MustParse("3.0.0")})
require.Nil(t, rtcNoUpdate)

rtcInexistent2 := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero-blah", Version: semver.MustParse("1.0.0")})
rtcInexistent2 := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero-blah", Version: semver.MustParse("1.0.0")})
require.Nil(t, rtcInexistent2)

resolve1 := index.ResolveDependencies(alp.Releases["1.2.1"])
Expand Down
5 changes: 4 additions & 1 deletion cli/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ func (ir installedResult) String() string {
lastName := ""
for _, libMeta := range ir.installedLibs {
lib := libMeta.GetLibrary()
name := lib.Name
name := lib.RealName
if name == "" {
name = lib.Name
}
if name == lastName {
name = ` "`
} else {
Expand Down
6 changes: 3 additions & 3 deletions commands/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library

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

instaledLibs := []*rpc.InstalledLibrary{}
installedLibs := []*rpc.InstalledLibrary{}
res := listLibraries(lm, req.GetUpdatable(), req.GetAll())
if f := req.GetFqbn(); f != "" {
fqbn, err := cores.ParseFQBN(req.GetFqbn())
Expand Down Expand Up @@ -106,13 +106,13 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
if err != nil {
return nil, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Library.Name), Cause: err}
}
instaledLibs = append(instaledLibs, &rpc.InstalledLibrary{
installedLibs = append(installedLibs, &rpc.InstalledLibrary{
Library: rpcLib,
Release: release,
})
}

return &rpc.LibraryListResponse{InstalledLibraries: instaledLibs}, nil
return &rpc.LibraryListResponse{InstalledLibraries: installedLibs}, nil
}

// listLibraries returns the list of installed libraries. If updatable is true it
Expand Down
2 changes: 1 addition & 1 deletion commands/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func filterByName(libs []*installedLib, names []string) []*installedLib {
ret := []*installedLib{}
for _, lib := range libs {
// skip if library name wasn't in the query
if _, found := queryMap[lib.Library.Name]; found {
if _, found := queryMap[lib.Library.RealName]; found {
ret = append(ret, lib)
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def test_lib_list_using_library_with_invalid_version(run_command, data_dir):
# Changes the version of the currently installed library so that it's
# invalid
lib_path = Path(data_dir, "libraries", "WiFi101")
Path(lib_path, "library.properties").write_text("version=1.0001")
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")

# Verifies version is now empty
res = run_command(["lib", "list", "--format", "json"])
Expand All @@ -852,7 +852,7 @@ def test_lib_upgrade_using_library_with_invalid_version(run_command, data_dir):
# Changes the version of the currently installed library so that it's
# invalid
lib_path = Path(data_dir, "libraries", "WiFi101")
Path(lib_path, "library.properties").write_text("version=1.0001")
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")

# Verifies version is now empty
res = run_command(["lib", "list", "--format", "json"])
Expand Down
2 changes: 1 addition & 1 deletion test/test_outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_outdated_using_library_with_invalid_version(run_command, data_dir):
# Changes the version of the currently installed library so that it's
# invalid
lib_path = Path(data_dir, "libraries", "WiFi101")
Path(lib_path, "library.properties").write_text("version=1.0001")
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")

# Verifies library is correctly returned
res = run_command(["outdated"])
Expand Down
2 changes: 1 addition & 1 deletion test/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_update_showing_outdated_using_library_with_invalid_version(run_command,
# Changes the version of the currently installed library so that it's
# invalid
lib_path = Path(data_dir, "libraries", "WiFi101")
Path(lib_path, "library.properties").write_text("version=1.0001")
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")

# Verifies library gets updated
res = run_command(["update", "--show-outdated"])
Expand Down
2 changes: 1 addition & 1 deletion test/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_upgrade_using_library_with_invalid_version(run_command, data_dir):
# Changes the version of the currently installed library so that it's
# invalid
lib_path = Path(data_dir, "libraries", "WiFi101")
Path(lib_path, "library.properties").write_text("version=1.0001")
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")

# Verifies library gets upgraded
res = run_command(["upgrade"])
Expand Down