Skip to content

Commit 58d148b

Browse files
authored
Add SDL3 bootstrap (alongside SDL3, SDL3_ttf, SDL3_mixer, SDL3_image recipes) for Kivy 3.0.0 (#3125)
* Add SDL3 bootstrap * Avoid some DRY issues + minor fixes + version bump
1 parent fbd5255 commit 58d148b

File tree

61 files changed

+1177
-95
lines changed

Some content is hidden

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

61 files changed

+1177
-95
lines changed

pythonforandroid/bootstrap.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
rmdir, move)
1515
from pythonforandroid.recipe import Recipe
1616

17+
SDL_BOOTSTRAPS = ("sdl2", "sdl3")
18+
1719

1820
def copy_files(src_root, dest_root, override=True, symlink=False):
1921
for root, dirnames, filenames in walk(src_root):
@@ -39,7 +41,7 @@ def copy_files(src_root, dest_root, override=True, symlink=False):
3941

4042

4143
default_recipe_priorities = [
42-
"webview", "sdl2", "service_only" # last is highest
44+
"webview", "sdl2", "sdl3", "service_only" # last is highest
4345
]
4446
# ^^ NOTE: these are just the default priorities if no special rules
4547
# apply (which you can find in the code below), so basically if no
@@ -150,18 +152,18 @@ def get_bootstrap_dirs(self):
150152
return bootstrap_dirs
151153

152154
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",
155+
if self.name in SDL_BOOTSTRAPS:
156+
# Get the paths for copying SDL's java source code:
157+
sdl_recipe = Recipe.get_recipe(self.name, self.ctx)
158+
sdl_build_dir = sdl_recipe.get_jni_dir()
159+
src_dir = join(sdl_build_dir, "SDL", "android-project",
158160
"app", "src", "main", "java",
159161
"org", "libsdl", "app")
160162
target_dir = join(self.dist_dir, 'src', 'main', 'java', 'org',
161163
'libsdl', 'app')
162164

163165
# Do actual copying:
164-
info('Copying in SDL2 .java files from: ' + str(src_dir))
166+
info('Copying in SDL .java files from: ' + str(src_dir))
165167
if not os.path.exists(target_dir):
166168
os.makedirs(target_dir)
167169
copy_files(src_dir, target_dir, override=True)
@@ -193,7 +195,7 @@ def assemble_distribution(self):
193195
@classmethod
194196
def all_bootstraps(cls):
195197
'''Find all the available bootstraps and return them.'''
196-
forbidden_dirs = ('__pycache__', 'common')
198+
forbidden_dirs = ('__pycache__', 'common', '_sdl_common')
197199
bootstraps_dir = join(dirname(__file__), 'bootstraps')
198200
result = set()
199201
for name in listdir(bootstraps_dir):
@@ -272,6 +274,13 @@ def have_dependency_in_recipes(dep):
272274
info('Using sdl2 bootstrap since it is in dependencies')
273275
return cls.get_bootstrap("sdl2", ctx)
274276

277+
# Special rule: return SDL3 bootstrap if there's an sdl3 dep:
278+
if (have_dependency_in_recipes("sdl3") and
279+
"sdl3" in [b.name for b in acceptable_bootstraps]
280+
):
281+
info('Using sdl3 bootstrap since it is in dependencies')
282+
return cls.get_bootstrap("sdl3", ctx)
283+
275284
# Special rule: return "webview" if we depend on common web recipe:
276285
for possible_web_dep in known_web_packages:
277286
if have_dependency_in_recipes(possible_web_dep):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 SDLGradleBootstrap(Bootstrap):
11+
name = "_sdl_common"
12+
13+
recipe_depends = []
14+
15+
def assemble_distribution(self):
16+
info_main("# Creating Android project ({})".format(self.name))
17+
18+
rmdir(self.dist_dir)
19+
info("Copying SDL/gradle build")
20+
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
21+
22+
# either the build use environment variable (ANDROID_HOME)
23+
# or the local.properties if exists
24+
with current_directory(self.dist_dir):
25+
with open('local.properties', 'w') as fileh:
26+
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
27+
28+
with current_directory(self.dist_dir):
29+
info("Copying Python distribution")
30+
31+
self.distribute_javaclasses(self.ctx.javaclass_dir,
32+
dest_dir=join("src", "main", "java"))
33+
34+
for arch in self.ctx.archs:
35+
python_bundle_dir = join(f'_python_bundle__{arch.arch}', '_python_bundle')
36+
ensure_dir(python_bundle_dir)
37+
38+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
39+
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
40+
join(self.dist_dir, python_bundle_dir), arch)
41+
if not self.ctx.with_debug_symbols:
42+
self.strip_libraries(arch)
43+
self.fry_eggs(site_packages_dir)
44+
45+
if 'sqlite3' not in self.ctx.recipe_build_order:
46+
with open('blacklist.txt', 'a') as fileh:
47+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
48+
49+
super().assemble_distribution()

pythonforandroid/bootstraps/_sdl_common/build/src/main/res/mipmap/.gitkeep

Whitespace-only changes.

