Skip to content

Commit 3a06bc4

Browse files
committed
Avoid some DRY issues + minor fixes + version bump
1 parent 2abaa31 commit 3a06bc4

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

+812
-714
lines changed

pythonforandroid/bootstrap.py

+4-2
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):
@@ -150,7 +152,7 @@ def get_bootstrap_dirs(self):
150152
return bootstrap_dirs
151153

152154
def _copy_in_final_files(self):
153-
if self.name in ["sdl2", "sdl3"]:
155+
if self.name in SDL_BOOTSTRAPS:
154156
# Get the paths for copying SDL's java source code:
155157
sdl_recipe = Recipe.get_recipe(self.name, self.ctx)
156158
sdl_build_dir = sdl_recipe.get_jni_dir()
@@ -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):
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()
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)