import json import glob from os.path import exists, join from pythonforandroid.logger import ( debug, info, info_notify, warning, Err_Style, Err_Fore) from pythonforandroid.util import ( current_directory, BuildInterruptingException, rmdir) class Distribution: '''State container for information about a distribution (i.e. an Android project). This is separate from a Bootstrap because the Bootstrap is concerned with building and populating the dist directory, whereas the dist itself could also come from e.g. a binary download. ''' ctx = None name = None # A name identifying the dist. May not be None. needs_build = False # Whether the dist needs compiling url = None dist_dir = None # Where the dist dir ultimately is. Should not be None. ndk_api = None archs = [] '''The names of the arch targets that the dist is built for.''' recipes = [] description = '' # A long description def __init__(self, ctx): self.ctx = ctx def __str__(self): return ''.format( # self.name, ', '.join([recipe.name for recipe in self.recipes])) self.name, ', '.join(self.recipes)) def __repr__(self): return str(self) @classmethod def get_distribution( cls, ctx, *, archs, # required keyword argument: there is no sensible default name=None, recipes=[], ndk_api=None, force_build=False, extra_dist_dirs=[], require_perfect_match=False, allow_replace_dist=True ): '''Takes information about the distribution, and decides what kind of distribution it will be. If parameters conflict (e.g. a dist with that name already exists, but doesn't have the right set of recipes), an error is thrown. Parameters ---------- name : str The name of the distribution. If a dist with this name already ' exists, it will be used. ndk_api : int The NDK API to compile against, included in the dist because it cannot be changed later during APK packaging. archs : list The target architectures list 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. force_download: bool If True, only downloaded dists are considered. force_build : bool If True, the dist is forced to be built locally. extra_dist_dirs : list Any extra directories in which to search for dists. 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. ''' possible_dists = Distribution.get_distributions(ctx) debug(f"All possibl