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 (kivy#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

Lines changed: 17 additions & 8 deletions
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):
Lines changed: 49 additions & 0 deletions
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()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy