33import json
44
55from pythonforandroid .logger import (info , info_notify , warning ,
6- Err_Style , Err_Fore )
6+ Err_Style , Err_Fore , error )
77from pythonforandroid .util import current_directory
88
99
@@ -21,6 +21,7 @@ class Distribution(object):
2121 needs_build = False # Whether the dist needs compiling
2222 url = None
2323 dist_dir = None # Where the dist dir ultimately is. Should not be None.
24+ ndk_api = None
2425
2526 archs = []
2627 '''The arch targets that the dist is built for.'''
@@ -42,6 +43,7 @@ def __repr__(self):
4243
4344 @classmethod
4445 def get_distribution (cls , ctx , name = None , recipes = [],
46+ ndk_api = None ,
4547 force_build = False ,
4648 extra_dist_dirs = [],
4749 require_perfect_match = False ):
@@ -76,13 +78,19 @@ def get_distribution(cls, ctx, name=None, recipes=[],
7678
7779 possible_dists = existing_dists
7880
81+ name_match_dist = None
82+
7983 # 0) Check if a dist with that name already exists
8084 if name is not None and name :
8185 possible_dists = [d for d in possible_dists if d .name == name ]
86+ if possible_dists :
87+ name_match_dist = possible_dists [0 ]
8288
8389 # 1) Check if any existing dists meet the requirements
8490 _possible_dists = []
8591 for dist in possible_dists :
92+ if ndk_api is not None and dist .ndk_api != ndk_api :
93+ continue
8694 for recipe in recipes :
8795 if recipe not in dist .recipes :
8896 break
@@ -97,10 +105,12 @@ def get_distribution(cls, ctx, name=None, recipes=[],
97105 else :
98106 info ('No existing dists meet the given requirements!' )
99107
100- # If any dist has perfect recipes, return it
108+ # If any dist has perfect recipes and ndk API , return it
101109 for dist in possible_dists :
102110 if force_build :
103111 continue
112+ if ndk_api is not None and dist .ndk_api != ndk_api :
113+ continue
104114 if (set (dist .recipes ) == set (recipes ) or
105115 (set (recipes ).issubset (set (dist .recipes )) and
106116 not require_perfect_match )):
@@ -110,34 +120,22 @@ def get_distribution(cls, ctx, name=None, recipes=[],
110120
111121 assert len (possible_dists ) < 2
112122
113- if not name and possible_dists :
114- info ('Asked for dist with name {} with recipes ({}), but a dist '
115- 'with this name already exists and has incompatible recipes '
116- '({})' .format (name , ', ' .join (recipes ),
117- ', ' .join (possible_dists [0 ].recipes )))
118- info ('No compatible dist found, so exiting.' )
123+ # If there was a name match but we didn't already choose it,
124+ # then the existing dist is incompatible with the requested
125+ # configuration and the build cannot continue
126+ if name_match_dist is not None :
127+ error ('Asked for dist with name {name} with recipes ({req_recipes}) and '
128+ 'NDK API {req_ndk_api}, but a dist '
129+ 'with this name already exists and has either incompatible recipes '
130+ '({dist_recipes}) or NDK API {dist_ndk_api}' .format (
131+ name = name ,
132+ req_ndk_api = ndk_api ,
133+ dist_ndk_api = name_match_dist .ndk_api ,
134+ req_recipes = ', ' .join (recipes ),
135+ dist_recipes = ', ' .join (name_match_dist .recipes )))
136+ error ('No compatible dist found, so exiting.' )
119137 exit (1 )
120138
121- # # 2) Check if any downloadable dists meet the requirements
122-
123- # online_dists = [('testsdl2', ['hostpython2', 'sdl2_image',
124- # 'sdl2_mixer', 'sdl2_ttf',
125- # 'python2', 'sdl2',
126- # 'pyjniussdl2', 'kivysdl2'],
127- # 'https://github.com/inclement/sdl2-example-dist/archive/master.zip'),
128- # ]
129- # _possible_dists = []
130- # for dist_name, dist_recipes, dist_url in online_dists:
131- # for recipe in recipes:
132- # if recipe not in dist_recipes:
133- # break
134- # else:
135- # dist = Distribution(ctx)
136- # dist.name = dist_name
137- # dist.url = dist_url
138- # _possible_dists.append(dist)
139- # # if _possible_dists
140-
141139 # If we got this far, we need to build a new dist
142140 dist = Distribution (ctx )
143141 dist .needs_build = True
@@ -152,6 +150,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
152150 dist .name = name
153151 dist .dist_dir = join (ctx .dist_dir , dist .name )
154152 dist .recipes = recipes
153+ dist .ndk_api = ctx .ndk_api
155154
156155 return dist
157156
@@ -179,6 +178,7 @@ def get_distributions(cls, ctx, extra_dist_dirs=[]):
179178 dist .recipes = dist_info ['recipes' ]
180179 if 'archs' in dist_info :
181180 dist .archs = dist_info ['archs' ]
181+ dist .ndk_api = dist_info ['ndk_api' ]
182182 dists .append (dist )
183183 return dists
184184
@@ -200,10 +200,12 @@ def save_info(self, dirn):
200200def pretty_log_dists (dists , log_func = info ):
201201 infos = []
202202 for dist in dists :
203- infos .append ('{Fore.GREEN}{Style.BRIGHT}{name}{Style.RESET_ALL}: '
203+ ndk_api = 'unknown' if dist .ndk_api is None else dist .ndk_api
204+ infos .append ('{Fore.GREEN}{Style.BRIGHT}{name}{Style.RESET_ALL}: min API {ndk_api}, '
204205 'includes recipes ({Fore.GREEN}{recipes}'
205206 '{Style.RESET_ALL}), built for archs ({Fore.BLUE}'
206207 '{archs}{Style.RESET_ALL})' .format (
208+ ndk_api = ndk_api ,
207209 name = dist .name , recipes = ', ' .join (dist .recipes ),
208210 archs = ', ' .join (dist .archs ) if dist .archs else 'UNKNOWN' ,
209211 Fore = Err_Fore , Style = Err_Style ))
0 commit comments