Skip to content

Commit f2e584b

Browse files
committed
major changes underway to rework library handling for different architectures
1 parent 5fef895 commit f2e584b

File tree

9 files changed

+275
-178
lines changed

9 files changed

+275
-178
lines changed

app/src/processing/app/Library.java

Lines changed: 137 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111

1212

1313
public class Library extends LocalContribution {
14-
static final String[] platformNames = PConstants.platformNames;
14+
// static final String[] platformNames = PConstants.platformNames;
15+
16+
static StringDict newToOld = new StringDict(new String[][] {
17+
{ "macos-x86_64", "macosx" },
18+
{ "windows-amd64", "windows64" },
19+
{ "linux-amd64", "linux64" },
20+
{ "linux-arm", "linux-armv6hf" },
21+
{ "linux-aarch64", "linux-arm64" }
22+
});
1523

1624
protected File libraryFolder; // shortname/library
1725
protected File examplesFolder; // shortname/examples
@@ -30,21 +38,22 @@ public class Library extends LocalContribution {
3038
/** Per-platform exports for this library. */
3139
Map<String, String[]> exportList;
3240

33-
/** Applet exports (cross-platform by definition). */
34-
String[] appletExportList;
35-
3641
/** Android exports (single platform for now, may not exist). */
3742
String[] androidExportList;
3843

39-
/** True if there are separate 32/64 bit for the specified platform index. */
40-
boolean[] multipleArch = new boolean[platformNames.length];
44+
// /** True if there are separate 32/64 bit for the specified platform index. */
45+
// boolean[] multipleArch = new boolean[platformNames.length];
46+
// Map<String, Boolean> multipleArch = new HashMap<>();
4147

4248
/**
4349
* For runtime, the native library path for this platform. e.g. on Windows 64,
4450
* this might be the windows64 subfolder with the library.
4551
*/
4652
String nativeLibraryPath;
4753

54+
// /** True if */
55+
// boolean variants;
56+
4857
static public final String propertiesFileName = "library.properties";
4958

5059
/**
@@ -59,25 +68,24 @@ public class Library extends LocalContribution {
5968
* explicitly listing all possible architectures, and so that
6069
* macos-blah as well as and macosx will be handled properly.
6170
*/
62-
static FilenameFilter standardFilter = new FilenameFilter() {
63-
public boolean accept(File dir, String name) {
64-
// skip .DS_Store files, .svn folders, etc
65-
if (name.charAt(0) == '.') return false;
66-
// ha, the sftp library still has one [fry 220121]
67-
if (name.equals("CVS")) return false;
68-
if (name.equals("export.txt")) return false;
69-
70-
File file = new File(dir, name);
71-
if (file.isDirectory()) {
72-
if (name.startsWith("macos") ||
73-
name.startsWith("windows") ||
74-
name.startsWith("linux") ||
75-
name.startsWith("android")) {
76-
return false;
77-
}
71+
static FilenameFilter libraryFolderFilter = (dir, name) -> {
72+
// skip .DS_Store files, .svn folders, etc
73+
if (name.charAt(0) == '.') return false;
74+
// ha, the sftp library still has one [fry 220121]
75+
if (name.equals("CVS")) return false;
76+
if (name.equals("export.txt")) return false;
77+
78+
File file = new File(dir, name);
79+
if (file.isDirectory()) {
80+
//noinspection RedundantIfStatement
81+
if (name.startsWith("macos") ||
82+
name.startsWith("windows") ||
83+
name.startsWith("linux")) {
84+
//name.startsWith("android")) { // no libraries use this
85+
return false;
7886
}
79-
return true;
8087
}
88+
return true;
8189
};
8290

8391
static FilenameFilter jarFilter = (dir, name) -> {
@@ -122,66 +130,94 @@ private Library(File folder, String groupName) {
122130
* Handles all the Java-specific parsing for library handling.
123131
*/
124132
protected void handle() {
125-
File exportSettings = new File(libraryFolder, "export.txt");
126-
StringDict exportTable = exportSettings.exists() ?
127-
Util.readSettings(exportSettings) : new StringDict();
128-
129-
exportList = new HashMap<>();
130-
131-
// get the list of files just in the library root
132-
String[] baseList = libraryFolder.list(standardFilter);
133-
// System.out.println("Loading " + name + "...");
134-
// PApplet.println(baseList);
133+
handleNative();
134+
handleExports();
135+
}
135136

136-
String appletExportStr = exportTable.get("applet");
137-
if (appletExportStr != null) {
138-
appletExportList = PApplet.splitTokens(appletExportStr, ", ");
139-
} else {
140-
appletExportList = baseList;
141-
}
142137

143-
String androidExportStr = exportTable.get("android");
144-
if (androidExportStr != null) {
145-
androidExportList = PApplet.splitTokens(androidExportStr, ", ");
146-
} else {
147-
androidExportList = baseList;
148-
}
138+
/**
139+
* Identify nativeLibraryFolder location for the current platform.
140+
*/
141+
private void handleNative() {
142+
String variant = Platform.getVariant();
149143

150-
// for the host platform, need to figure out what's available
144+
// use the root of the library folder as the default
151145
File nativeLibraryFolder = libraryFolder;
146+
147+
/*
152148
String hostPlatform = Platform.getName();
153-
// System.out.println("1 native lib folder now " + nativeLibraryFolder);
154149
// see if there's a 'windows', 'macosx', or 'linux' folder
155150
File hostLibrary = new File(libraryFolder, hostPlatform);
156151
if (hostLibrary.exists()) {
157152
nativeLibraryFolder = hostLibrary;
158153
}
159-
// System.out.println("2 native lib folder now " + nativeLibraryFolder);
160-
// check for bit-specific version, e.g. on windows, check if there
161-
// is a window32 or windows64 folder (on windows)
162-
hostLibrary =
163-
new File(libraryFolder, hostPlatform + Platform.getNativeBits());
154+
*/
155+
156+
// see if there's a {platform}-{arch} folder
157+
File hostLibrary = new File(libraryFolder, variant);
164158
if (hostLibrary.exists()) {
165159
nativeLibraryFolder = hostLibrary;
166-
}
167-
// System.out.println("3 native lib folder now " + nativeLibraryFolder);
168160

169-
if (hostPlatform.equals("linux") && System.getProperty("os.arch").equals("arm")) {
170-
hostLibrary = new File(libraryFolder, "linux-armv6hf");
171-
if (hostLibrary.exists()) {
172-
nativeLibraryFolder = hostLibrary;
173-
}
174-
}
175-
if (hostPlatform.equals("linux") && System.getProperty("os.arch").equals("aarch64")) {
176-
hostLibrary = new File(libraryFolder, "linux-arm64");
177-
if (hostLibrary.exists()) {
178-
nativeLibraryFolder = hostLibrary;
161+
} else {
162+
// if not found, try the old-style naming
163+
String oldName = newToOld.get(variant);
164+
if (oldName != null) {
165+
hostLibrary = new File(libraryFolder, oldName);
166+
if (hostLibrary.exists()) {
167+
nativeLibraryFolder = hostLibrary;
168+
}
179169
}
180170
}
181171

182172
// save that folder for later use
183173
nativeLibraryPath = nativeLibraryFolder.getAbsolutePath();
174+
}
175+
184176

177+
private void handleExports() {
178+
/*
179+
File exportSettings = new File(libraryFolder, "export.txt");
180+
StringDict exportTable = exportSettings.exists() ?
181+
Util.readSettings(exportSettings) : new StringDict();
182+
*/
183+
184+
exportList = new HashMap<>();
185+
186+
// get the list of files just in the library root
187+
String[] baseList = libraryFolder.list(libraryFolderFilter);
188+
189+
for (String variant : Platform.getSupportedVariants().keys()) {
190+
File variantFolder = new File(libraryFolder, variant);
191+
if (!variantFolder.exists()) {
192+
// check to see if old naming is in use
193+
String oldName = newToOld.get(variant, null);
194+
if (oldName != null) {
195+
variantFolder = new File(libraryFolder, variant);
196+
if (variantFolder.exists()) {
197+
Messages.log("Please update " + getName() + " for Processing 4. " +
198+
variantFolder + " is the older naming scheme.");
199+
}
200+
}
201+
}
202+
if (variantFolder.exists()) {
203+
String[] entries = listPlatformEntries(libraryFolder, variant, baseList);
204+
if (entries != null) {
205+
exportList.put(variant, entries);
206+
}
207+
}
208+
}
209+
210+
/*
211+
// not actually used in any libraries
212+
String androidExportStr = exportTable.get("android");
213+
if (androidExportStr != null) {
214+
androidExportList = PApplet.splitTokens(androidExportStr, ", ");
215+
} else {
216+
androidExportList = baseList;
217+
}
218+
*/
219+
220+
/*
185221
// for each individual platform that this library supports, figure out what's around
186222
for (int i = 1; i < platformNames.length; i++) {
187223
String platformName = platformNames[i];
@@ -221,7 +257,8 @@ protected void handle() {
221257
}
222258
223259
if (platformList32 != null || platformList64 != null || platformListArmv6hf != null || platformListArm64 != null) {
224-
multipleArch[i] = true;
260+
//multipleArch[i] = true;
261+
multipleArch.put(platformName, true);
225262
}
226263
227264
// if there aren't any relevant imports specified or in their own folders,
@@ -249,6 +286,8 @@ protected void handle() {
249286
}
250287
}
251288
}
289+
*/
290+
252291
// for (String p : exportList.keySet()) {
253292
// System.out.println(p + " -> ");
254293
// PApplet.println(exportList.get(p));
@@ -265,7 +304,7 @@ protected void handle() {
265304
static String[] listPlatformEntries(File libraryFolder, String folderName, String[] baseList) {
266305
File folder = new File(libraryFolder, folderName);
267306
if (folder.exists()) {
268-
String[] entries = folder.list(standardFilter);
307+
String[] entries = folder.list((dir, name) -> name.charAt(0) != '.');
269308
if (entries != null) {
270309
String[] outgoing = new String[entries.length + baseList.length];
271310
for (int i = 0; i < entries.length; i++) {
@@ -349,12 +388,11 @@ public String getJarPath() {
349388
}
350389

351390

352-
// this prepends a colon so that it can be appended to other paths safely
391+
// the returned value begins with File.pathSeparatorChar
392+
// so that it can be appended to other paths safely
353393
public String getClassPath() {
354394
StringBuilder cp = new StringBuilder();
355395

356-
// PApplet.println(libraryFolder.getAbsolutePath());
357-
// PApplet.println(libraryFolder.list());
358396
String[] jarHeads = libraryFolder.list(jarFilter);
359397
if (jarHeads != null) {
360398
for (String jar : jarHeads) {
@@ -372,7 +410,6 @@ public String getClassPath() {
372410
}
373411
}
374412
}
375-
//cp.setLength(cp.length() - 1); // remove the last separator
376413
return cp.toString();
377414
}
378415

@@ -391,17 +428,16 @@ protected File[] wrapFiles(String[] list) {
391428
}
392429

393430

431+
/*
394432
public File[] getApplicationExports(int platform, String variant) {
395433
String[] list = getApplicationExportList(platform, variant);
396434
return wrapFiles(list);
397435
}
398436
399437
400-
/**
401-
* Returns the necessary exports for the specified platform.
402-
* If no 32 or 64-bit version of the exports exists, it returns the version
403-
* that doesn't specify bit depth.
404-
*/
438+
// * Returns the necessary exports for the specified platform.
439+
// * If no 32 or 64-bit version of the exports exists, it returns the version
440+
// * that doesn't specify bit depth.
405441
public String[] getApplicationExportList(int platform, String variant) {
406442
String platformName = PConstants.platformNames[platform];
407443
if (variant.equals("32")) {
@@ -419,6 +455,11 @@ public String[] getApplicationExportList(int platform, String variant) {
419455
}
420456
return exportList.get(platformName);
421457
}
458+
*/
459+
460+
public String[] getApplicationExportList(String variant) {
461+
return exportList.get(variant);
462+
}
422463

423464

424465
@SuppressWarnings("unused")
@@ -427,11 +468,15 @@ public File[] getAndroidExports() {
427468
}
428469

429470

471+
/*
430472
public boolean hasMultipleArch(int platform) {
431-
return multipleArch[platform];
473+
//return multipleArch[platform];
474+
return multipleArch.getOrDefault(platform, false);
432475
}
476+
*/
433477

434478

479+
/*
435480
public boolean supportsArch(int platform, String variant) {
436481
// If this is a universal library, or has no natives, then we're good.
437482
if (multipleArch[platform] == false) {
@@ -440,10 +485,26 @@ public boolean supportsArch(int platform, String variant) {
440485
return getApplicationExportList(platform, variant) != null;
441486
}
442487
488+
public boolean isUnsupported(int platform, String variant) {
489+
// If this is a universal library, or has no natives, then we're good.
490+
if (!multipleArch.containsKey(platformNames[platform])) {
491+
return false;
492+
}
493+
return getApplicationExportList(platform, variant) == null;
494+
}
495+
*/
496+
497+
498+
public boolean isUnsupported(String variant) {
499+
return getApplicationExportList(variant) == null;
500+
}
501+
443502

503+
/*
444504
static public boolean hasMultipleArch(int platform, List<Library> libraries) {
445505
return libraries.stream().anyMatch(library -> library.hasMultipleArch(platform));
446506
}
507+
*/
447508

448509

449510
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

0 commit comments

Comments
 (0)