Skip to content

Do not overwrite full headers list with declared 'includes' in library.properties #987

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 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion arduino/libraries/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Library struct {
License string
Properties *properties.Map
Examples paths.PathList
declaredHeaders []string
sourceHeaders []string
}

Expand Down Expand Up @@ -157,7 +158,15 @@ func (library *Library) LocationPriorityFor(platformRelease, refPlatformRelease
return 0
}

// SourceHeaders returns the C++ headers in the library.
// DeclaredHeaders returns the C++ headers that the library declares in library.properties
func (library *Library) DeclaredHeaders() []string {
if library.declaredHeaders == nil {
library.declaredHeaders = []string{}
}
return library.declaredHeaders
}

// SourceHeaders returns all the C++ headers in the library even if not declared in library.properties
func (library *Library) SourceHeaders() ([]string, error) {
if library.sourceHeaders == nil {
cppHeaders, err := library.SourceDir.ReadDir()
Expand Down
2 changes: 1 addition & 1 deletion arduino/libraries/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
}

if includes := libProperties.Get("includes"); includes != "" {
library.sourceHeaders = commaSeparatedToList(includes)
library.declaredHeaders = commaSeparatedToList(includes)
}

if err := addExamples(library); err != nil {
Expand Down
7 changes: 1 addition & 6 deletions commands/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ func GetOutputLibrary(lib *libraries.Library) (*rpc.Library, error) {
cntplat = lib.ContainerPlatform.String()
}

libHeaders, err := lib.SourceHeaders()
if err != nil {
return nil, errors.Errorf("getting library headers: %s", err)
}

return &rpc.Library{
Name: lib.Name,
Author: lib.Author,
Expand All @@ -175,7 +170,7 @@ func GetOutputLibrary(lib *libraries.Library) (*rpc.Library, error) {
Version: lib.Version.String(),
License: lib.License,
Examples: lib.Examples.AsStrings(),
ProvidesIncludes: libHeaders,
ProvidesIncludes: lib.DeclaredHeaders(),
}, nil
}

Expand Down
9 changes: 3 additions & 6 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,18 @@ def test_list(run_command):
assert 1 == len(data)
# be sure data contains the available version
assert "" != data[0]["release"]["version"]
# be sure data contains the correct provides_includes field
assert "ArduinoJson.h" == data[0]["library"]["provides_includes"][0]
assert "ArduinoJson.hpp" == data[0]["library"]["provides_includes"][1]

# Install something we can list without provides_includes field given in library.properties
result = run_command("lib install Braccio@2.0.4")
result = run_command("lib install Arduino_APDS9960@1.0.3")
assert result.ok
# Look at the JSON output
result = run_command("lib list Braccio --format json")
result = run_command("lib list Arduino_APDS9960 --format json")
assert result.ok
assert "" == result.stderr
data = json.loads(result.stdout)
assert 1 == len(data)
# be sure data contains the correct provides_includes field
assert "Braccio.h" == data[0]["library"]["provides_includes"][0]
assert "Arduino_APDS9960.h" == data[0]["library"]["provides_includes"][0]


def test_install(run_command):
Expand Down