1010import sh
1111import subprocess
1212
13- from pythonforandroid .util import (ensure_dir , current_directory )
14- from pythonforandroid .logger import (info , warning , error , info_notify ,
15- Err_Fore , info_main , shprint )
13+ from pythonforandroid .util import (ensure_dir , current_directory , BuildInterruptingException )
14+ from pythonforandroid .logger import (info , warning , info_notify , info_main , shprint )
1615from pythonforandroid .archs import ArchARM , ArchARMv7_a , ArchAarch_64 , Archx86 , Archx86_64
1716from pythonforandroid .recipe import Recipe
1817
@@ -224,8 +223,7 @@ def prepare_build_environment(self,
224223 'maintain your own SDK download.' )
225224 sdk_dir = possible_dirs [0 ]
226225 if sdk_dir is None :
227- warning ('Android SDK dir was not specified, exiting.' )
228- exit (1 )
226+ raise BuildInterruptingException ('Android SDK dir was not specified, exiting.' )
229227 self .sdk_dir = realpath (sdk_dir )
230228
231229 # Check what Android API we're using
@@ -244,11 +242,11 @@ def prepare_build_environment(self,
244242 self .android_api = android_api
245243
246244 if self .android_api >= 21 and self .archs [0 ].arch == 'armeabi' :
247- error ( 'Asked to build for armeabi architecture with API '
248- '{}, but API 21 or greater does not support armeabi' . format (
249- self . android_api ))
250- error ( 'You probably want to build with --arch=armeabi-v7a instead' )
251- exit ( 1 )
245+ raise BuildInterruptingException (
246+ 'Asked to build for armeabi architecture with API '
247+ '{}, but API 21 or greater does not support armeabi' . format (
248+ self . android_api ),
249+ instructions = 'You probably want to build with --arch=armeabi-v7a instead' )
252250
253251 if exists (join (sdk_dir , 'tools' , 'bin' , 'avdmanager' )):
254252 avdmanager = sh .Command (join (sdk_dir , 'tools' , 'bin' , 'avdmanager' ))
@@ -257,9 +255,9 @@ def prepare_build_environment(self,
257255 android = sh .Command (join (sdk_dir , 'tools' , 'android' ))
258256 targets = android ('list' ).stdout .decode ('utf-8' ).split ('\n ' )
259257 else :
260- error ( 'Could not find `android` or `sdkmanager` binaries in '
261- ' Android SDK. Exiting.' )
262- exit ( 1 )
258+ raise BuildInterruptingException (
259+ 'Could not find `android` or `sdkmanager` binaries in Android SDK' ,
260+ instructions = 'Make sure the path to the Android SDK is correct' )
263261 apis = [s for s in targets if re .match (r'^ *API level: ' , s )]
264262 apis = [re .findall (r'[0-9]+' , s ) for s in apis ]
265263 apis = [int (s [0 ]) for s in apis if s ]
@@ -269,10 +267,9 @@ def prepare_build_environment(self,
269267 info (('Requested API target {} is available, '
270268 'continuing.' ).format (android_api ))
271269 else :
272- warning (('Requested API target {} is not available, install '
273- 'it with the SDK android tool.' ).format (android_api ))
274- warning ('Exiting.' )
275- exit (1 )
270+ raise BuildInterruptingException (
271+ ('Requested API target {} is not available, install '
272+ 'it with the SDK android tool.' ).format (android_api ))
276273
277274 # Find the Android NDK
278275 # Could also use ANDROID_NDK, but doesn't look like many tools use this
@@ -305,8 +302,7 @@ def prepare_build_environment(self,
305302 'maintain your own NDK download.' )
306303 ndk_dir = possible_dirs [0 ]
307304 if ndk_dir is None :
308- warning ('Android NDK dir was not specified, exiting.' )
309- exit (1 )
305+ raise BuildInterruptingException ('Android NDK dir was not specified' )
310306 self .ndk_dir = realpath (ndk_dir )
311307
312308 # Find the NDK version, and check it against what the NDK dir
@@ -367,11 +363,11 @@ def prepare_build_environment(self,
367363 self .ndk_api = ndk_api
368364
369365 if self .ndk_api > self .android_api :
370- error ( 'Target NDK API is {}, higher than the target Android API {}.' . format (
371- self . ndk_api , self . android_api ))
372- error ( 'The NDK API is a minimum supported API number and must be lower '
373- 'than the target Android API' )
374- exit ( 1 )
366+ raise BuildInterruptingException (
367+ 'Target NDK API is {}, higher than the target Android API {}.' . format (
368+ self . ndk_api , self . android_api ),
369+ instructions = ( 'The NDK API is a minimum supported API number and must be lower '
370+ 'than the target Android API' ) )
375371
376372 info ('Using {} NDK {}' .format (self .ndk .capitalize (), self .ndk_ver ))
377373
@@ -399,8 +395,7 @@ def prepare_build_environment(self,
399395 self .cython = cython
400396 break
401397 else :
402- error ('No cython binary found. Exiting.' )
403- exit (1 )
398+ raise BuildInterruptingException ('No cython binary found.' )
404399 if not self .cython :
405400 ok = False
406401 warning ("Missing requirement: cython is not installed" )
@@ -474,9 +469,8 @@ def prepare_build_environment(self,
474469 executable ))
475470
476471 if not ok :
477- error ('{}python-for-android cannot continue; aborting{}' .format (
478- Err_Fore .RED , Err_Fore .RESET ))
479- sys .exit (1 )
472+ raise BuildInterruptingException (
473+ 'python-for-android cannot continue due to the missing executables above' )
480474
481475 def __init__ (self ):
482476 super (Context , self ).__init__ ()
@@ -524,8 +518,7 @@ def set_archs(self, arch_names):
524518 new_archs .add (match )
525519 self .archs = list (new_archs )
526520 if not self .archs :
527- warning ('Asked to compile for no Archs, so failing.' )
528- exit (1 )
521+ raise BuildInterruptingException ('Asked to compile for no Archs, so failing.' )
529522 info ('Will compile for the following archs: {}' .format (
530523 ', ' .join ([arch .arch for arch in self .archs ])))
531524
0 commit comments