Skip to content

Commit

Permalink
Common bootstrap to be shared across bootstraps
Browse files Browse the repository at this point in the history
This is the first step to fix DRY across bootstraps, refs kivy#988
  • Loading branch information
kollivier authored and AndreMiras committed Sep 27, 2018
1 parent 99475fc commit f307718
Show file tree
Hide file tree
Showing 63 changed files with 39 additions and 9 deletions.
32 changes: 28 additions & 4 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
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))

0 comments on commit f307718

Please sign in to comment.