Skip to content

Commit 1d22bdd

Browse files
committed
Did initial implementation of an ndk-api build target option
1 parent 4a78c13 commit 1d22bdd

File tree

8 files changed

+54
-13
lines changed

8 files changed

+54
-13
lines changed

pythonforandroid/archs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def get_env(self, with_flags_in_cc=True):
133133
env['PATH'] = environ['PATH']
134134

135135
env['ARCH'] = self.arch
136+
env['NDK_API'] = str(self.ctx.ndk_api)
136137

137138
if self.ctx.python_recipe and self.ctx.python_recipe.from_crystax:
138139
env['CRYSTAX_PYTHON_VERSION'] = self.ctx.python_recipe.version

pythonforandroid/bootstraps/sdl2/build/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
# APP_ABI := armeabi armeabi-v7a x86
77
APP_ABI := $(ARCH)
8-
APP_PLATFORM := android-21
8+
APP_PLATFORM := $(NDK_API)

pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1212
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
1313
start.c
1414

15-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS) -I$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/Include -I$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/android-build
15+
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)
1616

1717
LOCAL_SHARED_LIBRARIES := SDL2 python_shared
1818

19-
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS) -lpython3.7m
19+
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
2020

21-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS) -L$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/android-build
21+
LOCAL_LDFLAGS += -L$(PYTHON_LINK_ROOT) $(APPLICATION_ADDITIONAL_LDFLAGS)
2222

2323
include $(BUILD_SHARED_LIBRARY)
2424

pythonforandroid/build.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ def ndk_dir(self):
163163
def ndk_dir(self, value):
164164
self._ndk_dir = value
165165

166-
def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
167-
user_android_api, user_ndk_ver):
166+
def prepare_build_environment(self,
167+
user_sdk_dir,
168+
user_ndk_dir,
169+
user_android_api,
170+
user_ndk_ver,
171+
user_ndk_api):
168172
'''Checks that build dependencies exist and sets internal variables
169173
for the Android SDK etc.
170174
@@ -335,6 +339,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
335339
'set it with `--ndk-version=...`.')
336340
self.ndk_ver = ndk_ver
337341

342+
self.ndk_api = user_ndk_api
343+
338344
info('Using {} NDK {}'.format(self.ndk.capitalize(), self.ndk_ver))
339345

340346
virtualenv = None

pythonforandroid/recipe.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ def get_build_container_dir(self, arch):
277277
alternative or optional dependencies are being built.
278278
'''
279279
dir_name = self.get_dir_name()
280-
return join(self.ctx.build_dir, 'other_builds', dir_name, arch)
280+
return join(self.ctx.build_dir, 'other_builds',
281+
dir_name, '{}__ndk_target_{}'.format(arch, self.ctx.ndk_api))
281282

282283
def get_dir_name(self):
283284
choices = self.check_recipe_choices()
@@ -1084,7 +1085,6 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
10841085

10851086
return env
10861087

1087-
10881088
class TargetPythonRecipe(Recipe):
10891089
'''Class for target python recipes. Sets ctx.python_recipe to point to
10901090
itself, so as to know later what kind of Python was built or used.'''
@@ -1105,6 +1105,13 @@ def prebuild_arch(self, arch):
11051105
exit(1)
11061106
self.ctx.python_recipe = self
11071107

1108+
def include_root(self, arch):
1109+
'''The root directory from which to include headers.'''
1110+
raise NotImplementedError('Not implemented in TargetPythonRecipe')
1111+
1112+
def link_root(self):
1113+
raise NotImplementedError('Not implemented in TargetPythonRecipe')
1114+
11081115
# @property
11091116
# def ctx(self):
11101117
# return self._ctx

pythonforandroid/recipes/python3/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,13 @@ def build_arch(self, arch):
103103
# TODO: Look into passing the path to pyconfig.h in a
104104
# better way, although this is probably acceptable
105105
sh.cp('pyconfig.h', join(recipe_build_dir, 'Include'))
106+
107+
def include_root(self, arch_name):
108+
return join(self.get_build_dir(arch_name),
109+
'Include')
110+
111+
def link_root(self, arch_name):
112+
return join(self.get_build_dir(arch_name),
113+
'android-build')
106114

