Skip to content

Commit 1636748

Browse files
authored
Merge pull request #1496 from JonasT/bootstrap_refactor
Rework common bootstrap area based on kollivier's work, refs #991
2 parents 8e7d649 + 1ea331d commit 1636748

File tree

22 files changed

+43
-12
lines changed

22 files changed

+43
-12
lines changed

pythonforandroid/bootstrap.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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 importlib
6+
import os
7+
import shutil
68

79
from pythonforandroid.logger import (warning, shprint, info, logger,
810
debug)
@@ -11,6 +13,26 @@
1113
from pythonforandroid.recipe import Recipe
1214

1315

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

102+
def get_common_dir(self):
103+
return os.path.abspath(join(self.bootstrap_dir, "..", 'common'))
104+
80105
@property
81106
def name(self):
82107
modname = self.__class__.__module__
@@ -86,9 +111,10 @@ def prepare_build_dir(self):
86111
'''Ensure that a build dir exists for the recipe. This same single
87112
dir will be used for building all different archs.'''
88113
self.build_dir = self.get_build_dir()
89-
shprint(sh.cp, '-r',
90-
join(self.bootstrap_dir, 'build'),
91-
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,
117+
override=False)
92118
if self.ctx.symlink_java_src:
93119
info('Symlinking java src instead of copying')
94120
shprint(sh.rm, '-r', join(self.build_dir, 'src'))
@@ -109,7 +135,7 @@ def run_distribute(self):
109135
@classmethod
110136
def list_bootstraps(cls):
111137
'''Find all the available bootstraps and return them.'''
112-
forbidden_dirs = ('__pycache__', )
138+
forbidden_dirs = ('__pycache__', 'common')
113139
bootstraps_dir = join(dirname(__file__), 'bootstraps')
114140
for name in listdir(bootstraps_dir):
115141
if name in forbidden_dirs:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include $(call all-subdir-makefiles)

pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk renamed to pythonforandroid/bootstraps/common/build/jni/application/src/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
44

55
LOCAL_MODULE := main
66

7-
SDL_PATH := ../SDL
7+
SDL_PATH := ../../SDL
88

99
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1010

0 commit comments

Comments
 (0)