1111import sys
1212from sys import stdout , stderr , platform
1313from os .path import (join , dirname , realpath , exists , isdir , basename ,
14- expanduser , splitext )
14+ expanduser , splitext , split )
1515from os import listdir , unlink , makedirs , environ , chdir , getcwd , walk , uname
1616import os
1717import zipfile
@@ -444,6 +444,13 @@ def sync(self):
444444
445445
446446class Arch (object ):
447+
448+ toolchain_prefix = None
449+ '''The prefix for the toolchain dir in the NDK.'''
450+
451+ command_prefix = None
452+ '''The prefix for NDK commands such as gcc.'''
453+
447454 def __init__ (self , ctx ):
448455 super (Arch , self ).__init__ ()
449456 self .ctx = ctx
@@ -534,6 +541,9 @@ def get_env(self):
534541
535542class ArchARM (Arch ):
536543 arch = "armeabi"
544+ toolchain_prefix = 'arm-linux-androideabi'
545+ command_prefix = 'arm-linux-androideabi'
546+ platform_dir = 'arch-arm'
537547
538548class ArchARMv7_a (ArchARM ):
539549 arch = 'armeabi-v7a'
@@ -546,6 +556,9 @@ def get_env(self):
546556
547557class Archx86 (Arch ):
548558 arch = 'x86'
559+ toolchain_prefix = 'x86'
560+ command_prefix = 'i686-linux-android'
561+ platform_dir = 'arch-x86'
549562
550563 def get_env (self ):
551564 env = super (Archx86 , self ).get_env ()
@@ -555,6 +568,9 @@ def get_env(self):
555568
556569class Archx86_64 (Arch ):
557570 arch = 'x86_64'
571+ toolchain_prefix = 'x86'
572+ command_prefix = 'x86_64-linux-android'
573+ platform_dir = 'arch-x86'
558574
559575 def get_env (self ):
560576 env = super (Archx86_64 , self ).get_env ()
@@ -976,24 +992,6 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
976992 warning ('Android NDK version could not be found, exiting.' )
977993 self .ndk_ver = ndk_ver
978994
979- # AND: need to change if supporting multiple archs at once
980- arch = self .archs [0 ]
981- if arch .arch [:3 ] == 'arm' :
982- compiler_dir = 'arch-arm'
983- elif arch .arch == 'x86' :
984- compiler_dir = 'arch-x86'
985- else :
986- warning ('Don\' t know what NDK compiler dir to look in. Exiting.' )
987- exit (1 )
988- self .ndk_platform = join (
989- self .ndk_dir ,
990- 'platforms' ,
991- 'android-{}' .format (self .android_api ),
992- compiler_dir )
993- if not exists (self .ndk_platform ):
994- warning ('ndk_platform doesn\' t exist' )
995- ok = False
996-
997995 virtualenv = None
998996 if virtualenv is None :
999997 virtualenv = sh .which ('virtualenv2' )
@@ -1021,38 +1019,31 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
10211019 ok = False
10221020 warning ("Missing requirement: cython is not installed" )
10231021
1024- # Modify the path so that sh finds modules appropriately
1022+ # AND: need to change if supporting multiple archs at once
1023+ arch = self .archs [0 ]
1024+ platform_dir = arch .platform_dir
1025+ toolchain_prefix = arch .toolchain_prefix
1026+ command_prefix = arch .command_prefix
1027+ self .ndk_platform = join (
1028+ self .ndk_dir ,
1029+ 'platforms' ,
1030+ 'android-{}' .format (self .android_api ),
1031+ platform_dir )
1032+ if not exists (self .ndk_platform ):
1033+ warning ('ndk_platform doesn\' t exist' )
1034+ ok = False
1035+
10251036 py_platform = sys .platform
10261037 if py_platform in ['linux2' , 'linux3' ]:
10271038 py_platform = 'linux'
1028- if arch .arch [:3 ] == 'arm' :
1029- if self .ndk_ver == 'r5b' :
1030- toolchain_prefix = 'arm-eabi'
1031- elif self .ndk_ver [:2 ] in ('r7' , 'r8' , 'r9' ):
1032- toolchain_prefix = 'arm-linux-androideabi'
1033- elif self .ndk_ver [:3 ] == 'r10' :
1034- toolchain_prefix = 'arm-linux-androideabi'
1035- else :
1036- warning ('Error: NDK not supported by these tools?' )
1037- exit (1 )
1038- else :
1039- toolchain_prefix = 'x86'
10401039
10411040 toolchain_versions = []
10421041 toolchain_path = join (self .ndk_dir , 'toolchains' )
10431042 if os .path .isdir (toolchain_path ):
1044- toolchain_contents = os .listdir (toolchain_path )
1045- for toolchain_content in toolchain_contents :
1046- if toolchain_content .startswith (toolchain_prefix ) and \
1047- os .path .isdir (
1048- os .path .join (toolchain_path , toolchain_content )):
1049- toolchain_version = toolchain_content [
1050- len (toolchain_prefix )+ 1 :]
1051- # AND: This is terrible!
1052- if toolchain_version [0 ] in map (str , range (10 )) and 'clang' not in toolchain_version and toolchain_version [:2 ] != '64' :
1053- debug ('Found toolchain version: {}' .format (
1054- toolchain_version ))
1055- toolchain_versions .append (toolchain_version )
1043+ toolchain_contents = glob .glob ('{}/{}-*' .format (toolchain_path ,
1044+ toolchain_prefix ))
1045+ toolchain_versions = [split (path )[- 1 ][len (toolchain_prefix ) + 1 :]
1046+ for path in toolchain_contents ]
10561047 else :
10571048 warning ('Could not find toolchain subdirectory!' )
10581049 ok = False
@@ -1077,6 +1068,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
10771068
10781069 self .toolchain_prefix = toolchain_prefix
10791070 self .toolchain_version = toolchain_version
1071+ # Modify the path so that sh finds modules appropriately
10801072 environ ['PATH' ] = (
10811073 '{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/'
10821074 'prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/'
0 commit comments