Skip to content

Commit 9b6436b

Browse files
committed
Did initial implementation of an ndk-api build target option
1 parent 7d5aa0b commit 9b6436b

File tree

8 files changed

+50
-11
lines changed

8 files changed

+50
-11
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
@@ -158,8 +158,12 @@ def ndk_dir(self):
158158
def ndk_dir(self, value):
159159
self._ndk_dir = value
160160

161-
def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
162-
user_android_api, user_ndk_ver):
161+
def prepare_build_environment(self,
162+
user_sdk_dir,
163+
user_ndk_dir,
164+
user_android_api,
165+
user_ndk_ver,
166+
user_ndk_api):
163167
'''Checks that build dependencies exist and sets internal variables
164168
for the Android SDK etc.
165169
@@ -328,6 +332,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
328332
'set it with `--ndk-version=...`.')
329333
self.ndk_ver = ndk_ver
330334

335+
self.ndk_api = user_ndk_api
336+
331337
info('Using {} NDK {}'.format(self.ndk.capitalize(), self.ndk_ver))
332338

333339
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()
@@ -1081,7 +1082,6 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
10811082

10821083
return env
10831084

1084-
10851085
class TargetPythonRecipe(Recipe):
10861086
'''Class for target python recipes. Sets ctx.python_recipe to point to
10871087
itself, so as to know later what kind of Python was built or used.'''
@@ -1102,6 +1102,13 @@ def prebuild_arch(self, arch):
11021102
exit(1)
11031103
self.ctx.python_recipe = self
11041104

1105+
def include_root(self, arch):
1106+
'''The root directory from which to include headers.'''
1107+
raise NotImplementedError('Not implemented in TargetPythonRecipe')
1108+
1109+
def link_root(self):
1110+
raise NotImplementedError('Not implemented in TargetPythonRecipe')
1111+
11051112
# @property
11061113
# def ctx(self):
11071114
# 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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def wrapper_func(self, args):
139139
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
140140
user_ndk_dir=self.ndk_dir,
141141
user_android_api=self.android_api,
142-
user_ndk_ver=self.ndk_version)
142+
user_ndk_ver=self.ndk_version,
143+
user_ndk_api=self.ndk_api)
143144
dist = self._dist
144145
if dist.needs_build:
145146
info_notify('No dist exists that meets your requirements, '
@@ -260,6 +261,10 @@ def __init__(self):
260261
'--ndk-version', '--ndk_version', dest='ndk_version', default='',
261262
help=('The version of the Android NDK. This is optional, '
262263
'we try to work it out automatically from the ndk_dir.'))
264+
generic_parser.add_argument(
265+
'--ndk-api', type=int, default=21,
266+
help=('The Android API level to compile against. This should be your '
267+
'*minimal supported* API, not normally the same as your --android-api.'))
263268
generic_parser.add_argument(
264269
'--symlink-java-src', '--symlink_java_src',
265270
action='store_true',
@@ -500,6 +505,7 @@ def add_parser(subparsers, *args, **kwargs):
500505
self.ndk_dir = args.ndk_dir
501506
self.android_api = args.android_api
502507
self.ndk_version = args.ndk_version
508+
self.ndk_api = args.ndk_api
503509
self.ctx.symlink_java_src = args.symlink_java_src
504510
self.ctx.java_build_tool = args.java_build_tool
505511

@@ -903,7 +909,8 @@ def sdk_tools(self, args):
903909
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
904910
user_ndk_dir=self.ndk_dir,
905911
user_android_api=self.android_api,
906-
user_ndk_ver=self.ndk_version)
912+
user_ndk_ver=self.ndk_version,
913+
user_ndk_api=self.ndk_api)
907914
android = sh.Command(join(ctx.sdk_dir, 'tools', args.tool))
908915
output = android(
909916
*args.unknown_args, _iter=True, _out_bufsize=1, _err_to_out=True)
@@ -930,7 +937,8 @@ def _adb(self, commands):
930937
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
931938
user_ndk_dir=self.ndk_dir,
932939
user_android_api=self.android_api,
933-
user_ndk_ver=self.ndk_version)
940+
user_ndk_ver=self.ndk_version,
941+
user_ndk_api=self.ndk_api)
934942
if platform in ('win32', 'cygwin'):
935943
adb = sh.Command(join(ctx.sdk_dir, 'platform-tools', 'adb.exe'))
936944
else:

0 commit comments

Comments
 (0)