Skip to content

Commit 4a75474

Browse files
committed
WIP: Add SDL3 bootstrap
1 parent ceed049 commit 4a75474

File tree

50 files changed

+1581
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1581
-31
lines changed

pythonforandroid/bootstrap.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def copy_files(src_root, dest_root, override=True, symlink=False):
3939

4040

4141
default_recipe_priorities = [
42-
"webview", "sdl2", "service_only" # last is highest
42+
"webview", "sdl2", "sdl3", "service_only" # last is highest
4343
]
4444
# ^^ NOTE: these are just the default priorities if no special rules
4545
# apply (which you can find in the code below), so basically if no
@@ -150,18 +150,18 @@ def get_bootstrap_dirs(self):
150150
return bootstrap_dirs
151151

152152
def _copy_in_final_files(self):
153-
if self.name == "sdl2":
154-
# Get the paths for copying SDL2's java source code:
155-
sdl2_recipe = Recipe.get_recipe("sdl2", self.ctx)
156-
sdl2_build_dir = sdl2_recipe.get_jni_dir()
157-
src_dir = join(sdl2_build_dir, "SDL", "android-project",
153+
if self.name in ["sdl2", "sdl3"]:
154+
# Get the paths for copying SDL's java source code:
155+
sdl_recipe = Recipe.get_recipe(self.name, self.ctx)
156+
sdl_build_dir = sdl_recipe.get_jni_dir()
157+
src_dir = join(sdl_build_dir, "SDL", "android-project",
158158
"app", "src", "main", "java",
159159
"org", "libsdl", "app")
160160
target_dir = join(self.dist_dir, 'src', 'main', 'java', 'org',
161161
'libsdl', 'app')
162162

163163
# Do actual copying:
164-
info('Copying in SDL2 .java files from: ' + str(src_dir))
164+
info('Copying in SDL .java files from: ' + str(src_dir))
165165
if not os.path.exists(target_dir):
166166
os.makedirs(target_dir)
167167
copy_files(src_dir, target_dir, override=True)
@@ -272,6 +272,13 @@ def have_dependency_in_recipes(dep):
272272
info('Using sdl2 bootstrap since it is in dependencies')
273273
return cls.get_bootstrap("sdl2", ctx)
274274

275+
# Special rule: return SDL3 bootstrap if there's an sdl3 dep:
276+
if (have_dependency_in_recipes("sdl3") and
277+
"sdl3" in [b.name for b in acceptable_bootstraps]
278+
):
279+
info('Using sdl3 bootstrap since it is in dependencies')
280+
return cls.get_bootstrap("sdl3", ctx)
281+
275282
# Special rule: return "webview" if we depend on common web recipe:
276283
for possible_web_dep in known_web_packages:
277284
if have_dependency_in_recipes(possible_web_dep):

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ def get_bootstrap_name():
7878
_bootstrap_name = get_bootstrap_name()
7979
else:
8080
PYTHON = "python3"
81-
_bootstrap_name = "sdl2"
81+
_bootstrap_name = "sdl3"
8282

8383
if PYTHON is not None and not exists(PYTHON):
8484
PYTHON = None
8585

86-
if _bootstrap_name in ('sdl2', 'webview', 'service_only', 'qt'):
86+
if _bootstrap_name in ('sdl2', 'sdl3', 'webview', 'service_only', 'qt'):
8787
WHITELIST_PATTERNS.append('pyconfig.h')
8888

8989
environment = jinja2.Environment(loader=jinja2.FileSystemLoader(
@@ -541,7 +541,7 @@ def make_package(args):
541541
"debug": "debug" in args.build_mode,
542542
"native_services": args.native_services
543543
}
544-
if get_bootstrap_name() == "sdl2":
544+
if get_bootstrap_name() in ["sdl2", "sdl3"]:
545545
render_args["url_scheme"] = url_scheme
546546

547547
render(
@@ -596,7 +596,7 @@ def make_package(args):
596596
"args": args,
597597
"private_version": hashlib.sha1(private_version.encode()).hexdigest()
598598
}
599-
if get_bootstrap_name() == "sdl2":
599+
if get_bootstrap_name() in ["sdl2", "sdl3"]:
600600
render_args["url_scheme"] = url_scheme
601601
render(
602602
'strings.tmpl.xml',
@@ -769,7 +769,7 @@ def create_argument_parser():
769769
ap.add_argument('--private', dest='private',
770770
help='the directory with the app source code files' +
771771
' (containing your main.py entrypoint)',
772-
required=(get_bootstrap_name() != "sdl2"))
772+
required=(get_bootstrap_name() not in ["sdl2", "sdl3"]))
773773
ap.add_argument('--package', dest='package',
774774
help=('The name of the java package the project will be'
775775
' packaged under.'),
@@ -787,7 +787,7 @@ def create_argument_parser():
787787
'same number of groups of numbers as previous '
788788
'versions.'),
789789
required=True)
790-
if get_bootstrap_name() == "sdl2":
790+
if get_bootstrap_name() in ["sdl2", "sdl3"]:
791791
ap.add_argument('--launcher', dest='launcher', action='store_true',
792792
help=('Provide this argument to build a multi-app '
793793
'launcher, rather than a single app.'))
@@ -1044,7 +1044,7 @@ def _read_configuration():
10441044
args.orientation, args.manifest_orientation
10451045
)
10461046

