Skip to content

Commit dbf9815

Browse files
committed
Fixed dist selection to account for ndk_api
1 parent 82c1fc9 commit dbf9815

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

pythonforandroid/bootstrap.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ def prepare_build_dir(self):
102102
fileh.write('target=android-{}'.format(self.ctx.android_api))
103103

104104
def prepare_dist_dir(self, name):
105-
# self.dist_dir = self.get_dist_dir(name)
106105
ensure_dir(self.dist_dir)
107106

108107
def run_distribute(self):
109-
# TODO: Move this to Distribution.save_info
110108
self.distribution.save_info(self.dist_dir)
111109

112110
@classmethod

pythonforandroid/distribution.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44

55
from pythonforandroid.logger import (info, info_notify, warning,
6-
Err_Style, Err_Fore)
6+
Err_Style, Err_Fore, error)
77
from 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):
200200
def 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))

pythonforandroid/toolchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def dist_from_args(ctx, args):
155155
return Distribution.get_distribution(
156156
ctx,
157157
name=args.dist_name,
158+
ndk_api=args.ndk_api,
158159
recipes=split_argument_list(args.requirements),
159160
require_perfect_match=args.require_perfect_match)
160161

0 commit comments

Comments
 (0)