107115
recipe = Python3Recipe()

pythonforandroid/recipes/sdl2/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ class LibSDL2Recipe(BootstrapNDKRecipe):
1717

1818
def get_recipe_env(self, arch=None):
1919
env = super(LibSDL2Recipe, self).get_recipe_env(arch)
20+
2021
py2 = self.get_recipe('python2', arch.ctx)
2122
env['PYTHON2_NAME'] = py2.get_dir_name()
23+
py3 = self.get_recipe('python3', arch.ctx)
24+
25+
env['PYTHON_INCLUDE_ROOT'] = self.ctx.python_recipe.include_root(arch.arch)
26+
env['PYTHON_LINK_ROOT'] = self.ctx.python_recipe.link_root(arch.arch)
27+
2228
if 'python2' in self.ctx.recipe_build_order:
2329
env['EXTRA_LDLIBS'] = ' -lpython2.7'
2430

31+
if 'python3' in self.ctx.recipe_build_order:
32+
env['EXTRA_LDLIBS'] = ' -lpython3.7m' # TODO: don't hardcode the python version
33+
2534
env['APP_ALLOW_MISSING_DEPS'] = 'true'
2635
return env
2736

pythonforandroid/toolchain.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def wrapper_func(self, args):
137137
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
138138
user_ndk_dir=self.ndk_dir,
139139
user_android_api=self.android_api,
140-
user_ndk_ver=self.ndk_version)
140+
user_ndk_ver=self.ndk_version,
141+
user_ndk_api=self.ndk_api)
141142
dist = self._dist
142143
if dist.needs_build:
143144
info_notify('No dist exists that meets your requirements, '
@@ -257,8 +258,14 @@ def __init__(self):
257258
help=('The version of the Android NDK. This is optional: '
258259
'we try to work it out automatically from the ndk_dir.'))
259260
generic_parser.add_argument(
260-
'--symlink-java-src', '--symlink_java_src', action='store_true',
261-
dest='symlink_java_src', default=False,
261+
'--ndk-api', type=int, default=21,
262+
help=('The Android API level to compile against. This should be your '
263+
'*minimal supported* API, not normally the same as your --android-api.'))
264+
generic_parser.add_argument(
265+
'--symlink-java-src', '--symlink_java_src',
266+
action='store_true',
267+
dest='symlink_java_src',
268+
default=False,
262269
help=('If True, symlinks the java src folder during build and dist '
263270
'creation. This is useful for development only, it could also'
264271
' cause weird problems.'))
@@ -520,6 +527,7 @@ def add_parser(subparsers, *args, **kwargs):
520527
self.ndk_dir = args.ndk_dir
521528
self.android_api = args.android_api
522529
self.ndk_version = args.ndk_version
530+
self.ndk_api = args.ndk_api
523531
self.ctx.symlink_java_src = args.symlink_java_src
524532
self.ctx.java_build_tool = args.java_build_tool
525533

@@ -928,7 +936,8 @@ def sdk_tools(self, args):
928936
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
929937
user_ndk_dir=self.ndk_dir,
930938
user_android_api=self.android_api,
931-
user_ndk_ver=self.ndk_version)
939+
user_ndk_ver=self.ndk_version,
940+
user_ndk_api=self.ndk_api)
932941
android = sh.Command(join(ctx.sdk_dir, 'tools', args.tool))
933942
output = android(
934943
*args.unknown_args, _iter=True, _out_bufsize=1, _err_to_out=True)
@@ -955,7 +964,8 @@ def _adb(self, commands):
955964
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
956965
user_ndk_dir=self.ndk_dir,
957966
user_android_api=self.android_api,
958-
user_ndk_ver=self.ndk_version)
967+
user_ndk_ver=self.ndk_version,
968+
user_ndk_api=self.ndk_api)
959969
if platform in ('win32', 'cygwin'):
960970
adb = sh.Command(join(ctx.sdk_dir, 'platform-tools', 'adb.exe'))
961971
else:

0 commit comments

Comments
 (0)