Skip to content

Start on a common area for bootstraps, so that different bootstraps #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 29 additions & 5 deletions pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from os.path import (join, dirname, isdir, splitext, basename)
from os import listdir
from os import listdir, walk, sep
import sh
import glob
import json
import importlib
import os
import shutil

from pythonforandroid.logger import (warning, shprint, info, logger,
debug)
Expand All @@ -12,6 +14,25 @@
from pythonforandroid.recipe import Recipe


def copy_files(src_root, dest_root):
for root, dirnames, filenames in walk(src_root):
for filename in filenames:
subdir = root.replace(src_root, "")
if subdir.startswith(sep):
subdir = subdir[1:]
dest_dir = join(dest_root, subdir)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
src_file = join(root, filename)
dest_file = join(dest_dir, filename)
if os.path.isfile(src_file):
if os.path.exists(dest_file):
os.unlink(dest_file)
shutil.copy(src_file, dest_file)
else:
os.makedirs(dest_file)


class Bootstrap(object):
'''An Android project template, containing recipe stuff for
compilation and templated fields for APK info.
Expand Down Expand Up @@ -78,6 +99,9 @@ def get_build_dir(self):
def get_dist_dir(self, name):
return join(self.ctx.dist_dir, name)

def get_common_dir(self):
return os.path.abspath(join(self.bootstrap_dir, "..", 'common'))

@property
def name(self):
modname = self.__class__.__module__
Expand All @@ -87,9 +111,9 @@ 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)
self.common_dir = self.get_common_dir()
copy_files(join(self.bootstrap_dir, 'build'), self.build_dir)
copy_files(join(self.common_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'))
Expand Down Expand Up @@ -121,7 +145,7 @@ def run_distribute(self):
@classmethod
def list_bootstraps(cls):
'''Find all the available bootstraps and return them.'''
forbidden_dirs = ('__pycache__', )
forbidden_dirs = ('__pycache__', 'common')
bootstraps_dir = join(dirname(__file__), 'bootstraps')
for name in listdir(bootstraps_dir):
if name in forbidden_dirs:
Expand Down
6 changes: 5 additions & 1 deletion pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def wrapper_func(self, args):
user_android_api=self.android_api,
user_ndk_ver=self.ndk_version)
dist = self._dist
bs = Bootstrap.get_bootstrap(args.bootstrap, ctx)
# recipes rarely change, but during dev, bootstraps can change from
# build to build, so run prepare_bootstrap even if needs_build is false
if dist.needs_build:
info_notify('No dist exists that meets your requirements, '
'so one will be built.')
Expand Down Expand Up @@ -186,7 +189,8 @@ def build_dist_from_args(ctx, dist, args):

ctx.dist_name = bs.distribution.name
ctx.prepare_bootstrap(bs)
ctx.prepare_dist(ctx.dist_name)
if dist.needs_build:
ctx.prepare_dist(ctx.dist_name)

build_recipes(build_order, python_modules, ctx)

Expand Down
10 changes: 6 additions & 4 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

name_sets = [['python2'],
['kivy']]
# TODO sdl2 -> common (for now)
bootstraps = [None,
Bootstrap.get_bootstrap('pygame', ctx),
Bootstrap.get_bootstrap('sdl2', ctx)]
Bootstrap.get_bootstrap('common', ctx)]
valid_combinations = list(product(name_sets, bootstraps))
# TODO sdl2 -> common (for now)
valid_combinations.extend(
[(['python3crystax'], Bootstrap.get_bootstrap('sdl2', ctx)),
(['kivy', 'python3crystax'], Bootstrap.get_bootstrap('sdl2', ctx))])
[(['python3crystax'], Bootstrap.get_bootstrap('common', ctx)),
(['kivy', 'python3crystax'], Bootstrap.get_bootstrap('common', ctx))])
invalid_combinations = [[['python2', 'python3crystax'], None]]


Expand Down Expand Up @@ -45,4 +47,4 @@ def test_bootstrap_dependency_addition2():

if __name__ == "__main__":
get_recipe_order_and_bootstrap(ctx, ['python3'],
Bootstrap.get_bootstrap('sdl2', ctx))
Bootstrap.get_bootstrap('common', ctx))