Skip to content

Commit fa8d666

Browse files
committed
Merge branch 'master' into local
2 parents 74164d4 + 922625c commit fa8d666

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

pythonforandroid/bootstraps/sdl2/build/build.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ def parse_args(args=None):
491491
'NAME:PATH_TO_PY[:foreground]')
492492
ap.add_argument('--add-source', dest='extra_source_dirs', action='append',
493493
help='Include additional source dirs in Java build')
494+
ap.add_argument('--try-system-python-compile', dest='try_system_python_compile',
495+
action='store_true',
496+
help='Use the system python during compileall if possible.')
494497
ap.add_argument('--no-compile-pyo', dest='no_compile_pyo', action='store_true',
495498
help='Do not optimise .py files to .pyo.')
496499
ap.add_argument('--sign', action='store_true',
@@ -524,6 +527,18 @@ def parse_args(args=None):
524527
if args.services is None:
525528
args.services = []
526529

530+
if args.try_system_python_compile:
531+
# Hardcoding python2.7 is okay for now, as python3 skips the
532+
# compilation anyway
533+
if not exists('crystax_python'):
534+
python_executable = 'python2.7'
535+
try:
536+
subprocess.call([python_executable, '--version'])
537+
except (OSError, subprocess.CalledProcessError):
538+
pass
539+
else:
540+
PYTHON = python_executable
541+
527542
if args.no_compile_pyo:
528543
PYTHON = None
529544
BLACKLIST_PATTERNS.remove('*.py')

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonUtil.java

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,58 @@
33
import java.io.File;
44

55
import android.util.Log;
6-
6+
import java.util.ArrayList;
7+
import java.io.FilenameFilter;
8+
import java.util.regex.Pattern;
79

810
public class PythonUtil {
911
private static final String TAG = "pythonutil";
1012

11-
protected static String[] getLibraries() {
12-
return new String[] {
13-
"SDL2",
14-
"SDL2_image",
15-
"SDL2_mixer",
16-
"SDL2_ttf",
17-
"python2.7",
18-
"python3.5m",
19-
"python3.6m",
20-
"main"
21-
};
13+
protected static void addLibraryIfExists(ArrayList<String> libsList, String pattern, File libsDir) {
14+
// pattern should be the name of the lib file, without the
15+
// preceding "lib" or suffix ".so", for instance "ssl.*" will
16+
// match files of the form "libssl.*.so".
17+
File [] files = libsDir.listFiles();
18+
19+
pattern = "lib" + pattern + "\\.so";
20+
Pattern p = Pattern.compile(pattern);
21+
for (int i = 0; i < files.length; ++i) {
22+
File file = files[i];
23+
String name = file.getName();
24+
Log.v(TAG, "Checking pattern " + pattern + " against " + name);
25+
if (p.matcher(name).matches()) {
26+
Log.v(TAG, "Pattern " + pattern + " matched file " + name);
27+
libsList.add(name.substring(3, name.length() - 3));
28+
}
29+
}
2230
}
2331

24-
public static void loadLibraries(File filesDir) {
32+
protected static ArrayList<String> getLibraries(File filesDir) {
33+
34+
String libsDirPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/";
35+
File libsDir = new File(libsDirPath);
36+
37+
ArrayList<String> libsList = new ArrayList<String>();
38+
addLibraryIfExists(libsList, "crystax", libsDir);
39+
addLibraryIfExists(libsList, "sqlite3", libsDir);
40+
libsList.add("SDL2");
41+
libsList.add("SDL2_image");
42+
libsList.add("SDL2_mixer");
43+
libsList.add("SDL2_ttf");
44+
addLibraryIfExists(libsList, "ssl.*", libsDir);
45+
addLibraryIfExists(libsList, "crypto.*", libsDir);
46+
libsList.add("python2.7");
47+
libsList.add("python3.5m");
48+
libsList.add("main");
49+
return libsList;
50+
}
51+
52+
public static void loadLibraries(File filesDir) {
2553

2654
String filesDirPath = filesDir.getAbsolutePath();
2755
boolean foundPython = false;
2856

29-
for (String lib : getLibraries()) {
57+
for (String lib : getLibraries(filesDir)) {
3058
Log.v(TAG, "Loading library: " + lib);
3159
try {
3260
System.loadLibrary(lib);
@@ -66,3 +94,4 @@ public static void loadLibraries(File filesDir) {
6694
Log.v(TAG, "Loaded everything!");
6795
}
6896
}
97+

0 commit comments

Comments
 (0)