12
12
import shutil
13
13
import subprocess
14
14
from contextlib import suppress
15
+ from distutils .version import LooseVersion
15
16
16
17
from pythonforandroid .util import (
17
- current_directory , ensure_dir ,
18
+ build_platform , current_directory , ensure_dir ,
18
19
BuildInterruptingException ,
19
20
)
20
21
from pythonforandroid .logger import (info , warning , info_notify , info_main , shprint )
23
24
from pythonforandroid .recipe import CythonRecipe , Recipe
24
25
from pythonforandroid .recommendations import (
25
26
check_ndk_version , check_target_api , check_ndk_api ,
26
- RECOMMENDED_NDK_API , RECOMMENDED_TARGET_API )
27
+ read_ndk_version , RECOMMENDED_NDK_API , RECOMMENDED_TARGET_API )
27
28
28
29
29
30
def get_ndk_platform_dir (ndk_dir , ndk_api , arch ):
@@ -40,6 +41,21 @@ def get_ndk_platform_dir(ndk_dir, ndk_api, arch):
40
41
return ndk_platform , ndk_platform_dir_exists
41
42
42
43
44
+ def get_ndk_standalone (ndk_dir ):
45
+ return join (ndk_dir , 'toolchains' , 'llvm' , 'prebuilt' , build_platform )
46
+
47
+
48
+ def get_ndk_sysroot (ndk_dir ):
49
+ sysroot = join (get_ndk_standalone (ndk_dir ), 'sysroot' )
50
+ if not exists (sysroot ):
51
+ warning ("sysroot doesn't exist: {}" .format (sysroot ))
52
+ return sysroot
53
+
54
+
55
+ def get_ndk_lib_dir (sysroot , ndk_api , arch ):
56
+ return join (sysroot , 'usr' , 'lib' , arch .command_prefix , str (ndk_api ))
57
+
58
+
43
59
def get_toolchain_versions (ndk_dir , arch ):
44
60
toolchain_versions = []
45
61
toolchain_path_exists = True
@@ -115,6 +131,10 @@ class Context:
115
131
ccache = None # whether to use ccache
116
132
117
133
ndk_platform = None # the ndk platform directory
134
+ ndk_standalone = None # ndk >= r22 doesn't have platform/ & sysroot/
135
+ ndk_sysroot = None
136
+ ndk_lib_dir = None # usr/lib
137
+ ndk_include_dir = None # usr/include
118
138
119
139
bootstrap = None
120
140
bootstrap_build_dir = None
@@ -378,9 +398,19 @@ def prepare_build_environment(self,
378
398
# This would need to be changed if supporting multiarch APKs
379
399
arch = self .archs [0 ]
380
400
toolchain_prefix = arch .toolchain_prefix
381
- self .ndk_platform , ndk_platform_dir_exists = get_ndk_platform_dir (
382
- self .ndk_dir , self .ndk_api , arch )
383
- ok = ok and ndk_platform_dir_exists
401
+ ndk_version = read_ndk_version (ndk_dir )
402
+ if ndk_version is not None and ndk_version < LooseVersion ('22' ):
403
+ self .ndk_platform , ndk_platform_dir_exists = get_ndk_platform_dir (
404
+ self .ndk_dir , self .ndk_api , arch )
405
+ ok = ok and ndk_platform_dir_exists
406
+ self .ndk_sysroot = join (self .ndk_dir , 'sysroot' )
407
+ self .ndk_lib_dir = join (self .ndk_dir , 'usr' , 'lib' )
408
+ else :
409
+ self .ndk_standalone = get_ndk_standalone (self .ndk_dir )
410
+ self .ndk_sysroot = get_ndk_sysroot (self .ndk_dir )
411
+ self .ndk_lib_dir = get_ndk_lib_dir (self .ndk_sysroot , self .ndk_api , arch )
412
+ ok = ok and exists (self .ndk_sysroot )
413
+ self .ndk_include_dir = join (self .ndk_sysroot , 'usr' , 'include' )
384
414
385
415
py_platform = sys .platform
386
416
if py_platform in ['linux2' , 'linux3' ]:
@@ -878,7 +908,7 @@ def biglink(ctx, arch):
878
908
879
909
# Move to the directory containing crtstart_so.o and crtend_so.o
880
910
# This is necessary with newer NDKs? A gcc bug?
881
- with current_directory (join ( ctx .ndk_platform , 'usr' , 'lib' ) ):
911
+ with current_directory (ctx .ndk_lib_dir ):
882
912
do_biglink (
883
913
join (ctx .get_libs_dir (arch .arch ), 'libpymodules.so' ),
884
914
obj_dir .split (' ' ),
0 commit comments