From b8187b40ae4c4e88629aacaa9cb744abf868cf5c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Sep 2022 16:44:59 +0200 Subject: [PATCH 01/12] Removed LibraryAlternatives object in favor of libraries.List --- arduino/libraries/librarieslist.go | 28 +++++++++ arduino/libraries/librariesmanager/install.go | 6 +- .../librariesmanager/librariesmanager.go | 62 ++++--------------- arduino/libraries/librariesresolver/cpp.go | 8 +-- commands/lib/list.go | 2 +- legacy/builder/test/libraries_loader_test.go | 2 +- 6 files changed, 50 insertions(+), 58 deletions(-) diff --git a/arduino/libraries/librarieslist.go b/arduino/libraries/librarieslist.go index f1644b84a29..3f807ebda67 100644 --- a/arduino/libraries/librarieslist.go +++ b/arduino/libraries/librarieslist.go @@ -17,6 +17,8 @@ package libraries import ( "sort" + + semver "go.bug.st/relaxed-semver" ) // List is a list of Libraries @@ -39,6 +41,16 @@ func (list *List) Add(libs ...*Library) { } } +// Remove removes the library from the list +func (list *List) Remove(library *Library) { + for i, lib := range *list { + if lib == library { + *list = append((*list)[:i], (*list)[i+1:]...) + return + } + } +} + // FindByName returns the first library in the list that match // the specified name or nil if not found func (list *List) FindByName(name string) *Library { @@ -50,6 +62,22 @@ func (list *List) FindByName(name string) *Library { return nil } +// FilterByVersionAndInstallLocation returns the libraries mathching the provided version and install location. If version +// is nil all version are matched. +func (list *List) FilterByVersionAndInstallLocation(version *semver.Version, installLocation LibraryLocation) List { + var found List + for _, lib := range *list { + if lib.Location != installLocation { + continue + } + if version != nil && !lib.Version.Equal(version) { + continue + } + found.Add(lib) + } + return found +} + // SortByName sorts the libraries by name func (list *List) SortByName() { sort.Slice(*list, func(i, j int) bool { diff --git a/arduino/libraries/librariesmanager/install.go b/arduino/libraries/librariesmanager/install.go index 8363e000362..d666982e4d8 100644 --- a/arduino/libraries/librariesmanager/install.go +++ b/arduino/libraries/librariesmanager/install.go @@ -53,7 +53,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde var replaced *libraries.Library if installedLibs, have := lm.Libraries[saneName]; have { - for _, installedLib := range installedLibs.Alternatives { + for _, installedLib := range installedLibs { if installedLib.Location != installLocation { continue } @@ -99,7 +99,9 @@ func (lm *LibrariesManager) Uninstall(lib *libraries.Library) error { return fmt.Errorf(tr("removing lib directory: %s"), err) } - lm.Libraries[lib.Name].Remove(lib) + alternatives := lm.Libraries[lib.Name] + alternatives.Remove(lib) + lm.Libraries[lib.Name] = alternatives return nil } diff --git a/arduino/libraries/librariesmanager/librariesmanager.go b/arduino/libraries/librariesmanager/librariesmanager.go index fdb98fe3473..264d616fec5 100644 --- a/arduino/libraries/librariesmanager/librariesmanager.go +++ b/arduino/libraries/librariesmanager/librariesmanager.go @@ -27,7 +27,6 @@ import ( paths "github.com/arduino/go-paths-helper" "github.com/pmylund/sortutil" "github.com/sirupsen/logrus" - semver "go.bug.st/relaxed-semver" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -36,7 +35,7 @@ import ( // (the list of libraries, revisions, installed paths, etc.) type LibrariesManager struct { LibrariesDir []*LibrariesDir - Libraries map[string]*LibraryAlternatives `json:"libraries"` + Libraries map[string]libraries.List `json:"libraries"` Index *librariesindex.Index IndexFile *paths.Path @@ -51,42 +50,8 @@ type LibrariesDir struct { PlatformRelease *cores.PlatformRelease } -// LibraryAlternatives is a list of different versions of the same library -// installed in the system -type LibraryAlternatives struct { - Alternatives libraries.List -} - var tr = i18n.Tr -// Add adds a library to the alternatives -func (alts *LibraryAlternatives) Add(library *libraries.Library) { - if len(alts.Alternatives) > 0 && alts.Alternatives[0].Name != library.Name { - panic(fmt.Sprintf("the library name is different from the set (%[1]s != %[2]s)", alts.Alternatives[0].Name, library.Name)) - } - alts.Alternatives = append(alts.Alternatives, library) -} - -// Remove removes the library from the alternatives -func (alts *LibraryAlternatives) Remove(library *libraries.Library) { - for i, lib := range alts.Alternatives { - if lib == library { - alts.Alternatives = append(alts.Alternatives[:i], alts.Alternatives[i+1:]...) - return - } - } -} - -// FindVersion returns the library mathching the provided version or nil if not found -func (alts *LibraryAlternatives) FindVersion(version *semver.Version, installLocation libraries.LibraryLocation) *libraries.Library { - for _, lib := range alts.Alternatives { - if lib.Version.Equal(version) && lib.Location == installLocation { - return lib - } - } - return nil -} - // Names returns an array with all the names of the installed libraries. func (lm LibrariesManager) Names() []string { res := make([]string, len(lm.Libraries)) @@ -107,7 +72,7 @@ func NewLibraryManager(indexDir *paths.Path, downloadsDir *paths.Path) *Librarie indexFileSignature = indexDir.Join("library_index.json.sig") } return &LibrariesManager{ - Libraries: map[string]*LibraryAlternatives{}, + Libraries: map[string]libraries.List{}, IndexFile: indexFile, IndexFileSignature: indexFileSignature, DownloadsDir: downloadsDir, @@ -208,12 +173,9 @@ func (lm *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) []* continue } library.ContainerPlatform = librariesDir.PlatformRelease - alternatives, ok := lm.Libraries[library.Name] - if !ok { - alternatives = &LibraryAlternatives{} - lm.Libraries[library.Name] = alternatives - } + alternatives := lm.Libraries[library.Name] alternatives.Add(library) + lm.Libraries[library.Name] = alternatives } return statuses @@ -232,13 +194,9 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location return fmt.Errorf(tr("loading library from %[1]s: %[2]s"), libRootDir, err) } - alternatives, ok := lm.Libraries[library.Name] - if !ok { - alternatives = &LibraryAlternatives{} - lm.Libraries[library.Name] = alternatives - } + alternatives := lm.Libraries[library.Name] alternatives.Add(library) - + lm.Libraries[library.Name] = alternatives return nil } @@ -253,12 +211,16 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in } // TODO: Move "search into user" into another method... if libRef.Version == nil { - for _, candidate := range alternatives.Alternatives { + for _, candidate := range alternatives { if candidate.Location == installLocation { return candidate } } return nil } - return alternatives.FindVersion(libRef.Version, installLocation) + res := alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation) + if len(res) > 0 { + return res[0] + } + return nil } diff --git a/arduino/libraries/librariesresolver/cpp.go b/arduino/libraries/librariesresolver/cpp.go index 05335d7da16..fb7b56fa520 100644 --- a/arduino/libraries/librariesresolver/cpp.go +++ b/arduino/libraries/librariesresolver/cpp.go @@ -47,7 +47,7 @@ func NewCppResolver() *Cpp { // and cache all C++ headers for later retrieval func (resolver *Cpp) ScanFromLibrariesManager(lm *librariesmanager.LibrariesManager) error { for _, libAlternatives := range lm.Libraries { - for _, lib := range libAlternatives.Alternatives { + for _, lib := range libAlternatives { resolver.ScanLibrary(lib) } } @@ -58,7 +58,7 @@ func (resolver *Cpp) ScanFromLibrariesManager(lm *librariesmanager.LibrariesMana // and cache all C++ headers for later retrieval. func (resolver *Cpp) ScanIDEBuiltinLibraries(lm *librariesmanager.LibrariesManager) error { for _, libAlternatives := range lm.Libraries { - for _, lib := range libAlternatives.Alternatives { + for _, lib := range libAlternatives { if lib.Location == libraries.IDEBuiltIn { resolver.ScanLibrary(lib) } @@ -71,7 +71,7 @@ func (resolver *Cpp) ScanIDEBuiltinLibraries(lm *librariesmanager.LibrariesManag // and cache all C++ headers for later retrieval. func (resolver *Cpp) ScanUserAndUnmanagedLibraries(lm *librariesmanager.LibrariesManager) error { for _, libAlternatives := range lm.Libraries { - for _, lib := range libAlternatives.Alternatives { + for _, lib := range libAlternatives { if lib.Location == libraries.User || lib.Location == libraries.Unmanaged { resolver.ScanLibrary(lib) } @@ -84,7 +84,7 @@ func (resolver *Cpp) ScanUserAndUnmanagedLibraries(lm *librariesmanager.Librarie // to find and cache all C++ headers for later retrieval. func (resolver *Cpp) ScanPlatformLibraries(lm *librariesmanager.LibrariesManager, platform *cores.PlatformRelease) error { for _, libAlternatives := range lm.Libraries { - for _, lib := range libAlternatives.Alternatives { + for _, lib := range libAlternatives { if lib.Location != libraries.PlatformBuiltIn && lib.Location != libraries.ReferencedPlatformBuiltIn { continue } diff --git a/commands/lib/list.go b/commands/lib/list.go index e22a4c191d9..d03f66dd259 100644 --- a/commands/lib/list.go +++ b/commands/lib/list.go @@ -121,7 +121,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bool) []*installedLib { res := []*installedLib{} for _, libAlternatives := range lm.Libraries { - for _, lib := range libAlternatives.Alternatives { + for _, lib := range libAlternatives { if !all { if lib.Location != libraries.User { continue diff --git a/legacy/builder/test/libraries_loader_test.go b/legacy/builder/test/libraries_loader_test.go index 125e404cbcb..2754f71dd13 100644 --- a/legacy/builder/test/libraries_loader_test.go +++ b/legacy/builder/test/libraries_loader_test.go @@ -31,7 +31,7 @@ import ( func extractLibraries(ctx *types.Context) []*libraries.Library { res := []*libraries.Library{} for _, lib := range ctx.LibrariesManager.Libraries { - for _, libAlternative := range lib.Alternatives { + for _, libAlternative := range lib { res = append(res, libAlternative) } } From 04cb6930554a7972ce282eb8e1f8c2076afdf98a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Sep 2022 16:46:04 +0200 Subject: [PATCH 02/12] Use RealName instead of (dir) Name as key in librarymanager.Library map --- arduino/libraries/librariesmanager/install.go | 23 ++++++++++--------- .../librariesmanager/librariesmanager.go | 12 ++++------ commands/lib/install.go | 6 ++++- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/arduino/libraries/librariesmanager/install.go b/arduino/libraries/librariesmanager/install.go index d666982e4d8..d2a2a835233 100644 --- a/arduino/libraries/librariesmanager/install.go +++ b/arduino/libraries/librariesmanager/install.go @@ -49,10 +49,9 @@ var ( // install path, where the library should be installed and the possible library that is already // installed on the same folder and it's going to be replaced by the new one. func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release, installLocation libraries.LibraryLocation) (*paths.Path, *libraries.Library, error) { - saneName := utils.SanitizeName(indexLibrary.Library.Name) - var replaced *libraries.Library - if installedLibs, have := lm.Libraries[saneName]; have { + name := indexLibrary.Library.Name + if installedLibs, have := lm.Libraries[name]; have { for _, installedLib := range installedLibs { if installedLib.Location != installLocation { continue @@ -72,7 +71,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde return nil, nil, fmt.Errorf(tr("Builtin libraries directory not set")) } - libPath := libsDir.Join(saneName) + libPath := libsDir.Join(utils.SanitizeName(indexLibrary.Library.Name)) if replaced != nil && replaced.InstallDir.EquivalentTo(libPath) { } else if libPath.IsDir() { @@ -99,9 +98,9 @@ func (lm *LibrariesManager) Uninstall(lib *libraries.Library) error { return fmt.Errorf(tr("removing lib directory: %s"), err) } - alternatives := lm.Libraries[lib.Name] + alternatives := lm.Libraries[lib.RealName] alternatives.Remove(lib) - lm.Libraries[lib.Name] = alternatives + lm.Libraries[lib.RealName] = alternatives return nil } @@ -191,8 +190,8 @@ func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath strin // InstallGitLib installs a library hosted on a git repository on the specified path. func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error { - libsDir := lm.getLibrariesDir(libraries.User) - if libsDir == nil { + installDir := lm.getLibrariesDir(libraries.User) + if installDir == nil { return fmt.Errorf(tr("User directory not set")) } @@ -204,10 +203,9 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error { return err } - installPath := libsDir.Join(libraryName) - // Deletes libraries folder if already installed - if _, ok := lm.Libraries[libraryName]; ok { + installPath := installDir.Join(libraryName) + if installPath.IsDir() { if !overwrite { return fmt.Errorf(tr("library %s already installed"), libraryName) } @@ -217,6 +215,9 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error { Trace("Deleting library") installPath.RemoveAll() } + if installPath.Exist() { + return fmt.Errorf(tr("could not create directory %s: a file with the same name exists!", installPath)) + } logrus. WithField("library name", libraryName). diff --git a/arduino/libraries/librariesmanager/librariesmanager.go b/arduino/libraries/librariesmanager/librariesmanager.go index 264d616fec5..134b75261bc 100644 --- a/arduino/libraries/librariesmanager/librariesmanager.go +++ b/arduino/libraries/librariesmanager/librariesmanager.go @@ -22,7 +22,6 @@ import ( "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" - "github.com/arduino/arduino-cli/arduino/utils" "github.com/arduino/arduino-cli/i18n" paths "github.com/arduino/go-paths-helper" "github.com/pmylund/sortutil" @@ -173,9 +172,9 @@ func (lm *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) []* continue } library.ContainerPlatform = librariesDir.PlatformRelease - alternatives := lm.Libraries[library.Name] + alternatives := lm.Libraries[library.RealName] alternatives.Add(library) - lm.Libraries[library.Name] = alternatives + lm.Libraries[library.RealName] = alternatives } return statuses @@ -194,9 +193,9 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location return fmt.Errorf(tr("loading library from %[1]s: %[2]s"), libRootDir, err) } - alternatives := lm.Libraries[library.Name] + alternatives := lm.Libraries[library.RealName] alternatives.Add(library) - lm.Libraries[library.Name] = alternatives + lm.Libraries[library.RealName] = alternatives return nil } @@ -204,8 +203,7 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location // name and version or, if the version is nil, the library installed // in the User folder. func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library { - saneName := utils.SanitizeName(libRef.Name) - alternatives, have := lm.Libraries[saneName] + alternatives, have := lm.Libraries[libRef.Name] if !have { return nil } diff --git a/commands/lib/install.go b/commands/lib/install.go index ca5eabb6257..512cad78044 100644 --- a/commands/lib/install.go +++ b/commands/lib/install.go @@ -144,7 +144,11 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries if err := lm.Install(libRelease, libPath, installLocation); err != nil { return &arduino.FailedLibraryInstallError{Cause: err} } - + if libReplaced != nil && !libReplaced.InstallDir.EquivalentTo(libPath) { + if err := lm.Uninstall(libReplaced); err != nil { + return fmt.Errorf("%s: %s", tr("could not remove old library"), err) + } + } taskCB(&rpc.TaskProgress{Message: tr("Installed %s", libRelease), Completed: true}) return nil } From 5ececd3b31b91d4b618a35bed7cbcd8d47a7c52f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Sep 2022 17:59:54 +0200 Subject: [PATCH 03/12] Refactored some librarymanager functions to query libraries list --- .../librariesmanager/librariesmanager.go | 27 +++++-------------- commands/lib/uninstall.go | 8 +++--- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/arduino/libraries/librariesmanager/librariesmanager.go b/arduino/libraries/librariesmanager/librariesmanager.go index 134b75261bc..9f271fffb49 100644 --- a/arduino/libraries/librariesmanager/librariesmanager.go +++ b/arduino/libraries/librariesmanager/librariesmanager.go @@ -199,26 +199,13 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location return nil } -// FindByReference return the installed library matching the Reference -// name and version or, if the version is nil, the library installed -// in the User folder. -func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library { - alternatives, have := lm.Libraries[libRef.Name] - if !have { +// FindByReference return the installed libraries matching the Reference +// name and version or, if the version is nil, the libraries installed +// in the installLocation. +func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) libraries.List { + alternatives := lm.Libraries[libRef.Name] + if alternatives == nil { return nil } - // TODO: Move "search into user" into another method... - if libRef.Version == nil { - for _, candidate := range alternatives { - if candidate.Location == installLocation { - return candidate - } - } - return nil - } - res := alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation) - if len(res) > 0 { - return res[0] - } - return nil + return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation) } diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index f265940b47c..075eda6a2ac 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -32,13 +32,13 @@ func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, tas return &arduino.InvalidLibraryError{Cause: err} } - lib := lm.FindByReference(ref, libraries.User) + libs := lm.FindByReference(ref, libraries.User) - if lib == nil { + if len(libs) == 0 { taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.Name), Completed: true}) } else { - taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", lib)}) - lm.Uninstall(lib) + taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", libs[0])}) + lm.Uninstall(libs[0]) taskCB(&rpc.TaskProgress{Completed: true}) } From 7dd0158c2dc28ed2757e5b72f11296ade8798f5f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Sep 2022 18:04:20 +0200 Subject: [PATCH 04/12] Simplified librariesmanager.Install It does not require installLocation since it can be obtained with libPath.Parent() --- arduino/libraries/librariesmanager/install.go | 8 ++------ commands/lib/install.go | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/arduino/libraries/librariesmanager/install.go b/arduino/libraries/librariesmanager/install.go index d2a2a835233..d45cc77cc5a 100644 --- a/arduino/libraries/librariesmanager/install.go +++ b/arduino/libraries/librariesmanager/install.go @@ -81,12 +81,8 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesinde } // Install installs a library on the specified path. -func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path, installLocation libraries.LibraryLocation) error { - libsDir := lm.getLibrariesDir(installLocation) - if libsDir == nil { - return fmt.Errorf(tr("User directory not set")) - } - return indexLibrary.Resource.Install(lm.DownloadsDir, libsDir, libPath) +func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error { + return indexLibrary.Resource.Install(lm.DownloadsDir, libPath.Parent(), libPath) } // Uninstall removes a Library diff --git a/commands/lib/install.go b/commands/lib/install.go index 512cad78044..0a82c9d074d 100644 --- a/commands/lib/install.go +++ b/commands/lib/install.go @@ -141,7 +141,7 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries taskCB(&rpc.TaskProgress{Message: tr("Replacing %[1]s with %[2]s", libReplaced, libRelease)}) } - if err := lm.Install(libRelease, libPath, installLocation); err != nil { + if err := lm.Install(libRelease, libPath); err != nil { return &arduino.FailedLibraryInstallError{Cause: err} } if libReplaced != nil && !libReplaced.InstallDir.EquivalentTo(libPath) { From 9d5d5754e03b8efc4c85738ecf52b7f48a2a9347 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Sep 2022 18:08:12 +0200 Subject: [PATCH 05/12] Added checks for multiple library installation --- arduino/errors.go | 24 ++++++++++ arduino/libraries/librariesmanager/install.go | 46 ++++++++++++------- commands/lib/uninstall.go | 19 ++++++-- internal/integrationtest/lib/lib_test.go | 29 ++++++++++++ 4 files changed, 98 insertions(+), 20 deletions(-) diff --git a/arduino/errors.go b/arduino/errors.go index fd126d414b4..823c2ed99bf 100644 --- a/arduino/errors.go +++ b/arduino/errors.go @@ -21,6 +21,7 @@ import ( "github.com/arduino/arduino-cli/i18n" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "github.com/arduino/go-paths-helper" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -810,3 +811,26 @@ func (e *MultiplePlatformsError) Error() string { func (e *MultiplePlatformsError) ToRPCStatus() *status.Status { return status.New(codes.InvalidArgument, e.Error()) } + +// MultipleLibraryInstallDetected is returned when the user request an +// operation on a library but multiple libraries with the same name +// (in library.properties) are detected. +type MultipleLibraryInstallDetected struct { + LibName string + LibsDir paths.PathList + Message string +} + +func (e *MultipleLibraryInstallDetected) Error() string { + res := tr("The library %s has multiple installations:", e.LibName) + "\n" + for _, lib := range e.LibsDir { + res += fmt.Sprintf("- %s\n", lib) + } + res += e.Message + return res +} + +// ToRPCStatus converts the error into a *status.Status +func (e *MultipleLibraryInstallDetected) ToRPCStatus() *status.Status { + return status.New(codes.InvalidArgument, e.Error()) +} diff --git a/arduino/libraries/librariesmanager/install.go b/arduino/libraries/librariesmanager/install.go index d45cc77cc5a..19906d76516 100644 --- a/arduino/libraries/librariesmanager/install.go +++ b/arduino/libraries/librariesmanager/install.go @@ -22,6 +22,7 @@ import ( "os" "strings" + "github.com/arduino/arduino-cli/arduino" "github.com/arduino/arduino-cli/arduino/globals" "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex" @@ -49,31 +50,42 @@ var ( // install path, where the library should be installed and the possible library that is already // installed on the same folder and it's going to be replaced by the new one. func (lm *LibrariesManager) InstallPrerequisiteCheck(indexLibrary *librariesindex.Release, installLocation libraries.LibraryLocation) (*paths.Path, *libraries.Library, error) { - var replaced *libraries.Library + installDir := lm.getLibrariesDir(installLocation) + if installDir == nil { + if installLocation == libraries.User { + return nil, nil, fmt.Errorf(tr("User directory not set")) + } + return nil, nil, fmt.Errorf(tr("Builtin libraries directory not set")) + } + name := indexLibrary.Library.Name - if installedLibs, have := lm.Libraries[name]; have { - for _, installedLib := range installedLibs { - if installedLib.Location != installLocation { - continue - } - if installedLib.Version != nil && installedLib.Version.Equal(indexLibrary.Version) { - return installedLib.InstallDir, nil, ErrAlreadyInstalled - } - replaced = installedLib + libs := lm.FindByReference(&librariesindex.Reference{Name: name}, installLocation) + for _, lib := range libs { + if lib.Version != nil && lib.Version.Equal(indexLibrary.Version) { + return lib.InstallDir, nil, ErrAlreadyInstalled } } - libsDir := lm.getLibrariesDir(installLocation) - if libsDir == nil { - if installLocation == libraries.User { - return nil, nil, fmt.Errorf(tr("User directory not set")) + if len(libs) > 1 { + libsDir := paths.NewPathList() + for _, lib := range libs { + libsDir.Add(lib.InstallDir) + } + return nil, nil, &arduino.MultipleLibraryInstallDetected{ + LibName: name, + LibsDir: libsDir, + Message: tr("Automatic library install can't be performed in this case, please manually remove all duplicates and retry."), } - return nil, nil, fmt.Errorf(tr("Builtin libraries directory not set")) } - libPath := libsDir.Join(utils.SanitizeName(indexLibrary.Library.Name)) - if replaced != nil && replaced.InstallDir.EquivalentTo(libPath) { + var replaced *libraries.Library + if len(libs) == 1 { + replaced = libs[0] + } + libPath := installDir.Join(utils.SanitizeName(indexLibrary.Library.Name)) + if replaced != nil && replaced.InstallDir.EquivalentTo(libPath) { + return libPath, replaced, nil } else if libPath.IsDir() { return nil, nil, fmt.Errorf(tr("destination dir %s already exists, cannot install"), libPath) } diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index 075eda6a2ac..53a09fc0167 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -22,6 +22,7 @@ import ( "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/commands" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" + "github.com/arduino/go-paths-helper" ) // LibraryUninstall FIXMEDOC @@ -36,11 +37,23 @@ func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, tas if len(libs) == 0 { taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.Name), Completed: true}) - } else { - taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", libs[0])}) + return nil + } + + if len(libs) == 1 { + taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", libs)}) lm.Uninstall(libs[0]) taskCB(&rpc.TaskProgress{Completed: true}) + return nil } - return nil + libsDir := paths.NewPathList() + for _, lib := range libs { + libsDir.Add(lib.InstallDir) + } + return &arduino.MultipleLibraryInstallDetected{ + LibName: libs[0].RealName, + LibsDir: libsDir, + Message: tr("Automatic library uninstall can't be performed in this case, please manually remove them."), + } } diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go index 08afa128841..825440ade1a 100644 --- a/internal/integrationtest/lib/lib_test.go +++ b/internal/integrationtest/lib/lib_test.go @@ -64,3 +64,32 @@ func TestLibUpgradeCommand(t *testing.T) { require.NoError(t, err) requirejson.Query(t, stdOut, `.[].library | select(.name=="Servo") | .version`, servoVersion) } + +func TestLibInstallMultipleSameLibrary(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + cliEnv := cli.GetDefaultEnv() + cliEnv["ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL"] = "true" + + // Check that 'lib install' didn't create a double install + // https://github.com/arduino/arduino-cli/issues/1870 + _, _, err := cli.RunWithCustomEnv(cliEnv, "lib", "install", "--git-url", "https://github.com/arduino-libraries/SigFox#1.0.3") + require.NoError(t, err) + _, _, err = cli.Run("lib", "install", "Arduino SigFox for MKRFox1200") + require.NoError(t, err) + jsonOut, _, err := cli.Run("lib", "list", "--format", "json") + require.NoError(t, err) + requirejson.Len(t, jsonOut, 1, "A duplicate library install has been detected") + + // Check that 'lib upgrade' didn't create a double install + // https://github.com/arduino/arduino-cli/issues/1870 + _, _, err = cli.Run("lib", "uninstall", "Arduino SigFox for MKRFox1200") + require.NoError(t, err) + _, _, err = cli.RunWithCustomEnv(cliEnv, "lib", "install", "--git-url", "https://github.com/arduino-libraries/SigFox#1.0.3") + require.NoError(t, err) + _, _, err = cli.Run("lib", "upgrade", "Arduino SigFox for MKRFox1200") + require.NoError(t, err) + jsonOut, _, err = cli.Run("lib", "list", "--format", "json") + require.NoError(t, err) + requirejson.Len(t, jsonOut, 1, "A duplicate library install has been detected") +} From ac8bc63fa15d45bb91415a4a8c6837a0ba31fb93 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Sep 2022 09:20:48 +0200 Subject: [PATCH 06/12] Added test to check that the cli is able to handle multiple lib installations --- internal/integrationtest/lib/lib_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go index 825440ade1a..e8cb411509f 100644 --- a/internal/integrationtest/lib/lib_test.go +++ b/internal/integrationtest/lib/lib_test.go @@ -93,3 +93,27 @@ func TestLibInstallMultipleSameLibrary(t *testing.T) { require.NoError(t, err) requirejson.Len(t, jsonOut, 1, "A duplicate library install has been detected") } + +func TestDuplicateLibInstallDetection(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + cliEnv := cli.GetDefaultEnv() + cliEnv["ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL"] = "true" + + // Make a double install in the sketchbook/user directory + _, _, err := cli.Run("lib", "install", "ArduinoOTA@1.0.0") + require.NoError(t, err) + otaLibPath := cli.SketchbookDir().Join("libraries", "ArduinoOTA") + err = otaLibPath.CopyDirTo(otaLibPath.Parent().Join("CopyOfArduinoOTA")) + require.NoError(t, err) + jsonOut, _, err := cli.Run("lib", "list", "--format", "json") + require.NoError(t, err) + requirejson.Len(t, jsonOut, 2, "Duplicate library install is not detected by the CLI") + + _, _, err = cli.Run("lib", "install", "ArduinoOTA") + require.Error(t, err) + _, _, err = cli.Run("lib", "upgrade", "ArduinoOTA") + require.Error(t, err) + _, _, err = cli.Run("lib", "uninstall", "ArduinoOTA") + require.Error(t, err) +} From c3231a332d3d8d841d677fdb1d5d47e344334d3c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Sep 2022 12:18:44 +0200 Subject: [PATCH 07/12] Renamed fields in Library structure: Name->CanonicalName; RealName->Name --- arduino/libraries/libraries.go | 10 +-- arduino/libraries/librariesindex/index.go | 2 +- .../libraries/librariesindex/index_test.go | 10 +-- arduino/libraries/librarieslist.go | 4 +- arduino/libraries/librariesmanager/install.go | 4 +- .../librariesmanager/librariesmanager.go | 8 +- arduino/libraries/librariesresolver/cpp.go | 14 +-- .../libraries/librariesresolver/cpp_test.go | 42 ++++----- arduino/libraries/loader.go | 6 +- commands/compile/compile.go | 2 +- commands/lib/list.go | 8 +- commands/lib/resolve_deps.go | 2 +- commands/lib/uninstall.go | 2 +- commands/lib/upgrade.go | 2 +- legacy/builder/container_find_includes.go | 2 +- legacy/builder/create_cmake_rule.go | 2 +- legacy/builder/phases/libraries_builder.go | 8 +- .../print_used_libraries_if_verbose.go | 4 +- legacy/builder/resolve_library.go | 2 +- legacy/builder/test/helper.go | 2 +- .../test/includes_to_include_folders_test.go | 22 ++--- legacy/builder/test/libraries_loader_test.go | 90 +++++++++---------- .../unused_compiled_libraries_remover_test.go | 4 +- legacy/builder/types/types.go | 2 +- .../unused_compiled_libraries_remover.go | 2 +- .../warn_about_arch_incompatible_libraries.go | 2 +- 26 files changed, 129 insertions(+), 129 deletions(-) diff --git a/arduino/libraries/libraries.go b/arduino/libraries/libraries.go index 52f17b992ea..8f4e90b8ddd 100644 --- a/arduino/libraries/libraries.go +++ b/arduino/libraries/libraries.go @@ -63,12 +63,12 @@ type Library struct { Types []string `json:"types,omitempty"` InstallDir *paths.Path + CanonicalName string SourceDir *paths.Path UtilityDir *paths.Path Location LibraryLocation ContainerPlatform *cores.PlatformRelease `json:""` Layout LibraryLayout - RealName string DotALinkage bool Precompiled bool PrecompiledWithSources bool @@ -85,9 +85,9 @@ type Library struct { func (library *Library) String() string { if library.Version.String() == "" { - return library.Name + return library.CanonicalName } - return library.Name + "@" + library.Version.String() + return library.CanonicalName + "@" + library.Version.String() } // ToRPCLibrary converts this library into an rpc.Library @@ -117,7 +117,7 @@ func (library *Library) ToRPCLibrary() (*rpc.Library, error) { } return &rpc.Library{ - Name: library.Name, + Name: library.CanonicalName, Author: library.Author, Maintainer: library.Maintainer, Sentence: library.Sentence, @@ -132,7 +132,7 @@ func (library *Library) ToRPCLibrary() (*rpc.Library, error) { Location: library.Location.ToRPCLibraryLocation(), ContainerPlatform: platformOrEmpty(library.ContainerPlatform), Layout: library.Layout.ToRPCLibraryLayout(), - RealName: library.RealName, + RealName: library.Name, DotALinkage: library.DotALinkage, Precompiled: library.Precompiled, LdFlags: library.LDflags, diff --git a/arduino/libraries/librariesindex/index.go b/arduino/libraries/librariesindex/index.go index 6a12af30232..01c5c20d10b 100644 --- a/arduino/libraries/librariesindex/index.go +++ b/arduino/libraries/librariesindex/index.go @@ -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.RealName] + return idx.Libraries[lib.Name] } // FindLibraryUpdate check if an installed library may be updated using diff --git a/arduino/libraries/librariesindex/index_test.go b/arduino/libraries/librariesindex/index_test.go index 5cebd219eae..59b245b4978 100644 --- a/arduino/libraries/librariesindex/index_test.go +++ b/arduino/libraries/librariesindex/index_test.go @@ -72,22 +72,22 @@ func TestIndexer(t *testing.T) { }) require.Nil(t, rtcInexistent) - rtc := index.FindIndexedLibrary(&libraries.Library{RealName: "RTCZero"}) + rtc := index.FindIndexedLibrary(&libraries.Library{Name: "RTCZero"}) require.NotNil(t, rtc) require.Equal(t, "RTCZero", rtc.Name) - rtcUpdate := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: semver.MustParse("1.0.0")}) + rtcUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "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{RealName: "RTCZero", Version: nil}) + rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: nil}) require.NotNil(t, rtcUpdateNoVersion) require.Equal(t, "RTCZero@1.6.0", rtcUpdateNoVersion.String()) - rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero", Version: semver.MustParse("3.0.0")}) + rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("3.0.0")}) require.Nil(t, rtcNoUpdate) - rtcInexistent2 := index.FindLibraryUpdate(&libraries.Library{RealName: "RTCZero-blah", Version: semver.MustParse("1.0.0")}) + rtcInexistent2 := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero-blah", Version: semver.MustParse("1.0.0")}) require.Nil(t, rtcInexistent2) resolve1 := index.ResolveDependencies(alp.Releases["1.2.1"]) diff --git a/arduino/libraries/librarieslist.go b/arduino/libraries/librarieslist.go index 3f807ebda67..b8c1d157932 100644 --- a/arduino/libraries/librarieslist.go +++ b/arduino/libraries/librarieslist.go @@ -55,7 +55,7 @@ func (list *List) Remove(library *Library) { // the specified name or nil if not found func (list *List) FindByName(name string) *Library { for _, lib := range *list { - if lib.Name == name { + if lib.CanonicalName == name { return lib } } @@ -82,7 +82,7 @@ func (list *List) FilterByVersionAndInstallLocation(version *semver.Version, ins func (list *List) SortByName() { sort.Slice(*list, func(i, j int) bool { a, b := (*list)[i], (*list)[j] - return a.Name < b.Name + return a.CanonicalName < b.CanonicalName }) } diff --git a/arduino/libraries/librariesmanager/install.go b/arduino/libraries/librariesmanager/install.go index 19906d76516..5baa17e3d94 100644 --- a/arduino/libraries/librariesmanager/install.go +++ b/arduino/libraries/librariesmanager/install.go @@ -106,9 +106,9 @@ func (lm *LibrariesManager) Uninstall(lib *libraries.Library) error { return fmt.Errorf(tr("removing lib directory: %s"), err) } - alternatives := lm.Libraries[lib.RealName] + alternatives := lm.Libraries[lib.Name] alternatives.Remove(lib) - lm.Libraries[lib.RealName] = alternatives + lm.Libraries[lib.Name] = alternatives return nil } diff --git a/arduino/libraries/librariesmanager/librariesmanager.go b/arduino/libraries/librariesmanager/librariesmanager.go index 9f271fffb49..9291db64117 100644 --- a/arduino/libraries/librariesmanager/librariesmanager.go +++ b/arduino/libraries/librariesmanager/librariesmanager.go @@ -172,9 +172,9 @@ func (lm *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) []* continue } library.ContainerPlatform = librariesDir.PlatformRelease - alternatives := lm.Libraries[library.RealName] + alternatives := lm.Libraries[library.Name] alternatives.Add(library) - lm.Libraries[library.RealName] = alternatives + lm.Libraries[library.Name] = alternatives } return statuses @@ -193,9 +193,9 @@ func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location return fmt.Errorf(tr("loading library from %[1]s: %[2]s"), libRootDir, err) } - alternatives := lm.Libraries[library.RealName] + alternatives := lm.Libraries[library.Name] alternatives.Add(library) - lm.Libraries[library.RealName] = alternatives + lm.Libraries[library.Name] = alternatives return nil } diff --git a/arduino/libraries/librariesresolver/cpp.go b/arduino/libraries/librariesresolver/cpp.go index fb7b56fa520..5159d816008 100644 --- a/arduino/libraries/librariesresolver/cpp.go +++ b/arduino/libraries/librariesresolver/cpp.go @@ -135,7 +135,7 @@ func (resolver *Cpp) ResolveFor(header, architecture string) *libraries.Library msg = " found another lib with same priority" } logrus. - WithField("lib", lib.Name). + WithField("lib", lib.CanonicalName). WithField("prio", fmt.Sprintf("%03X", libPriority)). Infof(msg) } @@ -149,12 +149,12 @@ func (resolver *Cpp) ResolveFor(header, architecture string) *libraries.Library // If more than one library qualifies use the "closestmatch" algorithm to // find the best matching one (instead of choosing it randomly) if best := findLibraryWithNameBestDistance(header, found); best != nil { - logrus.WithField("lib", best.Name).Info(" library with the best matching name") + logrus.WithField("lib", best.CanonicalName).Info(" library with the best matching name") return best } found.SortByName() - logrus.WithField("lib", found[0].Name).Info(" first library in alphabetic order") + logrus.WithField("lib", found[0].CanonicalName).Info(" first library in alphabetic order") return found[0] } @@ -167,8 +167,8 @@ func simplify(name string) string { func computePriority(lib *libraries.Library, header, arch string) int { header = strings.TrimSuffix(header, filepath.Ext(header)) header = simplify(header) - name := simplify(lib.Name) - realName := simplify(lib.RealName) + name := simplify(lib.CanonicalName) + realName := simplify(lib.Name) priority := 0 @@ -220,7 +220,7 @@ func findLibraryWithNameBestDistance(name string, libs libraries.List) *librarie // Create closestmatch DB wordsToTest := []string{} for _, lib := range libs { - wordsToTest = append(wordsToTest, simplify(lib.Name)) + wordsToTest = append(wordsToTest, simplify(lib.CanonicalName)) } // Choose a set of bag sizes, more is more accurate but slower bagSizes := []int{2} @@ -232,7 +232,7 @@ func findLibraryWithNameBestDistance(name string, libs libraries.List) *librarie // Return the closest-matching lib var winner *libraries.Library for _, lib := range libs { - if closestName == simplify(lib.Name) { + if closestName == simplify(lib.CanonicalName) { winner = lib break } diff --git a/arduino/libraries/librariesresolver/cpp_test.go b/arduino/libraries/librariesresolver/cpp_test.go index b9acb54b503..1685ac04f6d 100644 --- a/arduino/libraries/librariesresolver/cpp_test.go +++ b/arduino/libraries/librariesresolver/cpp_test.go @@ -22,14 +22,14 @@ import ( "github.com/stretchr/testify/require" ) -var l1 = &libraries.Library{Name: "Calculus Lib", Location: libraries.User} -var l2 = &libraries.Library{Name: "Calculus Lib-master", Location: libraries.User} -var l3 = &libraries.Library{Name: "Calculus Lib Improved", Location: libraries.User} -var l4 = &libraries.Library{Name: "Another Calculus Lib", Location: libraries.User} -var l5 = &libraries.Library{Name: "Yet Another Calculus Lib Improved", Location: libraries.User} -var l6 = &libraries.Library{Name: "Calculus Unified Lib", Location: libraries.User} -var l7 = &libraries.Library{Name: "AnotherLib", Location: libraries.User} -var bundleServo = &libraries.Library{Name: "Servo", Location: libraries.IDEBuiltIn, Architectures: []string{"avr", "sam", "samd"}} +var l1 = &libraries.Library{CanonicalName: "Calculus Lib", Location: libraries.User} +var l2 = &libraries.Library{CanonicalName: "Calculus Lib-master", Location: libraries.User} +var l3 = &libraries.Library{CanonicalName: "Calculus Lib Improved", Location: libraries.User} +var l4 = &libraries.Library{CanonicalName: "Another Calculus Lib", Location: libraries.User} +var l5 = &libraries.Library{CanonicalName: "Yet Another Calculus Lib Improved", Location: libraries.User} +var l6 = &libraries.Library{CanonicalName: "Calculus Unified Lib", Location: libraries.User} +var l7 = &libraries.Library{CanonicalName: "AnotherLib", Location: libraries.User} +var bundleServo = &libraries.Library{CanonicalName: "Servo", Location: libraries.IDEBuiltIn, Architectures: []string{"avr", "sam", "samd"}} func runResolver(include string, arch string, libs ...*libraries.Library) *libraries.Library { libraryList := libraries.List{} @@ -41,19 +41,19 @@ func runResolver(include string, arch string, libs ...*libraries.Library) *libra func TestArchitecturePriority(t *testing.T) { userServo := &libraries.Library{ - Name: "Servo", + CanonicalName: "Servo", Location: libraries.User, Architectures: []string{"avr", "sam", "samd"}} userServoAllArch := &libraries.Library{ - Name: "Servo", + CanonicalName: "Servo", Location: libraries.User, Architectures: []string{"*"}} userServoNonavr := &libraries.Library{ - Name: "Servo", + CanonicalName: "Servo", Location: libraries.User, Architectures: []string{"sam", "samd"}} userAnotherServo := &libraries.Library{ - Name: "AnotherServo", + CanonicalName: "AnotherServo", Location: libraries.User, Architectures: []string{"avr", "sam", "samd", "esp32"}} @@ -78,11 +78,11 @@ func TestArchitecturePriority(t *testing.T) { require.Equal(t, userServoAllArch, res, "selected library") userSDAllArch := &libraries.Library{ - Name: "SD", + CanonicalName: "SD", Location: libraries.User, Architectures: []string{"*"}} builtinSDesp := &libraries.Library{ - Name: "SD", + CanonicalName: "SD", Location: libraries.PlatformBuiltIn, Architectures: []string{"esp8266"}} res = runResolver("SD.h", "esp8266", userSDAllArch, builtinSDesp) @@ -133,7 +133,7 @@ func TestCppHeaderResolver(t *testing.T) { librarylist.Add(lib) } resolver.headers[header] = librarylist - return resolver.ResolveFor(header, "avr").Name + return resolver.ResolveFor(header, "avr").CanonicalName } require.Equal(t, "Calculus Lib", resolve("calculus_lib.h", l1, l2, l3, l4, l5, l6, l7)) require.Equal(t, "Calculus Lib-master", resolve("calculus_lib.h", l2, l3, l4, l5, l6, l7)) @@ -147,14 +147,14 @@ func TestCppHeaderResolver(t *testing.T) { func TestCppHeaderResolverWithLibrariesInStrangeDirectoryNames(t *testing.T) { resolver := NewCppResolver() librarylist := libraries.List{} - librarylist.Add(&libraries.Library{Name: "onewire_2_3_4", RealName: "OneWire", Architectures: []string{"*"}}) - librarylist.Add(&libraries.Library{Name: "onewireng_2_3_4", RealName: "OneWireNg", Architectures: []string{"avr"}}) + librarylist.Add(&libraries.Library{CanonicalName: "onewire_2_3_4", Name: "OneWire", Architectures: []string{"*"}}) + librarylist.Add(&libraries.Library{CanonicalName: "onewireng_2_3_4", Name: "OneWireNg", Architectures: []string{"avr"}}) resolver.headers["OneWire.h"] = librarylist - require.Equal(t, "onewire_2_3_4", resolver.ResolveFor("OneWire.h", "avr").Name) + require.Equal(t, "onewire_2_3_4", resolver.ResolveFor("OneWire.h", "avr").CanonicalName) librarylist2 := libraries.List{} - librarylist2.Add(&libraries.Library{Name: "OneWire", RealName: "OneWire", Architectures: []string{"*"}}) - librarylist2.Add(&libraries.Library{Name: "onewire_2_3_4", RealName: "OneWire", Architectures: []string{"avr"}}) + librarylist2.Add(&libraries.Library{CanonicalName: "OneWire", Name: "OneWire", Architectures: []string{"*"}}) + librarylist2.Add(&libraries.Library{CanonicalName: "onewire_2_3_4", Name: "OneWire", Architectures: []string{"avr"}}) resolver.headers["OneWire.h"] = librarylist2 - require.Equal(t, "OneWire", resolver.ResolveFor("OneWire.h", "avr").Name) + require.Equal(t, "OneWire", resolver.ResolveFor("OneWire.h", "avr").CanonicalName) } diff --git a/arduino/libraries/loader.go b/arduino/libraries/loader.go index 5a26efc9dab..78cf71773cf 100644 --- a/arduino/libraries/loader.go +++ b/arduino/libraries/loader.go @@ -108,8 +108,8 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library, if err := addExamples(library); err != nil { return nil, errors.Errorf(tr("scanning examples: %s"), err) } - library.Name = libraryDir.Base() - library.RealName = strings.TrimSpace(libProperties.Get("name")) + library.CanonicalName = libraryDir.Base() + library.Name = strings.TrimSpace(libProperties.Get("name")) library.Author = strings.TrimSpace(libProperties.Get("author")) library.Maintainer = strings.TrimSpace(libProperties.Get("maintainer")) library.Sentence = strings.TrimSpace(libProperties.Get("sentence")) @@ -131,7 +131,7 @@ func makeLegacyLibrary(path *paths.Path, location LibraryLocation) (*Library, er Location: location, SourceDir: path, Layout: FlatLayout, - Name: path.Base(), + CanonicalName: path.Base(), Architectures: []string{"*"}, IsLegacy: true, Version: semver.MustParse(""), diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 75278662f52..6c2bc67d918 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -205,7 +205,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream for _, lib := range builderCtx.ImportedLibraries { rpcLib, err := lib.ToRPCLibrary() if err != nil { - msg := tr("Error getting information for library %s", lib.Name) + ": " + err.Error() + "\n" + msg := tr("Error getting information for library %s", lib.CanonicalName) + ": " + err.Error() + "\n" errStream.Write([]byte(msg)) } importedLibs = append(importedLibs, rpcLib) diff --git a/commands/lib/list.go b/commands/lib/list.go index d03f66dd259..512e7e89e89 100644 --- a/commands/lib/list.go +++ b/commands/lib/list.go @@ -68,7 +68,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library continue } } - if latest, has := filteredRes[lib.Library.Name]; has { + if latest, has := filteredRes[lib.Library.CanonicalName]; has { if latest.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) >= lib.Library.LocationPriorityFor(boardPlatform, refBoardPlatform) { continue } @@ -86,7 +86,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library f: compatible, } - filteredRes[lib.Library.Name] = lib + filteredRes[lib.Library.CanonicalName] = lib } res = []*installedLib{} @@ -96,7 +96,7 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.Library } for _, lib := range res { - if nameFilter != "" && strings.ToLower(lib.Library.Name) != nameFilter { + if nameFilter != "" && strings.ToLower(lib.Library.CanonicalName) != nameFilter { continue } var release *rpc.LibraryRelease @@ -105,7 +105,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.Name), Cause: err} + return nil, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Library.CanonicalName), Cause: err} } installedLibs = append(installedLibs, &rpc.InstalledLibrary{ Library: rpcLib, diff --git a/commands/lib/resolve_deps.go b/commands/lib/resolve_deps.go index dc18591a0c5..0dc8da17aab 100644 --- a/commands/lib/resolve_deps.go +++ b/commands/lib/resolve_deps.go @@ -41,7 +41,7 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe // Extract all installed libraries installedLibs := map[string]*libraries.Library{} for _, lib := range listLibraries(lm, false, false) { - installedLibs[lib.Library.Name] = lib.Library + installedLibs[lib.Library.CanonicalName] = lib.Library } // Resolve all dependencies... diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index 53a09fc0167..61cd18a1362 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -52,7 +52,7 @@ func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, tas libsDir.Add(lib.InstallDir) } return &arduino.MultipleLibraryInstallDetected{ - LibName: libs[0].RealName, + LibName: libs[0].Name, LibsDir: libsDir, Message: tr("Automatic library uninstall can't be performed in this case, please manually remove them."), } diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index 6a8b810e2a1..a156553ee6a 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -86,7 +86,7 @@ func upgrade(lm *librariesmanager.LibrariesManager, libs []*installedLib, downlo func filterByName(libs []*installedLib, name string) *installedLib { for _, lib := range libs { - if lib.Library.RealName == name { + if lib.Library.Name == name { return lib } } diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 4e509715636..30b13a87d0f 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -352,7 +352,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t // Fully precompiled libraries should have no dependencies // to avoid ABI breakage if ctx.Verbose { - ctx.Info(tr("Skipping dependencies detection for precompiled library %[1]s", library.Name)) + ctx.Info(tr("Skipping dependencies detection for precompiled library %[1]s", library.CanonicalName)) } return nil } diff --git a/legacy/builder/create_cmake_rule.go b/legacy/builder/create_cmake_rule.go index 7e689c6f943..0bb5d9e691c 100644 --- a/legacy/builder/create_cmake_rule.go +++ b/legacy/builder/create_cmake_rule.go @@ -73,7 +73,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error { dynamicLibsFromPkgConfig := map[string]bool{} for _, library := range ctx.ImportedLibraries { // Copy used libraries in the correct folder - libDir := libBaseFolder.Join(library.Name) + libDir := libBaseFolder.Join(library.CanonicalName) mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU) utils.CopyDir(library.InstallDir.String(), libDir.String(), validExportExtensions) diff --git a/legacy/builder/phases/libraries_builder.go b/legacy/builder/phases/libraries_builder.go index 2a01ff60f3b..4fbe3de339e 100644 --- a/legacy/builder/phases/libraries_builder.go +++ b/legacy/builder/phases/libraries_builder.go @@ -86,7 +86,7 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib } } - ctx.Info(tr("Library %[1]s has been declared precompiled:", library.Name)) + ctx.Info(tr("Library %[1]s has been declared precompiled:", library.CanonicalName)) // Try directory with full fpuSpecs first, if available if len(fpuSpecs) > 0 { @@ -129,9 +129,9 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { if ctx.Verbose { - ctx.Info(tr(`Compiling library "%[1]s"`, library.Name)) + ctx.Info(tr(`Compiling library "%[1]s"`, library.CanonicalName)) } - libraryBuildPath := buildPath.Join(library.Name) + libraryBuildPath := buildPath.Join(library.CanonicalName) if err := libraryBuildPath.MkdirAll(); err != nil { return nil, errors.WithStack(err) @@ -189,7 +189,7 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p return nil, errors.WithStack(err) } if library.DotALinkage { - archiveFile, err := builder_utils.ArchiveCompiledFiles(ctx, libraryBuildPath, paths.New(library.Name+".a"), libObjectFiles, buildProperties) + archiveFile, err := builder_utils.ArchiveCompiledFiles(ctx, libraryBuildPath, paths.New(library.CanonicalName+".a"), libObjectFiles, buildProperties) if err != nil { return nil, errors.WithStack(err) } diff --git a/legacy/builder/print_used_libraries_if_verbose.go b/legacy/builder/print_used_libraries_if_verbose.go index 8c32c925995..49430786b62 100644 --- a/legacy/builder/print_used_libraries_if_verbose.go +++ b/legacy/builder/print_used_libraries_if_verbose.go @@ -36,13 +36,13 @@ func (s *PrintUsedLibrariesIfVerbose) Run(ctx *types.Context) error { if library.Version.String() == "" { ctx.Info( tr("Using library %[1]s in folder: %[2]s %[3]s", - library.Name, + library.CanonicalName, library.InstallDir, legacy)) } else { ctx.Info( tr("Using library %[1]s at version %[2]s in folder: %[3]s %[4]s", - library.Name, + library.CanonicalName, library.Version, library.InstallDir, legacy)) diff --git a/legacy/builder/resolve_library.go b/legacy/builder/resolve_library.go index 3cb3c07aee3..633266c7f80 100644 --- a/legacy/builder/resolve_library.go +++ b/legacy/builder/resolve_library.go @@ -45,7 +45,7 @@ func ResolveLibrary(ctx *types.Context, header string) *libraries.Library { } selected := resolver.ResolveFor(header, ctx.TargetPlatform.Platform.Architecture) - if alreadyImported := importedLibraries.FindByName(selected.Name); alreadyImported != nil { + if alreadyImported := importedLibraries.FindByName(selected.CanonicalName); alreadyImported != nil { // Certain libraries might have the same name but be different. // This usually happens when the user includes two or more custom libraries that have // different header name but are stored in a parent folder with identical name, like diff --git a/legacy/builder/test/helper.go b/legacy/builder/test/helper.go index 16cbe3d044b..4c42075c774 100644 --- a/legacy/builder/test/helper.go +++ b/legacy/builder/test/helper.go @@ -84,5 +84,5 @@ func (s ByLibraryName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s ByLibraryName) Less(i, j int) bool { - return s[i].Name < s[j].Name + return s[i].CanonicalName < s[j].CanonicalName } diff --git a/legacy/builder/test/includes_to_include_folders_test.go b/legacy/builder/test/includes_to_include_folders_test.go index 7049a06ef03..022e1c4649e 100644 --- a/legacy/builder/test/includes_to_include_folders_test.go +++ b/legacy/builder/test/includes_to_include_folders_test.go @@ -59,7 +59,7 @@ func TestIncludesToIncludeFolders(t *testing.T) { importedLibraries := ctx.ImportedLibraries require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "Bridge", importedLibraries[0].Name) + require.Equal(t, "Bridge", importedLibraries[0].CanonicalName) } func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { @@ -131,8 +131,8 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 2, len(importedLibraries)) - require.Equal(t, "Bridge", importedLibraries[0].Name) - require.Equal(t, "IRremote", importedLibraries[1].Name) + require.Equal(t, "Bridge", importedLibraries[0].CanonicalName) + require.Equal(t, "IRremote", importedLibraries[1].CanonicalName) } func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { @@ -166,8 +166,8 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 2, len(importedLibraries)) - require.Equal(t, "ANewLibrary-master", importedLibraries[0].Name) - require.Equal(t, "IRremote", importedLibraries[1].Name) + require.Equal(t, "ANewLibrary-master", importedLibraries[0].CanonicalName) + require.Equal(t, "IRremote", importedLibraries[1].CanonicalName) } func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { @@ -203,7 +203,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "SPI", importedLibraries[0].Name) + require.Equal(t, "SPI", importedLibraries[0].CanonicalName) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI")) } @@ -241,7 +241,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "SPI", importedLibraries[0].Name) + require.Equal(t, "SPI", importedLibraries[0].CanonicalName) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "SPI")) } @@ -279,7 +279,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "USBHost", importedLibraries[0].Name) + require.Equal(t, "USBHost", importedLibraries[0].CanonicalName) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "USBHost", "src")) } @@ -317,7 +317,7 @@ func TestIncludesToIncludeFoldersSubfolders(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 3, len(importedLibraries)) - require.Equal(t, "testlib1", importedLibraries[0].Name) - require.Equal(t, "testlib2", importedLibraries[1].Name) - require.Equal(t, "testlib3", importedLibraries[2].Name) + require.Equal(t, "testlib1", importedLibraries[0].CanonicalName) + require.Equal(t, "testlib2", importedLibraries[1].CanonicalName) + require.Equal(t, "testlib3", importedLibraries[2].CanonicalName) } diff --git a/legacy/builder/test/libraries_loader_test.go b/legacy/builder/test/libraries_loader_test.go index 2754f71dd13..3ad3e15c305 100644 --- a/legacy/builder/test/libraries_loader_test.go +++ b/legacy/builder/test/libraries_loader_test.go @@ -72,10 +72,10 @@ func TestLoadLibrariesAVR(t *testing.T) { idx := 0 - require.Equal(t, "ANewLibrary-master", libs[idx].Name) + require.Equal(t, "ANewLibrary-master", libs[idx].CanonicalName) idx++ - require.Equal(t, "Adafruit_PN532", libs[idx].Name) + require.Equal(t, "Adafruit_PN532", libs[idx].CanonicalName) require.True(t, Abs(t, paths.New("downloaded_libraries/Adafruit_PN532")).EquivalentTo(libs[idx].InstallDir)) require.True(t, Abs(t, paths.New("downloaded_libraries/Adafruit_PN532")).EquivalentTo(libs[idx].SourceDir)) require.Equal(t, 1, len(libs[idx].Architectures)) @@ -83,15 +83,15 @@ func TestLoadLibrariesAVR(t *testing.T) { require.False(t, libs[idx].IsLegacy) idx++ - require.Equal(t, "Audio", libs[idx].Name) + require.Equal(t, "Audio", libs[idx].CanonicalName) idx++ - require.Equal(t, "Balanduino", libs[idx].Name) + require.Equal(t, "Balanduino", libs[idx].CanonicalName) require.True(t, libs[idx].IsLegacy) idx++ bridgeLib := libs[idx] - require.Equal(t, "Bridge", bridgeLib.Name) + require.Equal(t, "Bridge", bridgeLib.CanonicalName) require.True(t, Abs(t, paths.New("downloaded_libraries/Bridge")).EquivalentTo(bridgeLib.InstallDir)) require.True(t, Abs(t, paths.New("downloaded_libraries/Bridge/src")).EquivalentTo(bridgeLib.SourceDir)) require.Equal(t, 1, len(bridgeLib.Architectures)) @@ -100,51 +100,51 @@ func TestLoadLibrariesAVR(t *testing.T) { require.Equal(t, "Arduino ", bridgeLib.Maintainer) idx++ - require.Equal(t, "CapacitiveSensor", libs[idx].Name) + require.Equal(t, "CapacitiveSensor", libs[idx].CanonicalName) idx++ - require.Equal(t, "EEPROM", libs[idx].Name) + require.Equal(t, "EEPROM", libs[idx].CanonicalName) idx++ - require.Equal(t, "Ethernet", libs[idx].Name) + require.Equal(t, "Ethernet", libs[idx].CanonicalName) idx++ - require.Equal(t, "FakeAudio", libs[idx].Name) + require.Equal(t, "FakeAudio", libs[idx].CanonicalName) idx++ - require.Equal(t, "FastLED", libs[idx].Name) + require.Equal(t, "FastLED", libs[idx].CanonicalName) idx++ - require.Equal(t, "HID", libs[idx].Name) + require.Equal(t, "HID", libs[idx].CanonicalName) idx++ - require.Equal(t, "IRremote", libs[idx].Name) + require.Equal(t, "IRremote", libs[idx].CanonicalName) idx++ - require.Equal(t, "Robot_IR_Remote", libs[idx].Name) + require.Equal(t, "Robot_IR_Remote", libs[idx].CanonicalName) idx++ - require.Equal(t, "SPI", libs[idx].Name) + require.Equal(t, "SPI", libs[idx].CanonicalName) idx++ - require.Equal(t, "SPI", libs[idx].Name) + require.Equal(t, "SPI", libs[idx].CanonicalName) idx++ - require.Equal(t, "ShouldNotRecurseWithOldLibs", libs[idx].Name) + require.Equal(t, "ShouldNotRecurseWithOldLibs", libs[idx].CanonicalName) idx++ - require.Equal(t, "SoftwareSerial", libs[idx].Name) + require.Equal(t, "SoftwareSerial", libs[idx].CanonicalName) idx++ - require.Equal(t, "USBHost", libs[idx].Name) + require.Equal(t, "USBHost", libs[idx].CanonicalName) idx++ - require.Equal(t, "Wire", libs[idx].Name) + require.Equal(t, "Wire", libs[idx].CanonicalName) libs = ctx.LibrariesResolver.AlternativesFor("Audio.h") require.Len(t, libs, 2) sort.Sort(ByLibraryName(libs)) - require.Equal(t, "Audio", libs[0].Name) - require.Equal(t, "FakeAudio", libs[1].Name) + require.Equal(t, "Audio", libs[0].CanonicalName) + require.Equal(t, "FakeAudio", libs[1].CanonicalName) libs = ctx.LibrariesResolver.AlternativesFor("FakeAudio.h") require.Len(t, libs, 1) - require.Equal(t, "FakeAudio", libs[0].Name) + require.Equal(t, "FakeAudio", libs[0].CanonicalName) libs = ctx.LibrariesResolver.AlternativesFor("Adafruit_PN532.h") require.Len(t, libs, 1) - require.Equal(t, "Adafruit_PN532", libs[0].Name) + require.Equal(t, "Adafruit_PN532", libs[0].CanonicalName) libs = ctx.LibrariesResolver.AlternativesFor("IRremote.h") require.Len(t, libs, 1) - require.Equal(t, "IRremote", libs[0].Name) + require.Equal(t, "IRremote", libs[0].CanonicalName) } func TestLoadLibrariesSAM(t *testing.T) { @@ -181,53 +181,53 @@ func TestLoadLibrariesSAM(t *testing.T) { sort.Sort(ByLibraryName(libraries)) idx := 0 - require.Equal(t, "ANewLibrary-master", libraries[idx].Name) + require.Equal(t, "ANewLibrary-master", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Adafruit_PN532", libraries[idx].Name) + require.Equal(t, "Adafruit_PN532", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Audio", libraries[idx].Name) + require.Equal(t, "Audio", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Balanduino", libraries[idx].Name) + require.Equal(t, "Balanduino", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Bridge", libraries[idx].Name) + require.Equal(t, "Bridge", libraries[idx].CanonicalName) idx++ - require.Equal(t, "CapacitiveSensor", libraries[idx].Name) + require.Equal(t, "CapacitiveSensor", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Ethernet", libraries[idx].Name) + require.Equal(t, "Ethernet", libraries[idx].CanonicalName) idx++ - require.Equal(t, "FakeAudio", libraries[idx].Name) + require.Equal(t, "FakeAudio", libraries[idx].CanonicalName) idx++ - require.Equal(t, "FastLED", libraries[idx].Name) + require.Equal(t, "FastLED", libraries[idx].CanonicalName) idx++ - require.Equal(t, "HID", libraries[idx].Name) + require.Equal(t, "HID", libraries[idx].CanonicalName) idx++ - require.Equal(t, "IRremote", libraries[idx].Name) + require.Equal(t, "IRremote", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Robot_IR_Remote", libraries[idx].Name) + require.Equal(t, "Robot_IR_Remote", libraries[idx].CanonicalName) idx++ - require.Equal(t, "SPI", libraries[idx].Name) + require.Equal(t, "SPI", libraries[idx].CanonicalName) idx++ - require.Equal(t, "SPI", libraries[idx].Name) + require.Equal(t, "SPI", libraries[idx].CanonicalName) idx++ - require.Equal(t, "ShouldNotRecurseWithOldLibs", libraries[idx].Name) + require.Equal(t, "ShouldNotRecurseWithOldLibs", libraries[idx].CanonicalName) idx++ - require.Equal(t, "USBHost", libraries[idx].Name) + require.Equal(t, "USBHost", libraries[idx].CanonicalName) idx++ - require.Equal(t, "Wire", libraries[idx].Name) + require.Equal(t, "Wire", libraries[idx].CanonicalName) libs := ctx.LibrariesResolver.AlternativesFor("Audio.h") require.Len(t, libs, 2) sort.Sort(ByLibraryName(libs)) - require.Equal(t, "Audio", libs[0].Name) - require.Equal(t, "FakeAudio", libs[1].Name) + require.Equal(t, "Audio", libs[0].CanonicalName) + require.Equal(t, "FakeAudio", libs[1].CanonicalName) libs = ctx.LibrariesResolver.AlternativesFor("FakeAudio.h") require.Len(t, libs, 1) - require.Equal(t, "FakeAudio", libs[0].Name) + require.Equal(t, "FakeAudio", libs[0].CanonicalName) libs = ctx.LibrariesResolver.AlternativesFor("IRremote.h") require.Len(t, libs, 1) - require.Equal(t, "IRremote", libs[0].Name) + require.Equal(t, "IRremote", libs[0].CanonicalName) } func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { diff --git a/legacy/builder/test/unused_compiled_libraries_remover_test.go b/legacy/builder/test/unused_compiled_libraries_remover_test.go index f6965cee0ff..47f8e7196d8 100644 --- a/legacy/builder/test/unused_compiled_libraries_remover_test.go +++ b/legacy/builder/test/unused_compiled_libraries_remover_test.go @@ -36,7 +36,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { ctx := &types.Context{} ctx.LibrariesBuildPath = temp - ctx.ImportedLibraries = []*libraries.Library{{Name: "Bridge"}} + ctx.ImportedLibraries = []*libraries.Library{{CanonicalName: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} err = cmd.Run(ctx) @@ -56,7 +56,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { ctx := &types.Context{} ctx.LibrariesBuildPath = paths.TempDir().Join("test") - ctx.ImportedLibraries = []*libraries.Library{{Name: "Bridge"}} + ctx.ImportedLibraries = []*libraries.Library{{CanonicalName: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} err := cmd.Run(ctx) diff --git a/legacy/builder/types/types.go b/legacy/builder/types/types.go index 70ee1c34608..ff12a63eafd 100644 --- a/legacy/builder/types/types.go +++ b/legacy/builder/types/types.go @@ -53,7 +53,7 @@ func buildRoot(ctx *Context, origin interface{}) *paths.Path { case *sketch.Sketch: return ctx.SketchBuildPath case *libraries.Library: - return ctx.LibrariesBuildPath.Join(o.Name) + return ctx.LibrariesBuildPath.Join(o.CanonicalName) default: panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin)) } diff --git a/legacy/builder/unused_compiled_libraries_remover.go b/legacy/builder/unused_compiled_libraries_remover.go index 595ce91302e..72d97df5eb3 100644 --- a/legacy/builder/unused_compiled_libraries_remover.go +++ b/legacy/builder/unused_compiled_libraries_remover.go @@ -53,7 +53,7 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error { func toLibraryNames(libraries []*libraries.Library) []string { libraryNames := []string{} for _, library := range libraries { - libraryNames = append(libraryNames, library.Name) + libraryNames = append(libraryNames, library.CanonicalName) } return libraryNames } diff --git a/legacy/builder/warn_about_arch_incompatible_libraries.go b/legacy/builder/warn_about_arch_incompatible_libraries.go index 712f79b2fe5..179f27a166c 100644 --- a/legacy/builder/warn_about_arch_incompatible_libraries.go +++ b/legacy/builder/warn_about_arch_incompatible_libraries.go @@ -37,7 +37,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error { if !importedLibrary.SupportsAnyArchitectureIn(archs...) { ctx.Info( tr("WARNING: library %[1]s claims to run on %[2]s architecture(s) and may be incompatible with your current board which runs on %[3]s architecture(s).", - importedLibrary.Name, + importedLibrary.CanonicalName, strings.Join(importedLibrary.Architectures, ", "), strings.Join(archs, ", "))) } From f1e5094b65be1bb9afbec865b58cb24c55d8fa8c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Sep 2022 12:34:59 +0200 Subject: [PATCH 08/12] Use Name instead of CanonicalName in LibraryList This fixes also `lib list` and `lib examples`. --- commands/lib/list.go | 21 +++++++++++---------- internal/integrationtest/lib/lib_test.go | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/commands/lib/list.go b/commands/lib/list.go index 512e7e89e89..bb529755871 100644 --- a/commands/lib/list.go +++ b/commands/lib/list.go @@ -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 { @@ -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 } } @@ -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 @@ -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, diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go index e8cb411509f..ad8cc029b3d 100644 --- a/internal/integrationtest/lib/lib_test.go +++ b/internal/integrationtest/lib/lib_test.go @@ -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() From 1908634b8a565ebb8a5917ce4cfa419cf0eb7561 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Sep 2022 14:04:50 +0200 Subject: [PATCH 09/12] Use `Name` field where appropriate instead of `CanonicalName` --- arduino/libraries/libraries.go | 6 +- arduino/libraries/librarieslist.go | 4 +- arduino/libraries/librariesresolver/cpp.go | 26 +- .../libraries/librariesresolver/cpp_test.go | 30 +-- arduino/libraries/loader.go | 1 + commands/compile/compile.go | 2 +- commands/lib/resolve_deps.go | 2 +- legacy/builder/container_find_includes.go | 2 +- legacy/builder/phases/libraries_builder.go | 4 +- .../print_used_libraries_if_verbose.go | 4 +- legacy/builder/resolve_library.go | 2 +- legacy/builder/test/helper.go | 2 +- .../test/includes_to_include_folders_test.go | 22 +- legacy/builder/test/libraries_loader_test.go | 91 +++---- .../unused_compiled_libraries_remover_test.go | 4 +- .../unused_compiled_libraries_remover.go | 2 +- .../warn_about_arch_incompatible_libraries.go | 2 +- rpc/cc/arduino/cli/commands/v1/lib.pb.go | 224 +++++++++--------- rpc/cc/arduino/cli/commands/v1/lib.proto | 2 +- 19 files changed, 219 insertions(+), 213 deletions(-) diff --git a/arduino/libraries/libraries.go b/arduino/libraries/libraries.go index 8f4e90b8ddd..ab0d2a380f7 100644 --- a/arduino/libraries/libraries.go +++ b/arduino/libraries/libraries.go @@ -85,9 +85,9 @@ type Library struct { func (library *Library) String() string { if library.Version.String() == "" { - return library.CanonicalName + return library.Name } - return library.CanonicalName + "@" + library.Version.String() + return library.Name + "@" + library.Version.String() } // ToRPCLibrary converts this library into an rpc.Library @@ -117,7 +117,7 @@ func (library *Library) ToRPCLibrary() (*rpc.Library, error) { } return &rpc.Library{ - Name: library.CanonicalName, + Name: library.Name, Author: library.Author, Maintainer: library.Maintainer, Sentence: library.Sentence, diff --git a/arduino/libraries/librarieslist.go b/arduino/libraries/librarieslist.go index b8c1d157932..3f807ebda67 100644 --- a/arduino/libraries/librarieslist.go +++ b/arduino/libraries/librarieslist.go @@ -55,7 +55,7 @@ func (list *List) Remove(library *Library) { // the specified name or nil if not found func (list *List) FindByName(name string) *Library { for _, lib := range *list { - if lib.CanonicalName == name { + if lib.Name == name { return lib } } @@ -82,7 +82,7 @@ func (list *List) FilterByVersionAndInstallLocation(version *semver.Version, ins func (list *List) SortByName() { sort.Slice(*list, func(i, j int) bool { a, b := (*list)[i], (*list)[j] - return a.CanonicalName < b.CanonicalName + return a.Name < b.Name }) } diff --git a/arduino/libraries/librariesresolver/cpp.go b/arduino/libraries/librariesresolver/cpp.go index 5159d816008..0078fdcca78 100644 --- a/arduino/libraries/librariesresolver/cpp.go +++ b/arduino/libraries/librariesresolver/cpp.go @@ -135,7 +135,7 @@ func (resolver *Cpp) ResolveFor(header, architecture string) *libraries.Library msg = " found another lib with same priority" } logrus. - WithField("lib", lib.CanonicalName). + WithField("lib", lib.Name). WithField("prio", fmt.Sprintf("%03X", libPriority)). Infof(msg) } @@ -149,12 +149,12 @@ func (resolver *Cpp) ResolveFor(header, architecture string) *libraries.Library // If more than one library qualifies use the "closestmatch" algorithm to // find the best matching one (instead of choosing it randomly) if best := findLibraryWithNameBestDistance(header, found); best != nil { - logrus.WithField("lib", best.CanonicalName).Info(" library with the best matching name") + logrus.WithField("lib", best.Name).Info(" library with the best matching name") return best } found.SortByName() - logrus.WithField("lib", found[0].CanonicalName).Info(" first library in alphabetic order") + logrus.WithField("lib", found[0].Name).Info(" first library in alphabetic order") return found[0] } @@ -167,8 +167,8 @@ func simplify(name string) string { func computePriority(lib *libraries.Library, header, arch string) int { header = strings.TrimSuffix(header, filepath.Ext(header)) header = simplify(header) - name := simplify(lib.CanonicalName) - realName := simplify(lib.Name) + name := simplify(lib.Name) + canonicalName := simplify(lib.CanonicalName) priority := 0 @@ -185,17 +185,17 @@ func computePriority(lib *libraries.Library, header, arch string) int { priority += 0 } - if realName == header && name == header { + if name == header && canonicalName == header { priority += 600 - } else if realName == header || name == header { + } else if name == header || canonicalName == header { priority += 500 - } else if realName == header+"-master" || name == header+"-master" { + } else if name == header+"-master" || canonicalName == header+"-master" { priority += 400 - } else if strings.HasPrefix(realName, header) || strings.HasPrefix(name, header) { + } else if strings.HasPrefix(name, header) || strings.HasPrefix(canonicalName, header) { priority += 300 - } else if strings.HasSuffix(realName, header) || strings.HasSuffix(name, header) { + } else if strings.HasSuffix(name, header) || strings.HasSuffix(canonicalName, header) { priority += 200 - } else if strings.Contains(realName, header) || strings.Contains(name, header) { + } else if strings.Contains(name, header) || strings.Contains(canonicalName, header) { priority += 100 } @@ -220,7 +220,7 @@ func findLibraryWithNameBestDistance(name string, libs libraries.List) *librarie // Create closestmatch DB wordsToTest := []string{} for _, lib := range libs { - wordsToTest = append(wordsToTest, simplify(lib.CanonicalName)) + wordsToTest = append(wordsToTest, simplify(lib.Name)) } // Choose a set of bag sizes, more is more accurate but slower bagSizes := []int{2} @@ -232,7 +232,7 @@ func findLibraryWithNameBestDistance(name string, libs libraries.List) *librarie // Return the closest-matching lib var winner *libraries.Library for _, lib := range libs { - if closestName == simplify(lib.CanonicalName) { + if closestName == simplify(lib.Name) { winner = lib break } diff --git a/arduino/libraries/librariesresolver/cpp_test.go b/arduino/libraries/librariesresolver/cpp_test.go index 1685ac04f6d..6f8b195be61 100644 --- a/arduino/libraries/librariesresolver/cpp_test.go +++ b/arduino/libraries/librariesresolver/cpp_test.go @@ -22,14 +22,14 @@ import ( "github.com/stretchr/testify/require" ) -var l1 = &libraries.Library{CanonicalName: "Calculus Lib", Location: libraries.User} -var l2 = &libraries.Library{CanonicalName: "Calculus Lib-master", Location: libraries.User} -var l3 = &libraries.Library{CanonicalName: "Calculus Lib Improved", Location: libraries.User} -var l4 = &libraries.Library{CanonicalName: "Another Calculus Lib", Location: libraries.User} -var l5 = &libraries.Library{CanonicalName: "Yet Another Calculus Lib Improved", Location: libraries.User} -var l6 = &libraries.Library{CanonicalName: "Calculus Unified Lib", Location: libraries.User} -var l7 = &libraries.Library{CanonicalName: "AnotherLib", Location: libraries.User} -var bundleServo = &libraries.Library{CanonicalName: "Servo", Location: libraries.IDEBuiltIn, Architectures: []string{"avr", "sam", "samd"}} +var l1 = &libraries.Library{Name: "Calculus Lib", Location: libraries.User} +var l2 = &libraries.Library{Name: "Calculus Lib-master", Location: libraries.User} +var l3 = &libraries.Library{Name: "Calculus Lib Improved", Location: libraries.User} +var l4 = &libraries.Library{Name: "Another Calculus Lib", Location: libraries.User} +var l5 = &libraries.Library{Name: "Yet Another Calculus Lib Improved", Location: libraries.User} +var l6 = &libraries.Library{Name: "Calculus Unified Lib", Location: libraries.User} +var l7 = &libraries.Library{Name: "AnotherLib", Location: libraries.User} +var bundleServo = &libraries.Library{Name: "Servo", Location: libraries.IDEBuiltIn, Architectures: []string{"avr", "sam", "samd"}} func runResolver(include string, arch string, libs ...*libraries.Library) *libraries.Library { libraryList := libraries.List{} @@ -41,19 +41,19 @@ func runResolver(include string, arch string, libs ...*libraries.Library) *libra func TestArchitecturePriority(t *testing.T) { userServo := &libraries.Library{ - CanonicalName: "Servo", + Name: "Servo", Location: libraries.User, Architectures: []string{"avr", "sam", "samd"}} userServoAllArch := &libraries.Library{ - CanonicalName: "Servo", + Name: "Servo", Location: libraries.User, Architectures: []string{"*"}} userServoNonavr := &libraries.Library{ - CanonicalName: "Servo", + Name: "Servo", Location: libraries.User, Architectures: []string{"sam", "samd"}} userAnotherServo := &libraries.Library{ - CanonicalName: "AnotherServo", + Name: "AnotherServo", Location: libraries.User, Architectures: []string{"avr", "sam", "samd", "esp32"}} @@ -78,11 +78,11 @@ func TestArchitecturePriority(t *testing.T) { require.Equal(t, userServoAllArch, res, "selected library") userSDAllArch := &libraries.Library{ - CanonicalName: "SD", + Name: "SD", Location: libraries.User, Architectures: []string{"*"}} builtinSDesp := &libraries.Library{ - CanonicalName: "SD", + Name: "SD", Location: libraries.PlatformBuiltIn, Architectures: []string{"esp8266"}} res = runResolver("SD.h", "esp8266", userSDAllArch, builtinSDesp) @@ -133,7 +133,7 @@ func TestCppHeaderResolver(t *testing.T) { librarylist.Add(lib) } resolver.headers[header] = librarylist - return resolver.ResolveFor(header, "avr").CanonicalName + return resolver.ResolveFor(header, "avr").Name } require.Equal(t, "Calculus Lib", resolve("calculus_lib.h", l1, l2, l3, l4, l5, l6, l7)) require.Equal(t, "Calculus Lib-master", resolve("calculus_lib.h", l2, l3, l4, l5, l6, l7)) diff --git a/arduino/libraries/loader.go b/arduino/libraries/loader.go index 78cf71773cf..f6cd0b679bb 100644 --- a/arduino/libraries/loader.go +++ b/arduino/libraries/loader.go @@ -131,6 +131,7 @@ func makeLegacyLibrary(path *paths.Path, location LibraryLocation) (*Library, er Location: location, SourceDir: path, Layout: FlatLayout, + Name: path.Base(), CanonicalName: path.Base(), Architectures: []string{"*"}, IsLegacy: true, diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 6c2bc67d918..75278662f52 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -205,7 +205,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream for _, lib := range builderCtx.ImportedLibraries { rpcLib, err := lib.ToRPCLibrary() if err != nil { - msg := tr("Error getting information for library %s", lib.CanonicalName) + ": " + err.Error() + "\n" + msg := tr("Error getting information for library %s", lib.Name) + ": " + err.Error() + "\n" errStream.Write([]byte(msg)) } importedLibs = append(importedLibs, rpcLib) diff --git a/commands/lib/resolve_deps.go b/commands/lib/resolve_deps.go index 0dc8da17aab..dc18591a0c5 100644 --- a/commands/lib/resolve_deps.go +++ b/commands/lib/resolve_deps.go @@ -41,7 +41,7 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe // Extract all installed libraries installedLibs := map[string]*libraries.Library{} for _, lib := range listLibraries(lm, false, false) { - installedLibs[lib.Library.CanonicalName] = lib.Library + installedLibs[lib.Library.Name] = lib.Library } // Resolve all dependencies... diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 30b13a87d0f..4e509715636 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -352,7 +352,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t // Fully precompiled libraries should have no dependencies // to avoid ABI breakage if ctx.Verbose { - ctx.Info(tr("Skipping dependencies detection for precompiled library %[1]s", library.CanonicalName)) + ctx.Info(tr("Skipping dependencies detection for precompiled library %[1]s", library.Name)) } return nil } diff --git a/legacy/builder/phases/libraries_builder.go b/legacy/builder/phases/libraries_builder.go index 4fbe3de339e..ae1a09db11a 100644 --- a/legacy/builder/phases/libraries_builder.go +++ b/legacy/builder/phases/libraries_builder.go @@ -86,7 +86,7 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib } } - ctx.Info(tr("Library %[1]s has been declared precompiled:", library.CanonicalName)) + ctx.Info(tr("Library %[1]s has been declared precompiled:", library.Name)) // Try directory with full fpuSpecs first, if available if len(fpuSpecs) > 0 { @@ -129,7 +129,7 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) { if ctx.Verbose { - ctx.Info(tr(`Compiling library "%[1]s"`, library.CanonicalName)) + ctx.Info(tr(`Compiling library "%[1]s"`, library.Name)) } libraryBuildPath := buildPath.Join(library.CanonicalName) diff --git a/legacy/builder/print_used_libraries_if_verbose.go b/legacy/builder/print_used_libraries_if_verbose.go index 49430786b62..8c32c925995 100644 --- a/legacy/builder/print_used_libraries_if_verbose.go +++ b/legacy/builder/print_used_libraries_if_verbose.go @@ -36,13 +36,13 @@ func (s *PrintUsedLibrariesIfVerbose) Run(ctx *types.Context) error { if library.Version.String() == "" { ctx.Info( tr("Using library %[1]s in folder: %[2]s %[3]s", - library.CanonicalName, + library.Name, library.InstallDir, legacy)) } else { ctx.Info( tr("Using library %[1]s at version %[2]s in folder: %[3]s %[4]s", - library.CanonicalName, + library.Name, library.Version, library.InstallDir, legacy)) diff --git a/legacy/builder/resolve_library.go b/legacy/builder/resolve_library.go index 633266c7f80..3cb3c07aee3 100644 --- a/legacy/builder/resolve_library.go +++ b/legacy/builder/resolve_library.go @@ -45,7 +45,7 @@ func ResolveLibrary(ctx *types.Context, header string) *libraries.Library { } selected := resolver.ResolveFor(header, ctx.TargetPlatform.Platform.Architecture) - if alreadyImported := importedLibraries.FindByName(selected.CanonicalName); alreadyImported != nil { + if alreadyImported := importedLibraries.FindByName(selected.Name); alreadyImported != nil { // Certain libraries might have the same name but be different. // This usually happens when the user includes two or more custom libraries that have // different header name but are stored in a parent folder with identical name, like diff --git a/legacy/builder/test/helper.go b/legacy/builder/test/helper.go index 4c42075c774..16cbe3d044b 100644 --- a/legacy/builder/test/helper.go +++ b/legacy/builder/test/helper.go @@ -84,5 +84,5 @@ func (s ByLibraryName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s ByLibraryName) Less(i, j int) bool { - return s[i].CanonicalName < s[j].CanonicalName + return s[i].Name < s[j].Name } diff --git a/legacy/builder/test/includes_to_include_folders_test.go b/legacy/builder/test/includes_to_include_folders_test.go index 022e1c4649e..7049a06ef03 100644 --- a/legacy/builder/test/includes_to_include_folders_test.go +++ b/legacy/builder/test/includes_to_include_folders_test.go @@ -59,7 +59,7 @@ func TestIncludesToIncludeFolders(t *testing.T) { importedLibraries := ctx.ImportedLibraries require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "Bridge", importedLibraries[0].CanonicalName) + require.Equal(t, "Bridge", importedLibraries[0].Name) } func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) { @@ -131,8 +131,8 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 2, len(importedLibraries)) - require.Equal(t, "Bridge", importedLibraries[0].CanonicalName) - require.Equal(t, "IRremote", importedLibraries[1].CanonicalName) + require.Equal(t, "Bridge", importedLibraries[0].Name) + require.Equal(t, "IRremote", importedLibraries[1].Name) } func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { @@ -166,8 +166,8 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 2, len(importedLibraries)) - require.Equal(t, "ANewLibrary-master", importedLibraries[0].CanonicalName) - require.Equal(t, "IRremote", importedLibraries[1].CanonicalName) + require.Equal(t, "ANewLibrary-master", importedLibraries[0].Name) + require.Equal(t, "IRremote", importedLibraries[1].Name) } func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { @@ -203,7 +203,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "SPI", importedLibraries[0].CanonicalName) + require.Equal(t, "SPI", importedLibraries[0].Name) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI")) } @@ -241,7 +241,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "SPI", importedLibraries[0].CanonicalName) + require.Equal(t, "SPI", importedLibraries[0].Name) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "SPI")) } @@ -279,7 +279,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "USBHost", importedLibraries[0].CanonicalName) + require.Equal(t, "USBHost", importedLibraries[0].Name) requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "USBHost", "src")) } @@ -317,7 +317,7 @@ func TestIncludesToIncludeFoldersSubfolders(t *testing.T) { importedLibraries := ctx.ImportedLibraries sort.Sort(ByLibraryName(importedLibraries)) require.Equal(t, 3, len(importedLibraries)) - require.Equal(t, "testlib1", importedLibraries[0].CanonicalName) - require.Equal(t, "testlib2", importedLibraries[1].CanonicalName) - require.Equal(t, "testlib3", importedLibraries[2].CanonicalName) + require.Equal(t, "testlib1", importedLibraries[0].Name) + require.Equal(t, "testlib2", importedLibraries[1].Name) + require.Equal(t, "testlib3", importedLibraries[2].Name) } diff --git a/legacy/builder/test/libraries_loader_test.go b/legacy/builder/test/libraries_loader_test.go index 3ad3e15c305..4e1ca1a28f7 100644 --- a/legacy/builder/test/libraries_loader_test.go +++ b/legacy/builder/test/libraries_loader_test.go @@ -37,6 +37,7 @@ func extractLibraries(ctx *types.Context) []*libraries.Library { } return res } + func TestLoadLibrariesAVR(t *testing.T) { DownloadCoresAndToolsAndLibraries(t) @@ -72,10 +73,10 @@ func TestLoadLibrariesAVR(t *testing.T) { idx := 0 - require.Equal(t, "ANewLibrary-master", libs[idx].CanonicalName) + require.Equal(t, "ANewLibrary-master", libs[idx].Name) idx++ - require.Equal(t, "Adafruit_PN532", libs[idx].CanonicalName) + require.Equal(t, "Adafruit PN532", libs[idx].Name) require.True(t, Abs(t, paths.New("downloaded_libraries/Adafruit_PN532")).EquivalentTo(libs[idx].InstallDir)) require.True(t, Abs(t, paths.New("downloaded_libraries/Adafruit_PN532")).EquivalentTo(libs[idx].SourceDir)) require.Equal(t, 1, len(libs[idx].Architectures)) @@ -83,15 +84,15 @@ func TestLoadLibrariesAVR(t *testing.T) { require.False(t, libs[idx].IsLegacy) idx++ - require.Equal(t, "Audio", libs[idx].CanonicalName) + require.Equal(t, "Audio", libs[idx].Name) idx++ - require.Equal(t, "Balanduino", libs[idx].CanonicalName) + require.Equal(t, "Balanduino", libs[idx].Name) require.True(t, libs[idx].IsLegacy) idx++ bridgeLib := libs[idx] - require.Equal(t, "Bridge", bridgeLib.CanonicalName) + require.Equal(t, "Bridge", bridgeLib.Name) require.True(t, Abs(t, paths.New("downloaded_libraries/Bridge")).EquivalentTo(bridgeLib.InstallDir)) require.True(t, Abs(t, paths.New("downloaded_libraries/Bridge/src")).EquivalentTo(bridgeLib.SourceDir)) require.Equal(t, 1, len(bridgeLib.Architectures)) @@ -100,51 +101,51 @@ func TestLoadLibrariesAVR(t *testing.T) { require.Equal(t, "Arduino ", bridgeLib.Maintainer) idx++ - require.Equal(t, "CapacitiveSensor", libs[idx].CanonicalName) + require.Equal(t, "CapacitiveSensor", libs[idx].Name) idx++ - require.Equal(t, "EEPROM", libs[idx].CanonicalName) + require.Equal(t, "EEPROM", libs[idx].Name) idx++ - require.Equal(t, "Ethernet", libs[idx].CanonicalName) + require.Equal(t, "Ethernet", libs[idx].Name) idx++ - require.Equal(t, "FakeAudio", libs[idx].CanonicalName) + require.Equal(t, "FakeAudio", libs[idx].Name) idx++ - require.Equal(t, "FastLED", libs[idx].CanonicalName) + require.Equal(t, "FastLED", libs[idx].Name) idx++ - require.Equal(t, "HID", libs[idx].CanonicalName) + require.Equal(t, "HID", libs[idx].Name) idx++ - require.Equal(t, "IRremote", libs[idx].CanonicalName) + require.Equal(t, "IRremote", libs[idx].Name) idx++ - require.Equal(t, "Robot_IR_Remote", libs[idx].CanonicalName) + require.Equal(t, "Robot IR Remote", libs[idx].Name) idx++ - require.Equal(t, "SPI", libs[idx].CanonicalName) + require.Equal(t, "SPI", libs[idx].Name) idx++ - require.Equal(t, "SPI", libs[idx].CanonicalName) + require.Equal(t, "SPI", libs[idx].Name) idx++ - require.Equal(t, "ShouldNotRecurseWithOldLibs", libs[idx].CanonicalName) + require.Equal(t, "ShouldNotRecurseWithOldLibs", libs[idx].Name) idx++ - require.Equal(t, "SoftwareSerial", libs[idx].CanonicalName) + require.Equal(t, "SoftwareSerial", libs[idx].Name) idx++ - require.Equal(t, "USBHost", libs[idx].CanonicalName) + require.Equal(t, "USBHost", libs[idx].Name) idx++ - require.Equal(t, "Wire", libs[idx].CanonicalName) + require.Equal(t, "Wire", libs[idx].Name) libs = ctx.LibrariesResolver.AlternativesFor("Audio.h") require.Len(t, libs, 2) sort.Sort(ByLibraryName(libs)) - require.Equal(t, "Audio", libs[0].CanonicalName) - require.Equal(t, "FakeAudio", libs[1].CanonicalName) + require.Equal(t, "Audio", libs[0].Name) + require.Equal(t, "FakeAudio", libs[1].Name) libs = ctx.LibrariesResolver.AlternativesFor("FakeAudio.h") require.Len(t, libs, 1) - require.Equal(t, "FakeAudio", libs[0].CanonicalName) + require.Equal(t, "FakeAudio", libs[0].Name) libs = ctx.LibrariesResolver.AlternativesFor("Adafruit_PN532.h") require.Len(t, libs, 1) - require.Equal(t, "Adafruit_PN532", libs[0].CanonicalName) + require.Equal(t, "Adafruit PN532", libs[0].Name) libs = ctx.LibrariesResolver.AlternativesFor("IRremote.h") require.Len(t, libs, 1) - require.Equal(t, "IRremote", libs[0].CanonicalName) + require.Equal(t, "IRremote", libs[0].Name) } func TestLoadLibrariesSAM(t *testing.T) { @@ -181,53 +182,53 @@ func TestLoadLibrariesSAM(t *testing.T) { sort.Sort(ByLibraryName(libraries)) idx := 0 - require.Equal(t, "ANewLibrary-master", libraries[idx].CanonicalName) + require.Equal(t, "ANewLibrary-master", libraries[idx].Name) idx++ - require.Equal(t, "Adafruit_PN532", libraries[idx].CanonicalName) + require.Equal(t, "Adafruit PN532", libraries[idx].Name) idx++ - require.Equal(t, "Audio", libraries[idx].CanonicalName) + require.Equal(t, "Audio", libraries[idx].Name) idx++ - require.Equal(t, "Balanduino", libraries[idx].CanonicalName) + require.Equal(t, "Balanduino", libraries[idx].Name) idx++ - require.Equal(t, "Bridge", libraries[idx].CanonicalName) + require.Equal(t, "Bridge", libraries[idx].Name) idx++ - require.Equal(t, "CapacitiveSensor", libraries[idx].CanonicalName) + require.Equal(t, "CapacitiveSensor", libraries[idx].Name) idx++ - require.Equal(t, "Ethernet", libraries[idx].CanonicalName) + require.Equal(t, "Ethernet", libraries[idx].Name) idx++ - require.Equal(t, "FakeAudio", libraries[idx].CanonicalName) + require.Equal(t, "FakeAudio", libraries[idx].Name) idx++ - require.Equal(t, "FastLED", libraries[idx].CanonicalName) + require.Equal(t, "FastLED", libraries[idx].Name) idx++ - require.Equal(t, "HID", libraries[idx].CanonicalName) + require.Equal(t, "HID", libraries[idx].Name) idx++ - require.Equal(t, "IRremote", libraries[idx].CanonicalName) + require.Equal(t, "IRremote", libraries[idx].Name) idx++ - require.Equal(t, "Robot_IR_Remote", libraries[idx].CanonicalName) + require.Equal(t, "Robot IR Remote", libraries[idx].Name) idx++ - require.Equal(t, "SPI", libraries[idx].CanonicalName) + require.Equal(t, "SPI", libraries[idx].Name) idx++ - require.Equal(t, "SPI", libraries[idx].CanonicalName) + require.Equal(t, "SPI", libraries[idx].Name) idx++ - require.Equal(t, "ShouldNotRecurseWithOldLibs", libraries[idx].CanonicalName) + require.Equal(t, "ShouldNotRecurseWithOldLibs", libraries[idx].Name) idx++ - require.Equal(t, "USBHost", libraries[idx].CanonicalName) + require.Equal(t, "USBHost", libraries[idx].Name) idx++ - require.Equal(t, "Wire", libraries[idx].CanonicalName) + require.Equal(t, "Wire", libraries[idx].Name) libs := ctx.LibrariesResolver.AlternativesFor("Audio.h") require.Len(t, libs, 2) sort.Sort(ByLibraryName(libs)) - require.Equal(t, "Audio", libs[0].CanonicalName) - require.Equal(t, "FakeAudio", libs[1].CanonicalName) + require.Equal(t, "Audio", libs[0].Name) + require.Equal(t, "FakeAudio", libs[1].Name) libs = ctx.LibrariesResolver.AlternativesFor("FakeAudio.h") require.Len(t, libs, 1) - require.Equal(t, "FakeAudio", libs[0].CanonicalName) + require.Equal(t, "FakeAudio", libs[0].Name) libs = ctx.LibrariesResolver.AlternativesFor("IRremote.h") require.Len(t, libs, 1) - require.Equal(t, "IRremote", libs[0].CanonicalName) + require.Equal(t, "IRremote", libs[0].Name) } func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) { diff --git a/legacy/builder/test/unused_compiled_libraries_remover_test.go b/legacy/builder/test/unused_compiled_libraries_remover_test.go index 47f8e7196d8..f6965cee0ff 100644 --- a/legacy/builder/test/unused_compiled_libraries_remover_test.go +++ b/legacy/builder/test/unused_compiled_libraries_remover_test.go @@ -36,7 +36,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { ctx := &types.Context{} ctx.LibrariesBuildPath = temp - ctx.ImportedLibraries = []*libraries.Library{{CanonicalName: "Bridge"}} + ctx.ImportedLibraries = []*libraries.Library{{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} err = cmd.Run(ctx) @@ -56,7 +56,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) { func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) { ctx := &types.Context{} ctx.LibrariesBuildPath = paths.TempDir().Join("test") - ctx.ImportedLibraries = []*libraries.Library{{CanonicalName: "Bridge"}} + ctx.ImportedLibraries = []*libraries.Library{{Name: "Bridge"}} cmd := builder.UnusedCompiledLibrariesRemover{} err := cmd.Run(ctx) diff --git a/legacy/builder/unused_compiled_libraries_remover.go b/legacy/builder/unused_compiled_libraries_remover.go index 72d97df5eb3..595ce91302e 100644 --- a/legacy/builder/unused_compiled_libraries_remover.go +++ b/legacy/builder/unused_compiled_libraries_remover.go @@ -53,7 +53,7 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error { func toLibraryNames(libraries []*libraries.Library) []string { libraryNames := []string{} for _, library := range libraries { - libraryNames = append(libraryNames, library.CanonicalName) + libraryNames = append(libraryNames, library.Name) } return libraryNames } diff --git a/legacy/builder/warn_about_arch_incompatible_libraries.go b/legacy/builder/warn_about_arch_incompatible_libraries.go index 179f27a166c..712f79b2fe5 100644 --- a/legacy/builder/warn_about_arch_incompatible_libraries.go +++ b/legacy/builder/warn_about_arch_incompatible_libraries.go @@ -37,7 +37,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error { if !importedLibrary.SupportsAnyArchitectureIn(archs...) { ctx.Info( tr("WARNING: library %[1]s claims to run on %[2]s architecture(s) and may be incompatible with your current board which runs on %[3]s architecture(s).", - importedLibrary.CanonicalName, + importedLibrary.Name, strings.Join(importedLibrary.Architectures, ", "), strings.Join(archs, ", "))) } diff --git a/rpc/cc/arduino/cli/commands/v1/lib.pb.go b/rpc/cc/arduino/cli/commands/v1/lib.pb.go index 8b228350fc4..8753f33b7aa 100644 --- a/rpc/cc/arduino/cli/commands/v1/lib.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/lib.pb.go @@ -1744,6 +1744,8 @@ type Library struct { // (e.g., `arduino:avr@1.8.2`). ContainerPlatform string `protobuf:"bytes,14,opt,name=container_platform,json=containerPlatform,proto3" json:"container_platform,omitempty"` // Value of the `name` field in library.properties. + // + // Deprecated: Do not use. RealName string `protobuf:"bytes,16,opt,name=real_name,json=realName,proto3" json:"real_name,omitempty"` // Value of the `dot_a_linkage` field in library.properties. DotALinkage bool `protobuf:"varint,17,opt,name=dot_a_linkage,json=dotALinkage,proto3" json:"dot_a_linkage,omitempty"` @@ -1896,6 +1898,7 @@ func (x *Library) GetContainerPlatform() string { return "" } +// Deprecated: Do not use. func (x *Library) GetRealName() string { if x != nil { return x.RealName @@ -2461,7 +2464,7 @@ var file_cc_arduino_cli_commands_v1_lib_proto_rawDesc = []byte{ 0x32, 0x2a, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x52, 0x07, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x22, 0xee, 0x08, 0x0a, 0x07, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, + 0x6c, 0x65, 0x61, 0x73, 0x65, 0x22, 0xf2, 0x08, 0x0a, 0x07, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x12, 0x1e, 0x0a, @@ -2486,118 +2489,119 @@ var file_cc_arduino_cli_commands_v1_lib_proto_rawDesc = []byte{ 0x75, 0x74, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x44, 0x69, 0x72, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x65, 0x61, - 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, - 0x61, 0x6c, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x64, 0x6f, 0x74, 0x5f, 0x61, 0x5f, - 0x6c, 0x69, 0x6e, 0x6b, 0x61, 0x67, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x64, - 0x6f, 0x74, 0x41, 0x4c, 0x69, 0x6e, 0x6b, 0x61, 0x67, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x72, - 0x65, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x18, 0x12, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x0b, 0x70, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, - 0x6c, 0x64, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x6c, 0x64, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x73, 0x5f, 0x6c, 0x65, - 0x67, 0x61, 0x63, 0x79, 0x18, 0x14, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x4c, 0x65, - 0x67, 0x61, 0x63, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, - 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x18, - 0x0a, 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x70, - 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x18, 0x17, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x33, 0x2e, 0x63, - 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, - 0x79, 0x2e, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x12, 0x47, 0x0a, - 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x18, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x2b, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, + 0x72, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x1f, 0x0a, 0x09, 0x72, 0x65, 0x61, + 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, + 0x52, 0x08, 0x72, 0x65, 0x61, 0x6c, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x64, 0x6f, + 0x74, 0x5f, 0x61, 0x5f, 0x6c, 0x69, 0x6e, 0x6b, 0x61, 0x67, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x0b, 0x64, 0x6f, 0x74, 0x41, 0x4c, 0x69, 0x6e, 0x6b, 0x61, 0x67, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x70, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x18, 0x12, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x0b, 0x70, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, + 0x12, 0x19, 0x0a, 0x08, 0x6c, 0x64, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x18, 0x13, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6c, 0x64, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x69, + 0x73, 0x5f, 0x6c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x18, 0x14, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, + 0x69, 0x73, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x18, 0x16, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x0a, + 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x18, 0x17, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x33, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, + 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, + 0x62, 0x72, 0x61, 0x72, 0x79, 0x2e, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, + 0x73, 0x12, 0x47, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x18, 0x20, + 0x01, 0x28, 0x0e, 0x32, 0x2b, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, + 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, + 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x41, 0x0a, 0x06, 0x6c, 0x61, + 0x79, 0x6f, 0x75, 0x74, 0x18, 0x19, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x29, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4c, + 0x61, 0x79, 0x6f, 0x75, 0x74, 0x52, 0x06, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x08, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x70, 0x72, 0x6f, + 0x76, 0x69, 0x64, 0x65, 0x73, 0x5f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x73, 0x18, 0x1b, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x10, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x73, 0x49, 0x6e, + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x73, 0x12, 0x60, 0x0a, 0x0f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, + 0x69, 0x62, 0x6c, 0x65, 0x5f, 0x77, 0x69, 0x74, 0x68, 0x18, 0x1c, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x37, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x62, - 0x72, 0x61, 0x72, 0x79, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x6c, 0x6f, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x41, 0x0a, 0x06, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, - 0x18, 0x19, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x29, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, - 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4c, 0x61, 0x79, 0x6f, 0x75, - 0x74, 0x52, 0x06, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, - 0x73, 0x5f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x73, 0x18, 0x1b, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x10, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x73, 0x49, 0x6e, 0x63, 0x6c, 0x75, 0x64, - 0x65, 0x73, 0x12, 0x60, 0x0a, 0x0f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, - 0x5f, 0x77, 0x69, 0x74, 0x68, 0x18, 0x1c, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x37, 0x2e, 0x63, 0x63, - 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, - 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, - 0x57, 0x69, 0x74, 0x68, 0x1a, 0x3d, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, - 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, - 0x02, 0x38, 0x01, 0x1a, 0x41, 0x0a, 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, - 0x65, 0x57, 0x69, 0x74, 0x68, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x8e, 0x01, 0x0a, 0x18, 0x5a, 0x69, 0x70, 0x4c, 0x69, - 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, - 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x76, 0x65, - 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x76, - 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x22, 0x6a, 0x0a, 0x19, 0x5a, 0x69, 0x70, 0x4c, 0x69, - 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x0d, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x70, 0x72, 0x6f, - 0x67, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x63, - 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, - 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x0c, 0x74, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, 0x67, 0x72, - 0x65, 0x73, 0x73, 0x22, 0x8c, 0x01, 0x0a, 0x18, 0x47, 0x69, 0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, - 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, - 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, - 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, - 0x63, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x75, 0x72, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, - 0x74, 0x65, 0x22, 0x6a, 0x0a, 0x19, 0x47, 0x69, 0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, - 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x4d, 0x0a, 0x0d, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, + 0x72, 0x61, 0x72, 0x79, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x57, + 0x69, 0x74, 0x68, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, + 0x69, 0x62, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x1a, 0x3d, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x41, 0x0a, 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x61, + 0x74, 0x69, 0x62, 0x6c, 0x65, 0x57, 0x69, 0x74, 0x68, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x8e, 0x01, 0x0a, 0x18, 0x5a, + 0x69, 0x70, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, + 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, + 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x1c, 0x0a, + 0x09, 0x6f, 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x09, 0x6f, 0x76, 0x65, 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x22, 0x6a, 0x0a, 0x19, 0x5a, + 0x69, 0x70, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x0d, 0x74, 0x61, 0x73, 0x6b, + 0x5f, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, + 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x61, 0x73, + 0x6b, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x0c, 0x74, 0x61, 0x73, 0x6b, 0x50, + 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x22, 0x8c, 0x01, 0x0a, 0x18, 0x47, 0x69, 0x74, 0x4c, + 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, - 0x52, 0x0c, 0x74, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2a, 0x61, - 0x0a, 0x16, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, - 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x1d, 0x4c, 0x49, 0x42, 0x52, - 0x41, 0x52, 0x59, 0x5f, 0x49, 0x4e, 0x53, 0x54, 0x41, 0x4c, 0x4c, 0x5f, 0x4c, 0x4f, 0x43, 0x41, - 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x53, 0x45, 0x52, 0x10, 0x00, 0x12, 0x24, 0x0a, 0x20, 0x4c, - 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x49, 0x4e, 0x53, 0x54, 0x41, 0x4c, 0x4c, 0x5f, 0x4c, - 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, - 0x01, 0x2a, 0x5a, 0x0a, 0x13, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x53, 0x65, 0x61, 0x72, - 0x63, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x20, 0x0a, 0x1c, 0x4c, 0x49, 0x42, 0x52, - 0x41, 0x52, 0x59, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, - 0x53, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x00, 0x12, 0x21, 0x0a, 0x1d, 0x4c, 0x49, - 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x5f, 0x53, 0x54, 0x41, - 0x54, 0x55, 0x53, 0x5f, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x01, 0x2a, 0x46, 0x0a, - 0x0d, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x12, 0x17, - 0x0a, 0x13, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, - 0x5f, 0x46, 0x4c, 0x41, 0x54, 0x10, 0x00, 0x12, 0x1c, 0x0a, 0x18, 0x4c, 0x49, 0x42, 0x52, 0x41, - 0x52, 0x59, 0x5f, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x52, 0x45, 0x43, 0x55, 0x52, 0x53, - 0x49, 0x56, 0x45, 0x10, 0x01, 0x2a, 0xc3, 0x01, 0x0a, 0x0f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, - 0x79, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a, 0x18, 0x4c, 0x49, 0x42, - 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x42, 0x55, - 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, 0x00, 0x12, 0x19, 0x0a, 0x15, 0x4c, 0x49, 0x42, 0x52, 0x41, - 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x53, 0x45, 0x52, - 0x10, 0x01, 0x12, 0x25, 0x0a, 0x21, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, - 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x50, 0x4c, 0x41, 0x54, 0x46, 0x4f, 0x52, 0x4d, 0x5f, - 0x42, 0x55, 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x30, 0x0a, 0x2c, 0x4c, 0x49, 0x42, - 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x52, 0x45, - 0x46, 0x45, 0x52, 0x45, 0x4e, 0x43, 0x45, 0x44, 0x5f, 0x50, 0x4c, 0x41, 0x54, 0x46, 0x4f, 0x52, - 0x4d, 0x5f, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, 0x03, 0x12, 0x1e, 0x0a, 0x1a, 0x4c, + 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, + 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x76, 0x65, 0x72, + 0x77, 0x72, 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x76, 0x65, + 0x72, 0x77, 0x72, 0x69, 0x74, 0x65, 0x22, 0x6a, 0x0a, 0x19, 0x47, 0x69, 0x74, 0x4c, 0x69, 0x62, + 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x0d, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x70, 0x72, 0x6f, 0x67, + 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, 0x67, + 0x72, 0x65, 0x73, 0x73, 0x52, 0x0c, 0x74, 0x61, 0x73, 0x6b, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, + 0x73, 0x73, 0x2a, 0x61, 0x0a, 0x16, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x6e, 0x73, + 0x74, 0x61, 0x6c, 0x6c, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x1d, + 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x49, 0x4e, 0x53, 0x54, 0x41, 0x4c, 0x4c, 0x5f, + 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x53, 0x45, 0x52, 0x10, 0x00, 0x12, + 0x24, 0x0a, 0x20, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x49, 0x4e, 0x53, 0x54, 0x41, + 0x4c, 0x4c, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x42, 0x55, 0x49, 0x4c, + 0x54, 0x49, 0x4e, 0x10, 0x01, 0x2a, 0x5a, 0x0a, 0x13, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x20, 0x0a, 0x1c, + 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, 0x5f, 0x53, + 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x00, 0x12, 0x21, + 0x0a, 0x1d, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x53, 0x45, 0x41, 0x52, 0x43, 0x48, + 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, + 0x01, 0x2a, 0x46, 0x0a, 0x0d, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4c, 0x61, 0x79, 0x6f, + 0x75, 0x74, 0x12, 0x17, 0x0a, 0x13, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x41, + 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x46, 0x4c, 0x41, 0x54, 0x10, 0x00, 0x12, 0x1c, 0x0a, 0x18, 0x4c, + 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x41, 0x59, 0x4f, 0x55, 0x54, 0x5f, 0x52, 0x45, + 0x43, 0x55, 0x52, 0x53, 0x49, 0x56, 0x45, 0x10, 0x01, 0x2a, 0xc3, 0x01, 0x0a, 0x0f, 0x4c, 0x69, + 0x62, 0x72, 0x61, 0x72, 0x79, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a, + 0x18, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, + 0x4e, 0x5f, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, 0x00, 0x12, 0x19, 0x0a, 0x15, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, - 0x55, 0x4e, 0x4d, 0x41, 0x4e, 0x41, 0x47, 0x45, 0x44, 0x10, 0x04, 0x42, 0x48, 0x5a, 0x46, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, - 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, - 0x63, 0x2f, 0x63, 0x63, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, - 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x55, 0x53, 0x45, 0x52, 0x10, 0x01, 0x12, 0x25, 0x0a, 0x21, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, + 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x50, 0x4c, 0x41, 0x54, 0x46, + 0x4f, 0x52, 0x4d, 0x5f, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x30, 0x0a, + 0x2c, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, 0x49, 0x4f, + 0x4e, 0x5f, 0x52, 0x45, 0x46, 0x45, 0x52, 0x45, 0x4e, 0x43, 0x45, 0x44, 0x5f, 0x50, 0x4c, 0x41, + 0x54, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x42, 0x55, 0x49, 0x4c, 0x54, 0x49, 0x4e, 0x10, 0x03, 0x12, + 0x1e, 0x0a, 0x1a, 0x4c, 0x49, 0x42, 0x52, 0x41, 0x52, 0x59, 0x5f, 0x4c, 0x4f, 0x43, 0x41, 0x54, + 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x4e, 0x4d, 0x41, 0x4e, 0x41, 0x47, 0x45, 0x44, 0x10, 0x04, 0x42, + 0x48, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, + 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, + 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x63, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, + 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, + 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/rpc/cc/arduino/cli/commands/v1/lib.proto b/rpc/cc/arduino/cli/commands/v1/lib.proto index c8c6f626b4c..f92bd99349c 100644 --- a/rpc/cc/arduino/cli/commands/v1/lib.proto +++ b/rpc/cc/arduino/cli/commands/v1/lib.proto @@ -280,7 +280,7 @@ message Library { // (e.g., `arduino:avr@1.8.2`). string container_platform = 14; // Value of the `name` field in library.properties. - string real_name = 16; + string real_name = 16 [ deprecated = true ]; // Value of the `dot_a_linkage` field in library.properties. bool dot_a_linkage = 17; // Value of the `precompiled` field in library.properties. From 078fd9f7d6d263f343b782829fd6d2c4b8ac4103 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Sep 2022 17:01:09 +0200 Subject: [PATCH 10/12] Updated documentation --- docs/UPGRADING.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index 775cbc8f684..0cd1eb0d272 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -4,6 +4,58 @@ Here you can find a list of migration guides to handle breaking changes between ## 0.28.0 +### Breaking changes in libraries name handling + +In the structure `github.com/arduino/arduino-cli/arduino/libraries.Library` the field: + +- `RealName` has been renamed to `Name` +- `Name` has been renamed to `CanonicalName` + +Now `Name` is the name of the library as it appears in the `library.properties` file and `CanonicalName` it's the name +of the directory containing the library. The `CanonicalName` is usually the name of the library with non-alphanumeric +characters converted to underscore, but it could be actually anything since the directory where the library is installed +can be freely renamed. + +This change improves the overall code base naming coherence since all the structures involving libraries have the `Name` +field that refers to the library name as it appears in the `library.properties` file. + +### `github.com/arduino/arduino-cli/arduino/libraries/librariesmanager.LibrariesManager.Install` removed parameter `installLocation` + +The method: + +```go +func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path, installLocation libraries.LibraryLocation) error { ... } +``` + +no more needs the `installLocation` parameter: + +```go +func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release, libPath *paths.Path) error { ... } +``` + +The install location is determined from the libPath. + +### `github.com/arduino/arduino-cli/arduino/libraries/librariesmanager.LibrariesManager.FindByReference` now returns a list of libraries. + +The method: + +```go +func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) *libraries.Library { ... } +``` + +has been changed to: + +```go +func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, installLocation libraries.LibraryLocation) libraries.List { ... } +``` + +the method now returns all the libraries matching the criteria and not just the first one. + +### `github.com/arduino/arduino-cli/arduino/libraries/librariesmanager.LibraryAlternatives` removed + +The structure `librariesmanager.LibraryAlternatives` has been removed. The `libraries.List` object can be used as a +replacement. + ### Breaking changes in UpdateIndex API (both gRPC and go-lang) The gRPC message `cc.arduino.cli.commands.v1.UpdateIndexResponse` has been changed from: From edad41fcb6b9410d827dde4dd5650d9498929acf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 19 Sep 2022 16:53:00 +0200 Subject: [PATCH 11/12] Update arduino/libraries/librarieslist.go Co-authored-by: Umberto Baldi <34278123+umbynos@users.noreply.github.com> --- arduino/libraries/librarieslist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/libraries/librarieslist.go b/arduino/libraries/librarieslist.go index 3f807ebda67..9008bf2229b 100644 --- a/arduino/libraries/librarieslist.go +++ b/arduino/libraries/librarieslist.go @@ -62,7 +62,7 @@ func (list *List) FindByName(name string) *Library { return nil } -// FilterByVersionAndInstallLocation returns the libraries mathching the provided version and install location. If version +// FilterByVersionAndInstallLocation returns the libraries matching the provided version and install location. If version // is nil all version are matched. func (list *List) FilterByVersionAndInstallLocation(version *semver.Version, installLocation LibraryLocation) List { var found List From ac3018bc478bcfcd13d99e017a741c795d76a558 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 19 Sep 2022 16:57:36 +0200 Subject: [PATCH 12/12] Improved integration test --- internal/integrationtest/lib/lib_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/integrationtest/lib/lib_test.go b/internal/integrationtest/lib/lib_test.go index ad8cc029b3d..661e3d8b5eb 100644 --- a/internal/integrationtest/lib/lib_test.go +++ b/internal/integrationtest/lib/lib_test.go @@ -126,10 +126,13 @@ func TestDuplicateLibInstallDetection(t *testing.T) { require.NoError(t, err) requirejson.Len(t, jsonOut, 2, "Duplicate library install is not detected by the CLI") - _, _, err = cli.Run("lib", "install", "ArduinoOTA") + _, stdErr, err := cli.Run("lib", "install", "ArduinoOTA") require.Error(t, err) - _, _, err = cli.Run("lib", "upgrade", "ArduinoOTA") + require.Contains(t, string(stdErr), "The library ArduinoOTA has multiple installations") + _, stdErr, err = cli.Run("lib", "upgrade", "ArduinoOTA") require.Error(t, err) - _, _, err = cli.Run("lib", "uninstall", "ArduinoOTA") + require.Contains(t, string(stdErr), "The library ArduinoOTA has multiple installations") + _, stdErr, err = cli.Run("lib", "uninstall", "ArduinoOTA") require.Error(t, err) + require.Contains(t, string(stdErr), "The library ArduinoOTA has multiple installations") }