Skip to content

Commit 1ea331d

Browse files
author
Jonas Thiem
committed
Rework common bootstrap area based on kollivier's work (github.com/kollivier)
1 parent 8e7d649 commit 1ea331d

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

pythonforandroid/bootstraps/webview/build/jni/src/Android_static.mk renamed to pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.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-
LOCAL_SRC_FILES := YourSourceHere.c
7+
LOCAL_SRC_FILES := start.c
88

99
LOCAL_STATIC_LIBRARIES := SDL2_static
1010

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ LOCAL_MODULE := main
77
# Add your application source files here...
88
LOCAL_SRC_FILES := start.c pyjniusjni.c
99

10-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
10+
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
1111

1212
LOCAL_SHARED_LIBRARIES := python_shared
1313

1414
LOCAL_LDLIBS := -llog $(EXTRA_LDLIBS)
1515

16-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
16+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
1717

1818
include $(BUILD_SHARED_LIBRARY)
1919

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ LOCAL_MODULE := main
99
# Add your application source files here...
1010
LOCAL_SRC_FILES := start.c pyjniusjni.c
1111

12-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
12+
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
1313

1414
LOCAL_SHARED_LIBRARIES := python_shared
1515

1616
LOCAL_LDLIBS := -llog $(EXTRA_LDLIBS)
1717

18-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
18+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
1919

2020
include $(BUILD_SHARED_LIBRARY)
2121

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_ndk_ver=self.ndk_version,
142142
user_ndk_api=self.ndk_api)
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
if dist.folder_exists(): # possible if the dist is being replaced
146149
dist.delete()
@@ -183,7 +186,8 @@ def build_dist_from_args(ctx, dist, args):
183186

184187
ctx.dist_name = bs.distribution.name
185188
ctx.prepare_bootstrap(bs)
186-
ctx.prepare_dist(ctx.dist_name)
189+
if dist.needs_build:
190+
ctx.prepare_dist(ctx.dist_name)
187191

188192
build_recipes(build_order, python_modules, ctx)
189193

0 commit comments

Comments
 (0)