Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def android_api(self, value):
def ndk_api(self):
'''The API number compile against'''
if self._ndk_api is None:
raise ValueError('Tried to access ndk_api_api but it has not '
raise ValueError('Tried to access ndk_api but it has not '
'been set - this should not happen, something '
'went wrong!')
return self._ndk_api
Expand Down
16 changes: 14 additions & 2 deletions pythonforandroid/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pythonforandroid.logger import (info, info_notify, warning,
Err_Style, Err_Fore, error)
from pythonforandroid.util import current_directory
from shutil import rmtree


class Distribution(object):
Expand Down Expand Up @@ -46,7 +47,8 @@ def get_distribution(cls, ctx, name=None, recipes=[],
ndk_api=None,
force_build=False,
extra_dist_dirs=[],
require_perfect_match=False):
require_perfect_match=False,
allow_replace_dist=True):
'''Takes information about the distribution, and decides what kind of
distribution it will be.

Expand All @@ -70,6 +72,10 @@ def get_distribution(cls, ctx, name=None, recipes=[],
require_perfect_match : bool
If True, will only match distributions with precisely the
correct set of recipes.
allow_replace_dist : bool
If True, will allow an existing dist with the specified
name but incompatible requirements to be overwritten by
a new one with the current requirements.
'''

existing_dists = Distribution.get_distributions(ctx)
Expand Down Expand Up @@ -123,7 +129,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
# 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_dist is not None:
if name_match_dist is not None and not allow_replace_dist:
error('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 '
Expand Down Expand Up @@ -154,6 +160,12 @@ def get_distribution(cls, ctx, name=None, recipes=[],

return dist

def folder_exists(self):
return exists(self.dist_dir)

def delete(self):
rmtree(self.dist_dir)

@classmethod
def get_distributions(cls, ctx, extra_dist_dirs=[]):
'''Returns all the distributions found locally.'''
Expand Down
16 changes: 13 additions & 3 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def wrapper_func(self, args):
user_ndk_api=self.ndk_api)
dist = self._dist
if dist.needs_build:
if dist.folder_exists(): # possible if the dist is being replaced
dist.delete()
info_notify('No dist exists that meets your requirements, '
'so one will be built.')
build_dist_from_args(ctx, dist, args)
Expand All @@ -158,7 +160,8 @@ def dist_from_args(ctx, args):
name=args.dist_name,
ndk_api=args.ndk_api,
recipes=split_argument_list(args.requirements),
require_perfect_match=args.require_perfect_match)
require_perfect_match=args.require_perfect_match,
allow_replace_dist=args.allow_replace_dist)


def build_dist_from_args(ctx, dist, args):
Expand Down Expand Up @@ -316,6 +319,12 @@ def __init__(self):
description=('Whether the dist recipes must perfectly match '
'those requested'))

add_boolean_option(
generic_parser, ["allow-replace-dist"],
default=True,
description='Whether existing dist names can be automatically replaced'
)

generic_parser.add_argument(
'--local-recipes', '--local_recipes',
dest='local_recipes', default='./p4a-recipes',
Expand Down Expand Up @@ -921,10 +930,11 @@ def distributions(self, _args):

def delete_dist(self, _args):
dist = self._dist
if dist.needs_build:
if not dist.folder_exists():
info('No dist exists that matches your specifications, '
'exiting without deleting.')
shutil.rmtree(dist.dist_dir)
return
dist.delete()

def sdk_tools(self, args):
"""Runs the android binary from the detected SDK directory, passing
Expand Down