Skip to content

Commit 4ec6b97

Browse files
authored
[breaking] Fixed regression in library discovery (#1741)
* Fixed libraries-set selection for discovery Fix #1740 * removed useless variable * Added tests * Updated readme
1 parent f0245bc commit 4ec6b97

File tree

5 files changed

+90
-6
lines changed

5 files changed

+90
-6
lines changed

arduino/libraries/librariesresolver/cpp.go

+44
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121
"strings"
2222

23+
"github.com/arduino/arduino-cli/arduino/cores"
2324
"github.com/arduino/arduino-cli/arduino/libraries"
2425
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2526
"github.com/arduino/arduino-cli/arduino/utils"
@@ -53,6 +54,49 @@ func (resolver *Cpp) ScanFromLibrariesManager(lm *librariesmanager.LibrariesMana
5354
return nil
5455
}
5556

57+
// ScanIDEBuiltinLibraries reads ide-builtin librariers loaded in the LibrariesManager to find
58+
// and cache all C++ headers for later retrieval.
59+
func (resolver *Cpp) ScanIDEBuiltinLibraries(lm *librariesmanager.LibrariesManager) error {
60+
for _, libAlternatives := range lm.Libraries {
61+
for _, lib := range libAlternatives.Alternatives {
62+
if lib.Location == libraries.IDEBuiltIn {
63+
resolver.ScanLibrary(lib)
64+
}
65+
}
66+
}
67+
return nil
68+
}
69+
70+
// ScanUserAndUnmanagedLibraries reads user/unmanaged librariers loaded in the LibrariesManager to find
71+
// and cache all C++ headers for later retrieval.
72+
func (resolver *Cpp) ScanUserAndUnmanagedLibraries(lm *librariesmanager.LibrariesManager) error {
73+
for _, libAlternatives := range lm.Libraries {
74+
for _, lib := range libAlternatives.Alternatives {
75+
if lib.Location == libraries.User || lib.Location == libraries.Unmanaged {
76+
resolver.ScanLibrary(lib)
77+
}
78+
}
79+
}
80+
return nil
81+
}
82+
83+
// ScanPlatformLibraries reads platform-bundled libraries for a specific platform loaded in the LibrariesManager
84+
// to find and cache all C++ headers for later retrieval.
85+
func (resolver *Cpp) ScanPlatformLibraries(lm *librariesmanager.LibrariesManager, platform *cores.PlatformRelease) error {
86+
for _, libAlternatives := range lm.Libraries {
87+
for _, lib := range libAlternatives.Alternatives {
88+
if lib.Location != libraries.PlatformBuiltIn && lib.Location != libraries.ReferencedPlatformBuiltIn {
89+
continue
90+
}
91+
if lib.ContainerPlatform != platform {
92+
continue
93+
}
94+
resolver.ScanLibrary(lib)
95+
}
96+
}
97+
return nil
98+
}
99+
56100
// ScanLibrary reads a library to find and cache C++ headers for later retrieval
57101
func (resolver *Cpp) ScanLibrary(lib *libraries.Library) error {
58102
cppHeaders, err := lib.SourceHeaders()

docs/UPGRADING.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## 0.23.0
66

7+
### Arduino IDE builtin libraries are now excluded from the build when running `arduino-cli` standalone
8+
9+
Previously the "builtin libraries" in the Arduino IDE 1.8.x were always included in the build process. This wasn't the
10+
intended behaviour, `arduino-cli` should include them only if run as a daemon from the Arduino IDE. Now this is fixed,
11+
but since it has been the default behaviour from a very long time we decided to report it here as a breaking change.
12+
13+
If a compilation fail for a missing bundled library, you can fix it just by installing the missing library from the
14+
library manager as usual.
15+
716
### golang API: PackageManager.DownloadPlatformRelease no longer need `label` parameter
817

918
```go

legacy/builder/libraries_loader.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
3838
lm.AddLibrariesDir(folder, libraries.IDEBuiltIn)
3939
}
4040

41-
actualPlatform := ctx.ActualPlatform
42-
platform := ctx.TargetPlatform
43-
if actualPlatform != platform {
44-
lm.AddPlatformReleaseLibrariesDir(actualPlatform, libraries.ReferencedPlatformBuiltIn)
41+
if ctx.ActualPlatform != ctx.TargetPlatform {
42+
lm.AddPlatformReleaseLibrariesDir(ctx.ActualPlatform, libraries.ReferencedPlatformBuiltIn)
4543
}
46-
lm.AddPlatformReleaseLibrariesDir(platform, libraries.PlatformBuiltIn)
44+
lm.AddPlatformReleaseLibrariesDir(ctx.TargetPlatform, libraries.PlatformBuiltIn)
4745

4846
librariesFolders := ctx.OtherLibrariesDirs
4947
if err := librariesFolders.ToAbs(); err != nil {
@@ -72,9 +70,20 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
7270
}
7371

7472
resolver := librariesresolver.NewCppResolver()
75-
if err := resolver.ScanFromLibrariesManager(ctx.LibrariesManager); err != nil {
73+
if err := resolver.ScanIDEBuiltinLibraries(ctx.LibrariesManager); err != nil {
7674
return errors.WithStack(err)
7775
}
76+
if err := resolver.ScanUserAndUnmanagedLibraries(ctx.LibrariesManager); err != nil {
77+
return errors.WithStack(err)
78+
}
79+
if err := resolver.ScanPlatformLibraries(ctx.LibrariesManager, ctx.TargetPlatform); err != nil {
80+
return errors.WithStack(err)
81+
}
82+
if ctx.ActualPlatform != ctx.TargetPlatform {
83+
if err := resolver.ScanPlatformLibraries(ctx.LibrariesManager, ctx.ActualPlatform); err != nil {
84+
return errors.WithStack(err)
85+
}
86+
}
7887
ctx.LibrariesResolver = resolver
7988

8089
return nil

test/test_profiles.py

+19
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,22 @@ def test_compile_with_profiles(run_command, copy_sketch):
2828
# use profile with the required library -> should succeed
2929
result = run_command(["compile", "-m", "avr2", sketch_path])
3030
assert result.ok
31+
32+
33+
def test_builder_did_not_catch_libs_from_unused_platforms(run_command, copy_sketch):
34+
# Init the environment explicitly
35+
run_command(["core", "update-index"])
36+
37+
sketch_path = copy_sketch("sketch_with_error_including_wire")
38+
39+
# install two platforms with the Wire library bundled
40+
assert run_command(["core", "install", "arduino:avr"])
41+
assert run_command(["core", "install", "arduino:samd"])
42+
43+
# compile for AVR
44+
result = run_command(["compile", "-b", "arduino:avr:uno", sketch_path])
45+
assert result.failed
46+
47+
# check that the libary resolver did not take the SAMD bundled Wire library into account
48+
assert "samd" not in result.stdout
49+
assert "samd" not in result.stderr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <Wire.h>
2+
3+
this sketch has syntax errors

0 commit comments

Comments
 (0)