Skip to content

Commit 27316e3

Browse files
authored
Fixed a compile library discovery regression (#987)
* Do not overwrite full headers list with declared 'includes' in library.properties Otherwise the automatic library discovery would be affected. Fix #960 * fixed tests for 'provides_includes'
1 parent 439c473 commit 27316e3

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

Diff for: arduino/libraries/libraries.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type Library struct {
7373
License string
7474
Properties *properties.Map
7575
Examples paths.PathList
76+
declaredHeaders []string
7677
sourceHeaders []string
7778
}
7879

@@ -157,7 +158,15 @@ func (library *Library) LocationPriorityFor(platformRelease, refPlatformRelease
157158
return 0
158159
}
159160

160-
// SourceHeaders returns the C++ headers in the library.
161+
// DeclaredHeaders returns the C++ headers that the library declares in library.properties
162+
func (library *Library) DeclaredHeaders() []string {
163+
if library.declaredHeaders == nil {
164+
library.declaredHeaders = []string{}
165+
}
166+
return library.declaredHeaders
167+
}
168+
169+
// SourceHeaders returns all the C++ headers in the library even if not declared in library.properties
161170
func (library *Library) SourceHeaders() ([]string, error) {
162171
if library.sourceHeaders == nil {
163172
cppHeaders, err := library.SourceDir.ReadDir()

Diff for: arduino/libraries/loader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
101101
}
102102

103103
if includes := libProperties.Get("includes"); includes != "" {
104-
library.sourceHeaders = commaSeparatedToList(includes)
104+
library.declaredHeaders = commaSeparatedToList(includes)
105105
}
106106

107107
if err := addExamples(library); err != nil {

Diff for: commands/lib/list.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ func GetOutputLibrary(lib *libraries.Library) (*rpc.Library, error) {
146146
cntplat = lib.ContainerPlatform.String()
147147
}
148148

149-
libHeaders, err := lib.SourceHeaders()
150-
if err != nil {
151-
return nil, errors.Errorf("getting library headers: %s", err)
152-
}
153-
154149
return &rpc.Library{
155150
Name: lib.Name,
156151
Author: lib.Author,
@@ -175,7 +170,7 @@ func GetOutputLibrary(lib *libraries.Library) (*rpc.Library, error) {
175170
Version: lib.Version.String(),
176171
License: lib.License,
177172
Examples: lib.Examples.AsStrings(),
178-
ProvidesIncludes: libHeaders,
173+
ProvidesIncludes: lib.DeclaredHeaders(),
179174
}, nil
180175
}
181176

Diff for: test/test_lib.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,18 @@ def test_list(run_command):
5656
assert 1 == len(data)
5757
# be sure data contains the available version
5858
assert "" != data[0]["release"]["version"]
59-
# be sure data contains the correct provides_includes field
60-
assert "ArduinoJson.h" == data[0]["library"]["provides_includes"][0]
61-
assert "ArduinoJson.hpp" == data[0]["library"]["provides_includes"][1]
6259

6360
# Install something we can list without provides_includes field given in library.properties
64-
result = run_command("lib install Braccio@2.0.4")
61+
result = run_command("lib install Arduino_APDS9960@1.0.3")
6562
assert result.ok
6663
# Look at the JSON output
67-
result = run_command("lib list Braccio --format json")
64+
result = run_command("lib list Arduino_APDS9960 --format json")
6865
assert result.ok
6966
assert "" == result.stderr
7067
data = json.loads(result.stdout)
7168
assert 1 == len(data)
7269
# be sure data contains the correct provides_includes field
73-
assert "Braccio.h" == data[0]["library"]["provides_includes"][0]
70+
assert "Arduino_APDS9960.h" == data[0]["library"]["provides_includes"][0]
7471

7572

7673
def test_install(run_command):

0 commit comments

Comments
 (0)