Skip to content

Commit

Permalink
Did initial implementation of an ndk-api build target option
Browse files Browse the repository at this point in the history
  • Loading branch information
inclement committed Oct 17, 2018
1 parent 7d5aa0b commit 9b6436b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 11 deletions.
1 change: 1 addition & 0 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def get_env(self, with_flags_in_cc=True):
env['PATH'] = environ['PATH']

env['ARCH'] = self.arch
env['NDK_API'] = str(self.ctx.ndk_api)

if self.ctx.python_recipe and self.ctx.python_recipe.from_crystax:
env['CRYSTAX_PYTHON_VERSION'] = self.ctx.python_recipe.version
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/bootstraps/sdl2/build/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

# APP_ABI := armeabi armeabi-v7a x86
APP_ABI := $(ARCH)
APP_PLATFORM := android-21
APP_PLATFORM := $(NDK_API)
6 changes: 3 additions & 3 deletions pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
start.c

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
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)

LOCAL_SHARED_LIBRARIES := SDL2 python_shared

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

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
LOCAL_LDFLAGS += -L$(PYTHON_LINK_ROOT) $(APPLICATION_ADDITIONAL_LDFLAGS)

include $(BUILD_SHARED_LIBRARY)

Expand Down
10 changes: 8 additions & 2 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ def ndk_dir(self):
def ndk_dir(self, value):
self._ndk_dir = value

def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
user_android_api, user_ndk_ver):
def prepare_build_environment(self,
user_sdk_dir,
user_ndk_dir,
user_android_api,
user_ndk_ver,
user_ndk_api):
'''Checks that build dependencies exist and sets internal variables
for the Android SDK etc.
Expand Down Expand Up @@ -328,6 +332,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
'set it with `--ndk-version=...`.')
self.ndk_ver = ndk_ver

self.ndk_api = user_ndk_api

info('Using {} NDK {}'.format(self.ndk.capitalize(), self.ndk_ver))

virtualenv = None
Expand Down
11 changes: 9 additions & 2 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ def get_build_container_dir(self, arch):
alternative or optional dependencies are being built.
'''
dir_name = self.get_dir_name()
return join(self.ctx.build_dir, 'other_builds', dir_name, arch)
return join(self.ctx.build_dir, 'other_builds',
dir_name, '{}__ndk_target_{}'.format(arch, self.ctx.ndk_api))

def get_dir_name(self):
choices = self.check_recipe_choices()
Expand Down Expand Up @@ -1081,7 +1082,6 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):

return env


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

def include_root(self, arch):
'''The root directory from which to include headers.'''
raise NotImplementedError('Not implemented in TargetPythonRecipe')

def link_root(self):
raise NotImplementedError('Not implemented in TargetPythonRecipe')

# @property
# def ctx(self):
# return self._ctx
Expand Down
8 changes: 8 additions & 0 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,13 @@ def build_arch(self, arch):
# TODO: Look into passing the path to pyconfig.h in a
# better way, although this is probably acceptable
sh.cp('pyconfig.h', join(recipe_build_dir, 'Include'))

def include_root(self, arch_name):
return join(self.get_build_dir(arch_name),
'Include')

def link_root(self, arch_name):
return join(self.get_build_dir(arch_name),
'android-build')

recipe = Python3Recipe()
9 changes: 9 additions & 0 deletions pythonforandroid/recipes/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ class LibSDL2Recipe(BootstrapNDKRecipe):

def get_recipe_env(self, arch=None):
env = super(LibSDL2Recipe, self).get_recipe_env(arch)

py2 = self.get_recipe('python2', arch.ctx)
env['PYTHON2_NAME'] = py2.get_dir_name()
py3 = self.get_recipe('python3', arch.ctx)

env['PYTHON_INCLUDE_ROOT'] = self.ctx.python_recipe.include_root(arch.arch)
env['PYTHON_LINK_ROOT'] = self.ctx.python_recipe.link_root(arch.arch)

if 'python2' in self.ctx.recipe_build_order:
env['EXTRA_LDLIBS'] = ' -lpython2.7'

if 'python3' in self.ctx.recipe_build_order:
env['EXTRA_LDLIBS'] = ' -lpython3.7m' # TODO: don't hardcode the python version

env['APP_ALLOW_MISSING_DEPS'] = 'true'
return env

Expand Down
14 changes: 11 additions & 3 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def wrapper_func(self, args):
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
user_ndk_dir=self.ndk_dir,
user_android_api=self.android_api,
user_ndk_ver=self.ndk_version)
user_ndk_ver=self.ndk_version,
user_ndk_api=self.ndk_api)
dist = self._dist
if dist.needs_build:
info_notify('No dist exists that meets your requirements, '
Expand Down Expand Up @@ -260,6 +261,10 @@ def __init__(self):
'--ndk-version', '--ndk_version', dest='ndk_version', default='',
help=('The version of the Android NDK. This is optional, '
'we try to work it out automatically from the ndk_dir.'))
generic_parser.add_argument(
'--ndk-api', type=int, default=21,
help=('The Android API level to compile against. This should be your '
'*minimal supported* API, not normally the same as your --android-api.'))
generic_parser.add_argument(
'--symlink-java-src', '--symlink_java_src',
action='store_true',
Expand Down Expand Up @@ -500,6 +505,7 @@ def add_parser(subparsers, *args, **kwargs):
self.ndk_dir = args.ndk_dir
self.android_api = args.android_api
self.ndk_version = args.ndk_version
self.ndk_api = args.ndk_api
self.ctx.symlink_java_src = args.symlink_java_src
self.ctx.java_build_tool = args.java_build_tool

Expand Down Expand Up @@ -903,7 +909,8 @@ def sdk_tools(self, args):
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
user_ndk_dir=self.ndk_dir,
user_android_api=self.android_api,
user_ndk_ver=self.ndk_version)
user_ndk_ver=self.ndk_version,
user_ndk_api=self.ndk_api)
android = sh.Command(join(ctx.sdk_dir, 'tools', args.tool))
output = android(
*args.unknown_args, _iter=True, _out_bufsize=1, _err_to_out=True)
Expand All @@ -930,7 +937,8 @@ def _adb(self, commands):
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
user_ndk_dir=self.ndk_dir,
user_android_api=self.android_api,
user_ndk_ver=self.ndk_version)
user_ndk_ver=self.ndk_version,
user_ndk_api=self.ndk_api)
if platform in ('win32', 'cygwin'):
adb = sh.Command(join(ctx.sdk_dir, 'platform-tools', 'adb.exe'))
else:
Expand Down

0 comments on commit 9b6436b

Please sign in to comment.