Skip to content

Commit

Permalink
Fixed up check on existing folder when overwriting distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
inclement committed Sep 16, 2019
1 parent 53443c7 commit c49f5f3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pythonforandroid/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def get_distribution(cls, ctx, name=None, recipes=[],
ndk_api : int
The NDK API to compile against, included in the dist because it cannot
be changed later during APK packaging.
arch : Arch
The target architecture to compile against, included in the dist because
arch_name : str
The target architecture name to compile against, included in the dist because
it cannot be changed later during APK packaging.
recipes : list
The recipes that the distribution must contain.
Expand All @@ -86,17 +86,24 @@ def get_distribution(cls, ctx, name=None, recipes=[],

existing_dists = Distribution.get_distributions(ctx)

possible_dists = existing_dists
possible_dists = existing_dists[:]

name_match_dists = []
# Will hold dists that would be built in the same folder as an existing dist
folder_match_dist = None

# 0) Check if a dist with that name and architecture already exists
# There may be more than one dist with the same name but different arch targets
if name is not None and name:
possible_dists = [
d for d in possible_dists if
(d.name == name) and (arch_name in d.archs)]

# There should only be one folder with a given dist name *and* arch.
# We could check that here, but for compatibility let's let it slide
# and just record the details of one of them. We only use this data to
# possibly fail the build later, so it doesn't really matter if there
# was more than one clash.
folder_match_dist = possible_dists[0]

# 1) Check if any existing dists meet the requirements
_possible_dists = []
for dist in possible_dists:
Expand Down Expand Up @@ -133,22 +140,22 @@ def get_distribution(cls, ctx, name=None, recipes=[],
.format(dist.name))
return dist

assert len(possible_dists) < 2

# If there was a name match but we didn't already choose it,
# then the existing dist is incompatible with the requested
# configuration and the build cannot continue
if name_match_dists and not allow_replace_dist:
if folder_match_dist is not None and not allow_replace_dist:
raise BuildInterruptingException(
'Asked for dist with name {name} with recipes ({req_recipes}) and '
'NDK API {req_ndk_api}, but a dist '
'with this name already exists and has either incompatible recipes '
'({dist_recipes}) or NDK API {dist_ndk_api}'.format(
name=name,
req_ndk_api=ndk_api,
dist_ndk_api=name_match_dist.ndk_api,
dist_ndk_api=folder_match_dist.ndk_api,
req_recipes=', '.join(recipes),
dist_recipes=', '.join(name_match_dist.recipes)))
dist_recipes=', '.join(folder_match_dist.recipes)))

assert len(folder_match_dist) < 2

# If we got this far, we need to build a new dist
dist = Distribution(ctx)
Expand All @@ -170,7 +177,6 @@ def get_distribution(cls, ctx, name=None, recipes=[],
dist.ndk_api = ctx.ndk_api
dist.archs = [arch_name]


return dist

def folder_exists(self):
Expand Down

0 comments on commit c49f5f3

Please sign in to comment.