Skip to content

Commit eaf3f0d

Browse files
committed
Better defined sketch-vendored libraries priority
1 parent dcc216f commit eaf3f0d

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

Diff for: internal/arduino/libraries/libraries_location.go

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
// Unmanaged is for libraries set manually by the user in the CLI command or from the gRPC function.
4141
// Ideally it's used for `libraries` outside folders managed by the CLI.
4242
Unmanaged
43+
// Sketch is for libraries that are part of the sketch (inside the `libraries` subfolder of the sketch).
44+
Sketch
4345
)
4446

4547
func (d *LibraryLocation) String() string {
@@ -54,6 +56,8 @@ func (d *LibraryLocation) String() string {
5456
return "user"
5557
case Unmanaged:
5658
return "unmanaged"
59+
case Sketch:
60+
return "sketch"
5761
default:
5862
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
5963
}
@@ -86,6 +90,9 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
8690
case "unmanaged":
8791
*d = Unmanaged
8892
return nil
93+
case "sketch":
94+
*d = Sketch
95+
return nil
8996
default:
9097
return errors.New(i18n.Tr("invalid library location: %s", s))
9198
}
@@ -104,6 +111,8 @@ func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
104111
return rpc.LibraryLocation_LIBRARY_LOCATION_USER
105112
case Unmanaged:
106113
return rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED
114+
case Sketch:
115+
return rpc.LibraryLocation_LIBRARY_LOCATION_SKETCH
107116
default:
108117
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
109118
}
@@ -122,6 +131,8 @@ func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
122131
return User
123132
case rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED:
124133
return Unmanaged
134+
case rpc.LibraryLocation_LIBRARY_LOCATION_SKETCH:
135+
return Sketch
125136
default:
126137
panic(fmt.Sprintf("invalid rpc.LibraryLocation value %d", l))
127138
}

Diff for: internal/arduino/libraries/libraries_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestLibLayoutAndLocationJSONUnMarshaler(t *testing.T) {
5050
testLocation(ReferencedPlatformBuiltIn)
5151
testLocation(User)
5252
testLocation(Unmanaged)
53+
testLocation(Sketch)
5354
}
5455

5556
func TestLibrariesLoader(t *testing.T) {

Diff for: internal/arduino/libraries/librariesresolver/cpp.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,12 @@ func ComputePriority(lib *libraries.Library, header, arch string) int {
207207
priority += 2
208208
case libraries.User:
209209
priority += 3
210+
case libraries.Sketch:
211+
// Bonus for sketch libraries, those libraries get a better priority than others
212+
priority += 10000
210213
case libraries.Unmanaged:
211214
// Bonus for libraries specified via --libraries flags, those libraries gets the highest priority
212-
priority += 10000
215+
priority += 20000
213216
default:
214217
panic(fmt.Sprintf("Invalid library location: %d", lib.Location))
215218
}

Diff for: internal/arduino/sketch/sketch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func New(path *paths.Path) (*Sketch, error) {
152152
}
153153
libDirs.FilterDirs()
154154
for _, libDir := range libDirs {
155-
lib, err := libraries.Load(libDir, libraries.Unmanaged)
155+
lib, err := libraries.Load(libDir, libraries.Sketch)
156156
if err != nil {
157157
return nil, fmt.Errorf("%s: %w", i18n.Tr("reading sketch libraries"), err)
158158
}

Diff for: internal/cli/feedback/result/rpc.go

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const (
172172
LibraryLocationPlatformBuiltin LibraryLocation = "platform"
173173
LibraryLocationReferencedPlatformBuiltin LibraryLocation = "ref-platform"
174174
LibraryLocationUnmanged LibraryLocation = "unmanaged"
175+
LibraryLocationSketch LibraryLocation = "sketch"
175176
)
176177

177178
func NewLibraryLocation(r rpc.LibraryLocation) LibraryLocation {
@@ -186,6 +187,8 @@ func NewLibraryLocation(r rpc.LibraryLocation) LibraryLocation {
186187
return LibraryLocationUser
187188
case rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED:
188189
return LibraryLocationUnmanged
190+
case rpc.LibraryLocation_LIBRARY_LOCATION_SKETCH:
191+
return LibraryLocationSketch
189192
}
190193
return LibraryLocationIDEBuiltin
191194
}

Diff for: rpc/cc/arduino/cli/commands/v1/lib.pb.go

+13-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: rpc/cc/arduino/cli/commands/v1/lib.proto

+2
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ enum LibraryLocation {
379379
LIBRARY_LOCATION_REFERENCED_PLATFORM_BUILTIN = 3;
380380
// Outside the `libraries` folders managed by the CLI.
381381
LIBRARY_LOCATION_UNMANAGED = 4;
382+
// Inside the `libraries` folder of the sketch.
383+
LIBRARY_LOCATION_SKETCH = 5;
382384
}
383385

384386
message ZipLibraryInstallRequest {

0 commit comments

Comments
 (0)