Skip to content

Commit c28c854

Browse files
committed
Filter examples based on contributed libraries by architecture
Solves #4762
1 parent f74afc4 commit c28c854

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

app/src/processing/app/Base.java

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class Base {
8282

8383
public static final Predicate<UserLibrary> CONTRIBUTED = library -> library.getTypes() == null || library.getTypes().isEmpty() || library.getTypes().contains("Contributed");
8484
public static final Predicate<UserLibrary> RETIRED = library -> library.getTypes() != null && library.getTypes().contains("Retired");
85+
public static final Predicate<UserLibrary> COMPATIBLE = library -> library.getArchitectures() != null && (library.getArchitectures().contains("*") || library.getArchitectures().contains(BaseNoGui.getTargetPlatform().getId()));
8586

8687
private static final int RECENT_SKETCHES_MAX_SIZE = 10;
8788

@@ -1104,6 +1105,7 @@ public LibraryList getIDELibs() {
11041105
List<UserLibrary> libs = installedLibraries.stream()
11051106
.filter(CONTRIBUTED.negate())
11061107
.filter(RETIRED.negate())
1108+
.filter(COMPATIBLE)
11071109
.collect(Collectors.toList());
11081110
return new LibraryList(libs);
11091111
}

arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ private void scanLibrary(File folder, boolean isSketchbook) throws IOException {
187187
if (headers.length == 0) {
188188
throw new IOException(lib.getSrcFolder().getAbsolutePath());
189189
}
190-
installedLibraries.addOrReplace(lib);
190+
installedLibraries.addOrReplaceArchAware(lib);
191191
if (isSketchbook) {
192192
installedLibrariesWithDuplicates.add(lib);
193193
} else {
194-
installedLibrariesWithDuplicates.addOrReplace(lib);
194+
installedLibrariesWithDuplicates.addOrReplaceArchAware(lib);
195195
}
196196

197197
// Check if we can find the same library in the index

arduino-core/src/processing/app/packages/LibraryList.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,25 @@ public synchronized UserLibrary getByName(String name) {
5757
return null;
5858
}
5959

60+
public synchronized void addOrReplaceArchAware(UserLibrary lib) {
61+
addOrReplace(lib, true);
62+
}
63+
6064
public synchronized void addOrReplace(UserLibrary lib) {
61-
remove(lib);
65+
addOrReplace(lib, false);
66+
}
67+
68+
public synchronized void addOrReplace(UserLibrary lib, boolean archAware) {
69+
remove(lib, archAware);
6270
add(lib);
6371
}
64-
65-
public synchronized void remove(UserLibrary lib) {
72+
73+
public synchronized void remove(UserLibrary lib, boolean archAware) {
6674
UserLibrary l = getByName(lib.getName());
67-
if (l != null)
68-
super.remove(l);
75+
if (l != null) {
76+
if (!archAware || lib.getArchitectures().contains("*") || lib.getArchitectures().containsAll(l.getArchitectures()))
77+
super.remove(l);
78+
}
6979
}
7080

7181
public synchronized void sort() {

0 commit comments

Comments
 (0)