Skip to content

Commit f307718

Browse files
kollivierAndreMiras
authored andcommitted
Common bootstrap to be shared across bootstraps
This is the first step to fix DRY across bootstraps, refs #988
1 parent 99475fc commit f307718

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+39
-9
lines changed

pythonforandroid/bootstrap.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from os.path import (join, dirname, isdir, splitext, basename)
2-
from os import listdir
2+
from os import listdir, walk, sep
33
import sh
44
import glob
55
import json
66
import importlib
7+
import os
8+
import shutil
79

810
from pythonforandroid.logger import (warning, shprint, info, logger,
911
debug)
@@ -12,6 +14,25 @@
1214
from pythonforandroid.recipe import Recipe
1315

1416

17+
def copy_files(src_root, dest_root):
18+
for root, dirnames, filenames in walk(src_root):
19+
for filename in filenames:
20+
subdir = root.replace(src_root, "")
21+
if subdir.startswith(sep):
22+
subdir = subdir[1:]
23+
dest_dir = join(dest_root, subdir)
24+
if not os.path.exists(dest_dir):
25+
os.makedirs(dest_dir)
26+
src_file = join(root, filename)
27+
dest_file = join(dest_dir, filename)
28+
if os.path.isfile(src_file):
29+
if os.path.exists(dest_file):
30+
os.unlink(dest_file)
31+
shutil.copy(src_file, dest_file)
32+
else:
33+
os.makedirs(dest_file)
34+
35+
1536
class Bootstrap(object):
1637
'''An Android project template, containing recipe stuff for
1738
compilation and templated fields for APK info.
@@ -78,6 +99,9 @@ def get_build_dir(self):
7899
def get_dist_dir(self, name):
79100
return join(self.ctx.dist_dir, name)
80101

102+
def get_common_dir(self):
103+
return os.path.abspath(join(self.bootstrap_dir, "..", 'common'))
104+
81105
@property
82106
def name(self):
83107
modname = self.__class__.__module__
@@ -87,9 +111,9 @@ def prepare_build_dir(self):
87111
'''Ensure that a build dir exists for the recipe. This same single
88112
dir will be used for building all different archs.'''
89113
self.build_dir = self.get_build_dir()
90-
shprint(sh.cp, '-r',
91-
join(self.bootstrap_dir, 'build'),
92-
self.build_dir)
114+
self.common_dir = self.get_common_dir()
115+
copy_files(join(self.bootstrap_dir, 'build'), self.build_dir)
116+
copy_files(join(self.common_dir, 'build'), self.build_dir)
93117
if self.ctx.symlink_java_src:
94118
info('Symlinking java src instead of copying')
95119
shprint(sh.rm, '-r', join(self.build_dir, 'src'))

pythonforandroid/toolchain.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ def wrapper_func(self, args):
141141
user_android_api=self.android_api,
142142
user_ndk_ver=self.ndk_version)
143143
dist = self._dist
144+
bs = Bootstrap.get_bootstrap(args.bootstrap, ctx)
145+
# recipes rarely change, but during dev, bootstraps can change from
146+
# build to build, so run prepare_bootstrap even if needs_build is false
144147
if dist.needs_build:
145148
info_notify('No dist exists that meets your requirements, '
146149
'so one will be built.')
@@ -186,7 +189,8 @@ def build_dist_from_args(ctx, dist, args):
186189

187190
ctx.dist_name = bs.distribution.name
188191
ctx.prepare_bootstrap(bs)
189-
ctx.prepare_dist(ctx.dist_name)
192+
if dist.needs_build:
193+
ctx.prepare_dist(ctx.dist_name)
190194

191195
build_recipes(build_order, python_modules, ctx)
192196

tests/test_graph.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
name_sets = [['python2'],
1212
['kivy']]
13+
# TODO sdl2 -> common (for now)
1314
bootstraps = [None,
1415
Bootstrap.get_bootstrap('pygame', ctx),
15-
Bootstrap.get_bootstrap('sdl2', ctx)]
16+
Bootstrap.get_bootstrap('common', ctx)]
1617
valid_combinations = list(product(name_sets, bootstraps))
18+
# TODO sdl2 -> common (for now)
1719
valid_combinations.extend(
18-
[(['python3crystax'], Bootstrap.get_bootstrap('sdl2', ctx)),
19-
(['kivy', 'python3crystax'], Bootstrap.get_bootstrap('sdl2', ctx))])
20+
[(['python3crystax'], Bootstrap.get_bootstrap('common', ctx)),
21+
(['kivy', 'python3crystax'], Bootstrap.get_bootstrap('common', ctx))])
2022
invalid_combinations = [[['python2', 'python3crystax'], None]]
2123

2224

@@ -45,4 +47,4 @@ def test_bootstrap_dependency_addition2():
4547

4648
if __name__ == "__main__":
4749
get_recipe_order_and_bootstrap(ctx, ['python3'],
48-
Bootstrap.get_bootstrap('sdl2', ctx))
50+
Bootstrap.get_bootstrap('common', ctx))

0 commit comments

Comments
 (0)