Skip to content

Commit 1e7d0d4

Browse files
committed
[dist] Check android_api and archs when reusing dist
So in case that we detect a mismatched value, we will not use that dist. Note: also removed unneeded duplicated check
1 parent 46a05ca commit 1e7d0d4

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

pythonforandroid/distribution.py

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def get_distribution(cls, ctx, name=None, recipes=[],
8383

8484
name_match_dist = None
8585

86+
req_archs = [arch.arch for arch in ctx.archs]
87+
8688
# 0) Check if a dist with that name already exists
8789
if name is not None and name:
8890
possible_dists = [d for d in possible_dists if d.name == name]
@@ -92,7 +94,14 @@ def get_distribution(cls, ctx, name=None, recipes=[],
9294
# 1) Check if any existing dists meet the requirements
9395
_possible_dists = []
9496
for dist in possible_dists:
95-
if (dist.ndk_api != ctx.ndk_api) or dist.ndk_api is None:
97+
if any(
98+
[
99+
dist.ndk_api != ctx.ndk_api,
100+
dist.android_api != ctx.android_api,
101+
set(dist.archs) != set(req_archs),
102+
dist.ndk_api is None,
103+
]
104+
):
96105
continue
97106
for recipe in recipes:
98107
if recipe not in dist.recipes:
@@ -108,12 +117,11 @@ def get_distribution(cls, ctx, name=None, recipes=[],
108117
else:
109118
info('No existing dists meet the given requirements!')
110119

111-
# If any dist has perfect recipes and ndk API, return it
120+
# 2) Of the possible dists we will select the one which contains the
121+
# requested recipes, unless we used the kwarg `force_build`
112122
for dist in possible_dists:
113123
if force_build:
114124
continue
115-
if ctx.ndk_api is not None and dist.ndk_api != ctx.ndk_api:
116-
continue
117125
if (set(dist.recipes) == set(recipes) or
118126
(set(recipes).issubset(set(dist.recipes)) and
119127
not require_perfect_match)):
@@ -123,22 +131,35 @@ def get_distribution(cls, ctx, name=None, recipes=[],
123131

124132
assert len(possible_dists) < 2
125133

126-
# If there was a name match but we didn't already choose it,
134+
# 3) If there was a name match but we didn't already choose it,
127135
# then the existing dist is incompatible with the requested
128136
# configuration and the build cannot continue
129137
if name_match_dist is not None and not allow_replace_dist:
130138
raise BuildInterruptingException(
131-
'Asked for dist with name {name} with recipes ({req_recipes}) and '
132-
'NDK API {req_ndk_api}, but a dist '
133-
'with this name already exists and has either incompatible recipes '
134-
'({dist_recipes}) or NDK API {dist_ndk_api}'.format(
139+
'\n\tAsked for dist with name {name} and:'
140+
'\n\t-> recipes: ({req_recipes})'
141+
'\n\t-> NDK api: ({req_ndk_api})'
142+
'\n\t-> android api ({req_android_api})'
143+
'\n\t-> archs ({req_archs})'
144+
'\n...but a dist with this name already exists and has either '
145+
'incompatible:'
146+
'\n\t-> recipes: ({dist_recipes})'
147+
'\n\t-> NDK api: ({dist_ndk_api})'
148+
'\n\t-> android api ({dist_android_api})'
149+
'\n\t-> archs ({dist_archs})'.format(
135150
name=name,
151+
req_recipes=', '.join(recipes),
136152
req_ndk_api=ctx.ndk_api,
153+
req_android_api=ctx.android_api,
154+
req_archs=', '.join(req_archs),
155+
dist_recipes=', '.join(name_match_dist.recipes),
137156
dist_ndk_api=name_match_dist.ndk_api,
138-
req_recipes=', '.join(recipes),
139-
dist_recipes=', '.join(name_match_dist.recipes)))
157+
dist_android_api=name_match_dist.android_api,
158+
dist_archs=', '.join(name_match_dist.archs),
159+
)
160+
)
140161

141-
# If we got this far, we need to build a new dist
162+
# 4) If we got this far, we need to build a new dist
142163
dist = Distribution(ctx)
143164
dist.needs_build = True
144165

@@ -152,7 +173,9 @@ def get_distribution(cls, ctx, name=None, recipes=[],
152173
dist.name = name
153174
dist.dist_dir = join(ctx.dist_dir, dist.name)
154175
dist.recipes = recipes
176+
dist.archs = req_archs
155177
dist.ndk_api = ctx.ndk_api
178+
dist.android_api = ctx.android_api
156179

157180
return dist
158181

@@ -184,20 +207,18 @@ def get_distributions(cls, ctx, extra_dist_dirs=[]):
184207
dist.dist_dir = folder
185208
dist.needs_build = False
186209
dist.recipes = dist_info['recipes']
187-
if 'archs' in dist_info:
188-
dist.archs = dist_info['archs']
189-
if 'ndk_api' in dist_info:
190-
dist.ndk_api = dist_info['ndk_api']
191-
else:
192-
dist.ndk_api = None
193-
warning(
194-
"Distribution {distname}: ({distdir}) has been "
195-
"built with an unknown api target, ignoring it, "
196-
"you might want to delete it".format(
197-
distname=dist.name,
198-
distdir=dist.dist_dir
210+
for entry in {'archs', 'ndk_api', 'android_api'}:
211+
setattr(dist, entry, dist_info.get(entry, None))
212+
if entry not in dist_info:
213+
warning(
214+
"Distribution {distname}: ({distdir}) has been "
215+
"built with an unknown {entry}, ignoring it, "
216+
"you might want to delete it".format(
217+
distname=dist.name,
218+
distdir=dist.dist_dir,
219+
entry=entry,
220+
)
199221
)
200-
)
201222
dists.append(dist)
202223
return dists
203224

0 commit comments

Comments
 (0)