pythonforandroid/bootstraps/common/build/build.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from fnmatch import fnmatch
2121
import jinja2
2222

23+
from pythonforandroid.bootstrap import SDL_BOOTSTRAPS
2324
from pythonforandroid.util import rmdir, ensure_dir, max_build_tool_version
2425

2526

@@ -83,7 +84,7 @@ def get_bootstrap_name():
8384
if PYTHON is not None and not exists(PYTHON):
8485
PYTHON = None
8586

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

8990
environment = jinja2.Environment(loader=jinja2.FileSystemLoader(
@@ -220,6 +221,10 @@ def compile_py_file(python_file, optimize_python=True):
220221
return ".".join([os.path.splitext(python_file)[0], "pyc"])
221222

222223

224+
def is_sdl_bootstrap():
225+
return get_bootstrap_name() in SDL_BOOTSTRAPS
226+
227+
223228
def make_package(args):
224229
# If no launcher is specified, require a main.py/main.pyc:
225230
if (get_bootstrap_name() != "sdl" or args.launcher is None) and \
@@ -541,7 +546,7 @@ def make_package(args):
541546
"debug": "debug" in args.build_mode,
542547
"native_services": args.native_services
543548
}
544-
if get_bootstrap_name() == "sdl2":
549+
if is_sdl_bootstrap():
545550
render_args["url_scheme"] = url_scheme
546551

547552
render(
@@ -596,7 +601,7 @@ def make_package(args):
596601
"args": args,
597602
"private_version": hashlib.sha1(private_version.encode()).hexdigest()
598603
}
599-
if get_bootstrap_name() == "sdl2":
604+
if is_sdl_bootstrap():
600605
render_args["url_scheme"] = url_scheme
601606
render(
602607
'strings.tmpl.xml',
@@ -769,7 +774,7 @@ def create_argument_parser():
769774
ap.add_argument('--private', dest='private',
770775
help='the directory with the app source code files' +
771776
' (containing your main.py entrypoint)',
772-
required=(get_bootstrap_name() != "sdl2"))
777+
required=(not is_sdl_bootstrap()))
773778
ap.add_argument('--package', dest='package',
774779
help=('The name of the java package the project will be'
775780
' packaged under.'),
@@ -787,7 +792,7 @@ def create_argument_parser():
787792
'same number of groups of numbers as previous '
788793
'versions.'),
789794
required=True)
790-
if get_bootstrap_name() == "sdl2":
795+
if is_sdl_bootstrap():
791796
ap.add_argument('--launcher', dest='launcher', action='store_true',
792797
help=('Provide this argument to build a multi-app '
793798
'launcher, rather than a single app.'))
@@ -1044,7 +1049,7 @@ def _read_configuration():
10441049
args.orientation, args.manifest_orientation
10451050
)
10461051

1047-
if get_bootstrap_name() == "sdl2":
1052+
if is_sdl_bootstrap():
10481053
args.sdl_orientation_hint = get_sdl_orientation_hint(args.orientation)
10491054

10501055
if args.res_xmls and isinstance(args.res_xmls[0], list):
@@ -1073,10 +1078,9 @@ def _read_configuration():
10731078
if x.strip() and not x.strip().startswith('#')]
10741079
WHITELIST_PATTERNS += patterns
10751080

1076-
if args.private is None and \
1077-
get_bootstrap_name() == 'sdl2' and args.launcher is None:
1081+
if args.private is None and is_sdl_bootstrap() and args.launcher is None:
10781082
print('Need --private directory or ' +
1079-
'--launcher (SDL2 bootstrap only)' +
1083+
'--launcher (SDL2/SDL3 bootstrap only)' +
10801084
'to have something to launch inside the .apk!')
10811085
sys.exit(1)
10821086
make_package(args)

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

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

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";
+4-46
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
1-
from os.path import join
1+
from pythonforandroid.bootstraps._sdl_common import SDLGradleBootstrap
22

3-
import sh
43

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 SDL2GradleBootstrap(Bootstrap):
11-
name = 'sdl2'
4+
class SDL2GradleBootstrap(SDLGradleBootstrap):
5+
name = "sdl2"
126

137
recipe_depends = list(
14-
set(Bootstrap.recipe_depends).union({'sdl2'})
8+
set(SDLGradleBootstrap.recipe_depends).union({"sdl2"})
159
)
1610

17-
def assemble_distribution(self):
18-
info_main("# Creating Android project ({})".format(self.name))
19-
20-
rmdir(self.dist_dir)
21-
info("Copying SDL2/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-
5311

5412
bootstrap = SDL2GradleBootstrap()
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pythonforandroid.bootstraps._sdl_common import SDLGradleBootstrap
2+
3+
4+
class SDL3GradleBootstrap(SDLGradleBootstrap):
5+
name = "sdl3"
6+
7+
recipe_depends = list(
8+
set(SDLGradleBootstrap.recipe_depends).union({"sdl3"})
9+
)
10+
11+
12+
bootstrap = SDL3GradleBootstrap()
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+

0 commit comments

Comments
 (0)