Skip to content

Commit ca8c48a

Browse files
authored
Use real names for libs in upgrade commands (#1725)
The real name for a lib (the name stored in the library.properties) is required to find a library in the index. The installed name, which matches the diretory name, is not valid for looking up libraries in the index. Libraries that do not have a library.properties file, or where the name value in that file does not match the value in library_index.json, cannot be upgrade by the CLI. Also Fix tests for outdated libs The tests for update and outdated changed the library.properties file for an installed lib, but also wiped out the name field. Since we rely on that field to determine the library name when using the RealName property, the test's change was causing a failure outside the scope of the test itself.
1 parent 554c49d commit ca8c48a

File tree

9 files changed

+19
-16
lines changed

9 files changed

+19
-16
lines changed

Diff for: arduino/libraries/librariesindex/index.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (idx *Index) FindRelease(ref *Reference) *Release {
125125
// FindIndexedLibrary search an indexed library that matches the provided
126126
// installed library or nil if not found
127127
func (idx *Index) FindIndexedLibrary(lib *libraries.Library) *Library {
128-
return idx.Libraries[lib.Name]
128+
return idx.Libraries[lib.RealName]
129129
}
130130

131131
// FindLibraryUpdate check if an installed library may be updated using

Diff for: arduino/libraries/librariesindex/index_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@ func TestIndexer(t *testing.T) {
7272
})
7373
require.Nil(t, rtcInexistent)
7474

75-
rtc := index.FindIndexedLibrary(&libraries.Library{Name: "RTCZero"})
75+
rtc := index.FindIndexedLibrary(&libraries.Library{RealName: "RTCZero"})
7676
require.NotNil(t, rtc)
7777
require.Equal(t, "RTCZero", rtc.Name)
7878

79-
rtcUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("1.0.0")})
79+
rtcUpdate := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: semver.MustParse("1.0.0")})
8080
require.NotNil(t, rtcUpdate)
8181
require.Equal(t, "[email protected]", rtcUpdate.String())
8282

83-
rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: nil})
83+
rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: nil})
8484
require.NotNil(t, rtcUpdateNoVersion)
8585
require.Equal(t, "[email protected]", rtcUpdateNoVersion.String())
8686

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

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

9393
resolve1 := index.ResolveDependencies(alp.Releases["1.2.1"])

Diff for: cli/lib/list.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ func (ir installedResult) String() string {
129129
lastName := ""
130130
for _, libMeta := range ir.installedLibs {
131131
lib := libMeta.GetLibrary()
132-
name := lib.Name
132+
name := lib.RealName
133+
if name == "" {
134+
name = lib.Name
135+
}
133136
if name == lastName {
134137
name = ` "`
135138
} else {

Diff for: commands/lib/list.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library
4747

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

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

115-
return &rpc.LibraryListResponse{InstalledLibraries: instaledLibs}, nil
115+
return &rpc.LibraryListResponse{InstalledLibraries: installedLibs}, nil
116116
}
117117

118118
// listLibraries returns the list of installed libraries. If updatable is true it

Diff for: commands/lib/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func filterByName(libs []*installedLib, names []string) []*installedLib {
8282
ret := []*installedLib{}
8383
for _, lib := range libs {
8484
// skip if library name wasn't in the query
85-
if _, found := queryMap[lib.Library.Name]; found {
85+
if _, found := queryMap[lib.Library.RealName]; found {
8686
ret = append(ret, lib)
8787
}
8888
}

Diff for: test/test_lib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def test_lib_list_using_library_with_invalid_version(run_command, data_dir):
826826
# Changes the version of the currently installed library so that it's
827827
# invalid
828828
lib_path = Path(data_dir, "libraries", "WiFi101")
829-
Path(lib_path, "library.properties").write_text("version=1.0001")
829+
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")
830830

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

857857
# Verifies version is now empty
858858
res = run_command(["lib", "list", "--format", "json"])

Diff for: test/test_outdated.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_outdated_using_library_with_invalid_version(run_command, data_dir):
5151
# Changes the version of the currently installed library so that it's
5252
# invalid
5353
lib_path = Path(data_dir, "libraries", "WiFi101")
54-
Path(lib_path, "library.properties").write_text("version=1.0001")
54+
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")
5555

5656
# Verifies library is correctly returned
5757
res = run_command(["outdated"])

Diff for: test/test_update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_update_showing_outdated_using_library_with_invalid_version(run_command,
9999
# Changes the version of the currently installed library so that it's
100100
# invalid
101101
lib_path = Path(data_dir, "libraries", "WiFi101")
102-
Path(lib_path, "library.properties").write_text("version=1.0001")
102+
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")
103103

104104
# Verifies library gets updated
105105
res = run_command(["update", "--show-outdated"])

Diff for: test/test_upgrade.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_upgrade_using_library_with_invalid_version(run_command, data_dir):
5959
# Changes the version of the currently installed library so that it's
6060
# invalid
6161
lib_path = Path(data_dir, "libraries", "WiFi101")
62-
Path(lib_path, "library.properties").write_text("version=1.0001")
62+
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")
6363

6464
# Verifies library gets upgraded
6565
res = run_command(["upgrade"])

0 commit comments

Comments
 (0)