Skip to content

[skip-changelog] Exclude libraries with a missing .h file from lib list #2083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Exclude libraries with a missing .h file from lib commands
  • Loading branch information
MatteoPologruto committed Mar 28, 2023
commit 2ca033651455ef7ecfdf350f4ed7d15806fe5efb
22 changes: 22 additions & 0 deletions arduino/libraries/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"strings"

"github.com/arduino/arduino-cli/arduino/globals"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -126,6 +127,11 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
}

func makeLegacyLibrary(path *paths.Path, location LibraryLocation) (*Library, error) {
if foundHeader, err := containsHeaderFile(path); err != nil {
return nil, err
} else if !foundHeader {
return nil, errors.Errorf(tr("invalid library: no header files found"))
}
library := &Library{
InstallDir: path.Canonical(),
Location: location,
Expand Down Expand Up @@ -186,3 +192,19 @@ func addExamplesToPathList(examplesPath *paths.Path, list *paths.PathList) error
}
return nil
}

// containsHeaderFile returns true if the directory contains a ".h" file.
// Returns false otherwise
func containsHeaderFile(d *paths.Path) (bool, error) {
dirContent, err := d.ReadDir()
if err != nil {
return false, fmt.Errorf(tr("reading directory %[1]s content: %[2]w", d, err))
}
dirContent.FilterOutDirs()
headerExtensions := []string{}
for k := range globals.HeaderFilesValidExtensions {
headerExtensions = append(headerExtensions, k)
}
dirContent.FilterSuffix(headerExtensions...)
return len(dirContent) > 0, nil
}