from os.path import (join, dirname, isdir, splitext, basename, realpath) from os import listdir, mkdir import sh import glob import json import importlib from pythonforandroid.logger import (warning, shprint, info, logger, debug, error) from pythonforandroid.util import (current_directory, ensure_dir, temp_directory, which) from pythonforandroid.recipe import Recipe class Bootstrap(object): '''An Android project template, containing recipe stuff for compilation and templated fields for APK info. ''' name = '' jni_subdir = '/jni' ctx = None bootstrap_dir = None build_dir = None dist_dir = None dist_name = None distribution = None recipe_depends = ['sdl2'] can_be_chosen_automatically = True '''Determines whether the bootstrap can be chosen as one that satisfies user requirements. If False, it will not be returned from Bootstrap.get_bootstrap_from_recipes. ''' # Other things a Bootstrap might need to track (maybe separately): # ndk_main.c # whitelist.txt # blacklist.txt @property def dist_dir(self): '''The dist dir at which to place the finished distribution.''' if self.distribution is None: warning('Tried to access {}.dist_dir, but {}.distribution ' 'is None'.format(self, self)) exit(1) return self.distribution.dist_dir @property def jni_dir(self): return self.name + self.jni_subdir def check_recipe_choices(self): '''Checks what recipes are being built to see which of the alternative and optional dependencies are being used, and returns a list of these.''' recipes = [] built_recipes = self.ctx.recipe_build_order for recipe in self.recipe_depends: if isinstance(recipe, (tuple, list)): for alternative in recipe: if alternative in built_recipes: recipes.append(alternative) break return sorted(recipes) def get_build_dir_name(self): choices = self.check_recipe_choices() dir_name = '-'.join([self.name] + choices) return dir_name def get_build_dir(self): return join(self.ctx.build_dir, 'bootstrap_builds', self.get_build_dir_name()) def get_dist_dir(self, name): return join(self.ctx.dist_dir, name) @property def name(self): modname = self.__class__.__module__ return modname.split(".", 2)[-1] def prepare_build_dir(self): '''Ensure that a build dir exists for the recipe. This same single dir will be used for building all different archs.''' self.build_dir = self.get_build_dir() shprint(sh.cp, '-r', join(self.bootstrap_dir, 'build'), self.build_dir) if self.ctx.symlink_java_src: info('Symlinking java src instead of copying') shprint(sh.rm, '-r', join(self.build_dir, 'src')) shprint(sh.mkdir, join(self.build_dir, 'src')) for dirn in listdir(join(self.bootstrap_dir, 'build', 'src')): shprint(sh.ln, '-s', join