Skip to content

Commit e95cceb

Browse files
committed
Add SDL3 bootstrap
1 parent fbd5255 commit e95cceb

File tree

56 files changed

+1727
-35
lines changed

Some content is hidden

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

56 files changed

+1727
-35
lines changed

Diff for: pythonforandroid/bootstrap.py

+14-7
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):

Diff for: pythonforandroid/bootstraps/common/build/build.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_bootstrap_name():
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)

Diff for: pythonforandroid/bootstraps/common/build/jni/application/src/Android.mk

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ SDL_PATH := ../../SDL
99
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1010

1111
# Add your application source files here...
12-
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
13-
start.c
12+
LOCAL_SRC_FILES := start.c
1413

1514
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)
1615

17-
LOCAL_SHARED_LIBRARIES := SDL2 python_shared
16+
LOCAL_SHARED_LIBRARIES := python_shared
1817

1918
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
2019

Diff for: pythonforandroid/bootstraps/common/build/jni/application/src/start.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
#include "bootstrap_name.h"
1818

19-
#ifndef BOOTSTRAP_USES_NO_SDL_HEADERS
19+
#ifdef BOOTSTRAP_NAME_SDL2
2020
#include "SDL.h"
2121
#include "SDL_opengles2.h"
2222
#endif
23+
24+
#ifdef BOOTSTRAP_NAME_SDL3
25+
#include "SDL3/SDL.h"
26+
#include "SDL3/SDL_main.h"
27+
#endif
28+
2329
#include "android/log.h"
2430

2531
#define ENTRYPOINT_MAXLEN 128

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

+4
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");
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11

2-
#define BOOTSTRAP_USES_NO_SDL_HEADERS
32

43
const char bootstrap_name[] = "qt";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
include $(CLEAR_VARS)
4+
5+
LOCAL_MODULE := main
6+
7+
SDL_PATH := ../../SDL
8+
9+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
10+
11+
# Add your application source files here...
12+
LOCAL_SRC_FILES := start.c
13+
14+
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)
15+
16+
LOCAL_SHARED_LIBRARIES := SDL2 python_shared
17+
18+
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
19+
20+
LOCAL_LDFLAGS += -L$(PYTHON_LINK_ROOT) $(APPLICATION_ADDITIONAL_LDFLAGS)
21+
22+
include $(BUILD_SHARED_LIBRARY)

Diff for: pythonforandroid/bootstraps/sdl3/__init__.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
conflicts = ['sdl2']
14+
15+
recipe_depends = list(
16+
set(Bootstrap.recipe_depends).union({'sdl3'})
17+
)
18+
19+
def assemble_distribution(self):
20+
info_main("# Creating Android project ({})".format(self.name))
21+
22+
rmdir(self.dist_dir)
23+
info("Copying SDL3/gradle build")
24+
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
25+
26+
# either the build use environment variable (ANDROID_HOME)
27+
# or the local.properties if exists
28+
with current_directory(self.dist_dir):
29+
with open('local.properties', 'w') as fileh:
30+
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
31+
32+
with current_directory(self.dist_dir):
33+
info("Copying Python distribution")
34+
35+
self.distribute_javaclasses(self.ctx.javaclass_dir,
36+
dest_dir=join("src", "main", "java"))
37+
38+
for arch in self.ctx.archs:
39+
python_bundle_dir = join(f'_python_bundle__{arch.arch}', '_python_bundle')
40+
ensure_dir(python_bundle_dir)
41+
42+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
43+
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
44+
join(self.dist_dir, python_bundle_dir), arch)
45+
if not self.ctx.with_debug_symbols:
46+
self.strip_libraries(arch)
47+
self.fry_eggs(site_packages_dir)
48+
49+
if 'sqlite3' not in self.ctx.recipe_build_order:
50+
with open('blacklist.txt', 'a') as fileh:
51+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
52+
53+
super().assemble_distribution()
54+
55+
56+
bootstrap = SDL3GradleBootstrap()

Diff for: pythonforandroid/bootstraps/sdl3/build/.gitignore

+14
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

Diff for: pythonforandroid/bootstraps/sdl3/build/blacklist.txt

+84
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
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
include $(CLEAR_VARS)
4+
5+
LOCAL_MODULE := main
6+
7+
SDL_PATH := ../../SDL
8+
9+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
10+
11+
# Add your application source files here...
12+
LOCAL_SRC_FILES := start.c
13+
14+
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)
15+
16+
LOCAL_SHARED_LIBRARIES := SDL3 python_shared
17+
18+
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
19+
20+
LOCAL_LDFLAGS += -L$(PYTHON_LINK_ROOT) $(APPLICATION_ADDITIONAL_LDFLAGS)
21+
22+
include $(BUILD_SHARED_LIBRARY)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
12+
include $(BUILD_SHARED_LIBRARY)
13+
$(call import-module,SDL)LOCAL_PATH := $(call my-dir)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
#define BOOTSTRAP_NAME_SDL3
3+
4+
const char bootstrap_name[] = "SDL3"; // capitalized for historic reasons
5+

Diff for: pythonforandroid/bootstraps/sdl3/build/src/main/assets/.gitkeep

Whitespace-only changes.

Diff for: pythonforandroid/bootstraps/sdl3/build/src/main/java/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)