1047-
if get_bootstrap_name() == "sdl2":
1047+
if get_bootstrap_name() in ["sdl2", "sdl3"]:
10481048
args.sdl_orientation_hint = get_sdl_orientation_hint(args.orientation)
10491049

10501050
if args.res_xmls and isinstance(args.res_xmls[0], list):
@@ -1074,9 +1074,9 @@ def _read_configuration():
10741074
WHITELIST_PATTERNS += patterns
10751075

10761076
if args.private is None and \
1077-
get_bootstrap_name() == 'sdl2' and args.launcher is None:
1077+
get_bootstrap_name() in ['sdl2', 'sdl3'] and args.launcher is None:
10781078
print('Need --private directory or ' +
1079-
'--launcher (SDL2 bootstrap only)' +
1079+
'--launcher (SDL2/SDL3 bootstrap only)' +
10801080
'to have something to launch inside the .apk!')
10811081
sys.exit(1)
10821082
make_package(args)

pythonforandroid/bootstraps/common/build/jni/application/src/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
1414

1515
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)
1616

17-
LOCAL_SHARED_LIBRARIES := SDL2 python_shared
17+
LOCAL_SHARED_LIBRARIES := SDL3 python_shared
1818

1919
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
2020

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ protected static ArrayList<String> getLibraries(File libsDir) {
4949
addLibraryIfExists(libsList, "SDL2_image", libsDir);
5050
addLibraryIfExists(libsList, "SDL2_mixer", libsDir);
5151
addLibraryIfExists(libsList, "SDL2_ttf", libsDir);
52+
addLibraryIfExists(libsList, "SDL3", libsDir);
53+
addLibraryIfExists(libsList, "SDL3_image", libsDir);
54+
addLibraryIfExists(libsList, "SDL3_mixer", libsDir);
55+
addLibraryIfExists(libsList, "SDL3_ttf", libsDir);
5256
libsList.add("python3.5m");
5357
libsList.add("python3.6m");
5458
libsList.add("python3.7m");

pythonforandroid/bootstraps/common/build/templates/gradle.tmpl.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ org.gradle.jvmargs=-Xmx2500m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemor
66
{% if args.enable_androidx %}
77
android.useAndroidX=true
88
android.enableJetifier=true
9-
{% endif %}
9+
{% endif %}
10+
org.gradle.jvmargs=-Xmx4608m
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from os.path import join
2+
3+
import sh
4+
5+
from pythonforandroid.toolchain import (
6+
Bootstrap, shprint, current_directory, info, info_main)
7+
from pythonforandroid.util import ensure_dir, rmdir
8+
9+
10+
class SDL3GradleBootstrap(Bootstrap):
11+
name = 'sdl3'
12+
13+
recipe_depends = list(
14+
set(Bootstrap.recipe_depends).union({'sdl3'})
15+
)
16+
17+
def assemble_distribution(self):
18+
info_main("# Creating Android project ({})".format(self.name))
19+
20+
rmdir(self.dist_dir)
21+
info("Copying SDL3/gradle build")
22+
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
23+
24+
# either the build use environment variable (ANDROID_HOME)
25+
# or the local.properties if exists
26+
with current_directory(self.dist_dir):
27+
with open('local.properties', 'w') as fileh:
28+
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
29+
30+
with current_directory(self.dist_dir):
31+
info("Copying Python distribution")
32+
33+
self.distribute_javaclasses(self.ctx.javaclass_dir,
34+
dest_dir=join("src", "main", "java"))
35+
36+
for arch in self.ctx.archs:
37+
python_bundle_dir = join(f'_python_bundle__{arch.arch}', '_python_bundle')
38+
ensure_dir(python_bundle_dir)
39+
40+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
41+
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
42+
join(self.dist_dir, python_bundle_dir), arch)
43+
if not self.ctx.with_debug_symbols:
44+
self.strip_libraries(arch)
45+
self.fry_eggs(site_packages_dir)
46+
47+
if 'sqlite3' not in self.ctx.recipe_build_order:
48+
with open('blacklist.txt', 'a') as fileh:
49+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
50+
51+
super().assemble_distribution()
52+
53+
54+
bootstrap = SDL3GradleBootstrap()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.gradle
2+
/build/
3+
4+
# Ignore Gradle GUI config
5+
gradle-app.setting
6+
7+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
8+
!gradle-wrapper.jar
9+
10+
# Cache of project
11+
.gradletasknamecache
12+
13+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
14+
# gradle/wrapper/gradle-wrapper.properties
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# prevent user to include invalid extensions
2+
*.apk
3+
*.aab
4+
*.apks
5+
*.pxd
6+
7+
# eggs
8+
*.egg-info
9+
10+
# unit test
11+
unittest/*
12+
13+
# python config
14+
config/makesetup
15+
16+
# unused kivy files (platform specific)
17+
kivy/input/providers/wm_*
18+
kivy/input/providers/mactouch*
19+
kivy/input/providers/probesysfs*
20+
kivy/input/providers/mtdev*
21+
kivy/input/providers/hidinput*
22+
kivy/core/camera/camera_videocapture*
23+
kivy/core/spelling/*osx*
24+
kivy/core/video/video_pyglet*
25+
kivy/tools
26+
kivy/tests/*
27+
kivy/*/*.h
28+
kivy/*/*.pxi
29+
30+
# unused encodings
31+
lib-dynload/*codec*
32+
encodings/cp*.pyo
33+
encodings/tis*
34+
encodings/shift*
35+
encodings/bz2*
36+
encodings/iso*
37+
encodings/undefined*
38+
encodings/johab*
39+
encodings/p*
40+
encodings/m*
41+
encodings/euc*
42+
encodings/k*
43+
encodings/unicode_internal*
44+
encodings/quo*
45+
encodings/gb*
46+
encodings/big5*
47+
encodings/hp*
48+
encodings/hz*
49+
50+
# unused python modules
51+
bsddb/*
52+
wsgiref/*
53+
hotshot/*
54+
pydoc_data/*
55+
tty.pyo
56+
anydbm.pyo
57+
nturl2path.pyo
58+
LICENCE.txt
59+
macurl2path.pyo
60+
dummy_threading.pyo
61+
audiodev.pyo
62+
antigravity.pyo
63+
dumbdbm.pyo
64+
sndhdr.pyo
65+
__phello__.foo.pyo
66+
sunaudio.pyo
67+
os2emxpath.pyo
68+
multiprocessing/dummy*
69+
70+
# unused binaries python modules
71+
lib-dynload/termios.so
72+
lib-dynload/_lsprof.so
73+
lib-dynload/*audioop.so
74+
lib-dynload/_hotshot.so
75+
lib-dynload/_heapq.so
76+
lib-dynload/_json.so
77+
lib-dynload/grp.so
78+
lib-dynload/resource.so
79+
lib-dynload/pyexpat.so
80+
lib-dynload/_ctypes_test.so
81+
lib-dynload/_testcapi.so
82+
83+
# odd files
84+
plat-linux3/regen
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
# Uncomment this if you're using STL in your project
3+
# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information
4+
# APP_STL := stlport_static
5+
6+
# APP_ABI := armeabi armeabi-v7a x86
7+
APP_ABI := $(ARCH)
8+
APP_PLATFORM := $(NDK_API)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
include $(CLEAR_VARS)
4+
5+
LOCAL_MODULE := main
6+
7+
LOCAL_SRC_FILES := start.c
8+
9+
LOCAL_STATIC_LIBRARIES := SDL3_static
10+
11+
include $(BUILD_SHARED_LIBRARY)
12+
$(call import-module,SDL)LOCAL_PATH := $(call my-dir)

0 commit comments

Comments
 (0)