Skip to content

Commit

Permalink
Removed weird hack in the library detector
Browse files Browse the repository at this point in the history
Previously the libraries detector had to load the single librares
provided via '--library' flag after a Rescan, because the library
manager wasn't able to handle a single folder library. Now it can so we
removed all the tricky machinery.
  • Loading branch information
cmaglie committed Dec 22, 2023
1 parent 17cbf4f commit 2728183
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
15 changes: 8 additions & 7 deletions internal/arduino/builder/internal/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,14 @@ func LibrariesLoader(
})
}

for _, dir := range libraryDirs {
lm.AddLibrariesDir(&librariesmanager.LibrariesDir{
Path: dir,
Location: libraries.Unmanaged,
IsSingleLibrary: true,
})
}

for _, status := range lm.RescanLibraries() {
// With the refactoring of the initialization step of the CLI we changed how
// errors are returned when loading platforms and libraries, that meant returning a list of
Expand All @@ -647,13 +655,6 @@ func LibrariesLoader(
// When we're gonna refactor the legacy package this will be gone.
verboseOut.Write([]byte(status.Message()))
}

for _, dir := range libraryDirs {
// Libraries specified this way have top priority
if err := lm.LoadLibraryFromDir(dir, libraries.Unmanaged); err != nil {
return nil, nil, nil, err
}
}
}

resolver := librariesresolver.NewCppResolver()
Expand Down
19 changes: 0 additions & 19 deletions internal/arduino/libraries/librariesmanager/librariesmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,6 @@ func (lm *LibrariesManager) loadLibrariesFromDir(librariesDir *LibrariesDir) []*
return statuses
}

// LoadLibraryFromDir loads one single library from the libRootDir.
// libRootDir must point to the root of a valid library.
// An error is returned if the path doesn't exist or loading of the library fails.
func (lm *LibrariesManager) LoadLibraryFromDir(libRootDir *paths.Path, location libraries.LibraryLocation) error {
if libRootDir.NotExist() {
return fmt.Errorf(tr("library path does not exist: %s"), libRootDir)
}

library, err := libraries.Load(libRootDir, location)
if err != nil {
return fmt.Errorf(tr("loading library from %[1]s: %[2]s"), libRootDir, err)
}

alternatives := lm.Libraries[library.Name]
alternatives.Add(library)
lm.Libraries[library.Name] = alternatives
return nil
}

// FindByReference return the installed libraries matching the Reference
// name and version or, if the version is nil, the libraries installed
// in the installLocation.
Expand Down

0 comments on commit 2728183

Please sign in to comment.