11
11
import sys
12
12
from sys import stdout , stderr , platform
13
13
from os .path import (join , dirname , realpath , exists , isdir , basename ,
14
- expanduser , splitext )
14
+ expanduser , splitext , split )
15
15
from os import listdir , unlink , makedirs , environ , chdir , getcwd , walk , uname
16
16
import os
17
17
import zipfile
@@ -444,6 +444,13 @@ def sync(self):
444
444
445
445
446
446
class 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
+
447
454
def __init__ (self , ctx ):
448
455
super (Arch , self ).__init__ ()
449
456
self .ctx = ctx
@@ -534,6 +541,9 @@ def get_env(self):
534
541
535
542
class ArchARM (Arch ):
536
543
arch = "armeabi"
544
+ toolchain_prefix = 'arm-linux-androideabi'
545
+ command_prefix = 'arm-linux-androideabi'
546
+ platform_dir = 'arch-arm'
537
547
538
548
class ArchARMv7_a (ArchARM ):
539
549
arch = 'armeabi-v7a'
@@ -546,6 +556,9 @@ def get_env(self):
546
556
547
557
class Archx86 (Arch ):
548
558
arch = 'x86'
559
+ toolchain_prefix = 'x86'
560
+ command_prefix = 'i686-linux-android'
561
+ platform_dir = 'arch-x86'
549
562
550
563
def get_env (self ):
551
564
env = super (Archx86 , self ).get_env ()
@@ -555,6 +568,9 @@ def get_env(self):
555
568
556
569
class Archx86_64 (Arch ):
557
570
arch = 'x86_64'
571
+ toolchain_prefix = 'x86'
572
+ command_prefix = 'x86_64-linux-android'
573
+ platform_dir = 'arch-x86'
558
574
559
575
def get_env (self ):
560
576
env = super (Archx86_64 , self ).get_env ()
@@ -976,24 +992,6 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
976
992
warning ('Android NDK version could not be found, exiting.' )
977
993
self .ndk_ver = ndk_ver
978
994
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
-
997
995
virtualenv = None
998
996
if virtualenv is None :
999
997
virtualenv = sh .which ('virtualenv2' )
@@ -1021,38 +1019,31 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
1021
1019
ok = False
1022
1020
warning ("Missing requirement: cython is not installed" )
1023
1021
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
+
1025
1036
py_platform = sys .platform
1026
1037
if py_platform in ['linux2' , 'linux3' ]:
1027
1038
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'
1040
1039
1041
1040
toolchain_versions = []
1042
1041
toolchain_path = join (self .ndk_dir , 'toolchains' )
1043
1042
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 ]
1056
1047
else :
1057
1048
warning ('Could not find toolchain subdirectory!' )
1058
1049
ok = False
@@ -1077,6 +1068,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
1077
1068
1078
1069
self .toolchain_prefix = toolchain_prefix
1079
1070
self .toolchain_version = toolchain_version
1071
+ # Modify the path so that sh finds modules appropriately
1080
1072
environ ['PATH' ] = (
1081
1073
'{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/'
1082
1074
'prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/'
0 commit comments