From 1ea331d255b79134e93ed4aebdcbca55d651aced Mon Sep 17 00:00:00 2001 From: Jonas Thiem Date: Fri, 30 Nov 2018 03:06:55 +0100 Subject: [PATCH] Rework common bootstrap area based on kollivier's work (github.com/kollivier) --- pythonforandroid/bootstrap.py | 36 +++++++++++++++--- .../{sdl2 => common}/build/ant.properties | 0 .../{sdl2 => common}/build/jni/Android.mk | 0 .../common/build/jni/application/Android.mk | 1 + .../build/jni/application}/src/Android.mk | 2 +- .../build/jni/application}/src/start.c | 0 .../build/templates/Service.tmpl.java | 0 .../build/templates/build.tmpl.xml | 0 .../build/templates/custom_rules.tmpl.xml | 0 .../build/templates/kivy-icon.png | Bin .../build/templates/kivy-presplash.jpg | Bin .../{sdl2 => common}/build/whitelist.txt | 0 .../jni/application}/src/Android_static.mk | 2 +- .../jni/{ => application}/src/Android.mk | 4 +- .../{ => application}/src/Android_static.mk | 0 .../jni/{ => application}/src/pyjniusjni.c | 0 .../build/jni/{ => application}/src/start.c | 0 .../jni/{ => application}/src/Android.mk | 4 +- .../jni/application}/src/Android_static.mk | 0 .../jni/{ => application}/src/pyjniusjni.c | 0 .../build/jni/{ => application}/src/start.c | 0 pythonforandroid/toolchain.py | 6 ++- 22 files changed, 43 insertions(+), 12 deletions(-) rename pythonforandroid/bootstraps/{sdl2 => common}/build/ant.properties (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/jni/Android.mk (100%) create mode 100644 pythonforandroid/bootstraps/common/build/jni/application/Android.mk rename pythonforandroid/bootstraps/{sdl2/build/jni => common/build/jni/application}/src/Android.mk (96%) rename pythonforandroid/bootstraps/{sdl2/build/jni => common/build/jni/application}/src/start.c (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/templates/Service.tmpl.java (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/templates/build.tmpl.xml (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/templates/custom_rules.tmpl.xml (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/templates/kivy-icon.png (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/templates/kivy-presplash.jpg (100%) rename pythonforandroid/bootstraps/{sdl2 => common}/build/whitelist.txt (100%) rename pythonforandroid/bootstraps/{webview/build/jni => sdl2/build/jni/application}/src/Android_static.mk (84%) rename pythonforandroid/bootstraps/service_only/build/jni/{ => application}/src/Android.mk (56%) rename pythonforandroid/bootstraps/service_only/build/jni/{ => application}/src/Android_static.mk (100%) rename pythonforandroid/bootstraps/service_only/build/jni/{ => application}/src/pyjniusjni.c (100%) rename pythonforandroid/bootstraps/service_only/build/jni/{ => application}/src/start.c (100%) rename pythonforandroid/bootstraps/webview/build/jni/{ => application}/src/Android.mk (59%) rename pythonforandroid/bootstraps/{sdl2/build/jni => webview/build/jni/application}/src/Android_static.mk (100%) rename pythonforandroid/bootstraps/webview/build/jni/{ => application}/src/pyjniusjni.c (100%) rename pythonforandroid/bootstraps/webview/build/jni/{ => application}/src/start.c (100%) diff --git a/pythonforandroid/bootstrap.py b/pythonforandroid/bootstrap.py index 531bc0db90..2988a18d28 100644 --- a/pythonforandroid/bootstrap.py +++ b/pythonforandroid/bootstrap.py @@ -1,8 +1,10 @@ from os.path import (join, dirname, isdir, splitext, basename) -from os import listdir +from os import listdir, walk, sep import sh import glob import importlib +import os +import shutil from pythonforandroid.logger import (warning, shprint, info, logger, debug) @@ -11,6 +13,26 @@ from pythonforandroid.recipe import Recipe +def copy_files(src_root, dest_root, override=True): + 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 override and os.path.exists(dest_file): + os.unlink(dest_file) + if not os.path.exists(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. @@ -77,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__ @@ -86,9 +111,10 @@ 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, + override=False) if self.ctx.symlink_java_src: info('Symlinking java src instead of copying') shprint(sh.rm, '-r', join(self.build_dir, 'src')) @@ -109,7 +135,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: diff --git a/pythonforandroid/bootstraps/sdl2/build/ant.properties b/pythonforandroid/bootstraps/common/build/ant.properties similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/ant.properties rename to pythonforandroid/bootstraps/common/build/ant.properties diff --git a/pythonforandroid/bootstraps/sdl2/build/jni/Android.mk b/pythonforandroid/bootstraps/common/build/jni/Android.mk similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/jni/Android.mk rename to pythonforandroid/bootstraps/common/build/jni/Android.mk diff --git a/pythonforandroid/bootstraps/common/build/jni/application/Android.mk b/pythonforandroid/bootstraps/common/build/jni/application/Android.mk new file mode 100644 index 0000000000..5053e7d643 --- /dev/null +++ b/pythonforandroid/bootstraps/common/build/jni/application/Android.mk @@ -0,0 +1 @@ +include $(call all-subdir-makefiles) diff --git a/pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk b/pythonforandroid/bootstraps/common/build/jni/application/src/Android.mk similarity index 96% rename from pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk rename to pythonforandroid/bootstraps/common/build/jni/application/src/Android.mk index be2bb9b27a..4a442eeb32 100644 --- a/pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk +++ b/pythonforandroid/bootstraps/common/build/jni/application/src/Android.mk @@ -4,7 +4,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := main -SDL_PATH := ../SDL +SDL_PATH := ../../SDL LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include diff --git a/pythonforandroid/bootstraps/sdl2/build/jni/src/start.c b/pythonforandroid/bootstraps/common/build/jni/application/src/start.c similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/jni/src/start.c rename to pythonforandroid/bootstraps/common/build/jni/application/src/start.c diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java b/pythonforandroid/bootstraps/common/build/templates/Service.tmpl.java similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/templates/Service.tmpl.java rename to pythonforandroid/bootstraps/common/build/templates/Service.tmpl.java diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/build.tmpl.xml b/pythonforandroid/bootstraps/common/build/templates/build.tmpl.xml similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/templates/build.tmpl.xml rename to pythonforandroid/bootstraps/common/build/templates/build.tmpl.xml diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/custom_rules.tmpl.xml b/pythonforandroid/bootstraps/common/build/templates/custom_rules.tmpl.xml similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/templates/custom_rules.tmpl.xml rename to pythonforandroid/bootstraps/common/build/templates/custom_rules.tmpl.xml diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/kivy-icon.png b/pythonforandroid/bootstraps/common/build/templates/kivy-icon.png similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/templates/kivy-icon.png rename to pythonforandroid/bootstraps/common/build/templates/kivy-icon.png diff --git a/pythonforandroid/bootstraps/sdl2/build/templates/kivy-presplash.jpg b/pythonforandroid/bootstraps/common/build/templates/kivy-presplash.jpg similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/templates/kivy-presplash.jpg rename to pythonforandroid/bootstraps/common/build/templates/kivy-presplash.jpg diff --git a/pythonforandroid/bootstraps/sdl2/build/whitelist.txt b/pythonforandroid/bootstraps/common/build/whitelist.txt similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/whitelist.txt rename to pythonforandroid/bootstraps/common/build/whitelist.txt diff --git a/pythonforandroid/bootstraps/webview/build/jni/src/Android_static.mk b/pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.mk similarity index 84% rename from pythonforandroid/bootstraps/webview/build/jni/src/Android_static.mk rename to pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.mk index faed669c0e..517660be2a 100644 --- a/pythonforandroid/bootstraps/webview/build/jni/src/Android_static.mk +++ b/pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.mk @@ -4,7 +4,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := main -LOCAL_SRC_FILES := YourSourceHere.c +LOCAL_SRC_FILES := start.c LOCAL_STATIC_LIBRARIES := SDL2_static diff --git a/pythonforandroid/bootstraps/service_only/build/jni/src/Android.mk b/pythonforandroid/bootstraps/service_only/build/jni/application/src/Android.mk similarity index 56% rename from pythonforandroid/bootstraps/service_only/build/jni/src/Android.mk rename to pythonforandroid/bootstraps/service_only/build/jni/application/src/Android.mk index 018a7cadf0..2a880fbb3a 100644 --- a/pythonforandroid/bootstraps/service_only/build/jni/src/Android.mk +++ b/pythonforandroid/bootstraps/service_only/build/jni/application/src/Android.mk @@ -7,13 +7,13 @@ LOCAL_MODULE := main # Add your application source files here... LOCAL_SRC_FILES := start.c pyjniusjni.c -LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS) +LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS) LOCAL_SHARED_LIBRARIES := python_shared LOCAL_LDLIBS := -llog $(EXTRA_LDLIBS) -LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS) +LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS) include $(BUILD_SHARED_LIBRARY) diff --git a/pythonforandroid/bootstraps/service_only/build/jni/src/Android_static.mk b/pythonforandroid/bootstraps/service_only/build/jni/application/src/Android_static.mk similarity index 100% rename from pythonforandroid/bootstraps/service_only/build/jni/src/Android_static.mk rename to pythonforandroid/bootstraps/service_only/build/jni/application/src/Android_static.mk diff --git a/pythonforandroid/bootstraps/service_only/build/jni/src/pyjniusjni.c b/pythonforandroid/bootstraps/service_only/build/jni/application/src/pyjniusjni.c similarity index 100% rename from pythonforandroid/bootstraps/service_only/build/jni/src/pyjniusjni.c rename to pythonforandroid/bootstraps/service_only/build/jni/application/src/pyjniusjni.c diff --git a/pythonforandroid/bootstraps/service_only/build/jni/src/start.c b/pythonforandroid/bootstraps/service_only/build/jni/application/src/start.c similarity index 100% rename from pythonforandroid/bootstraps/service_only/build/jni/src/start.c rename to pythonforandroid/bootstraps/service_only/build/jni/application/src/start.c diff --git a/pythonforandroid/bootstraps/webview/build/jni/src/Android.mk b/pythonforandroid/bootstraps/webview/build/jni/application/src/Android.mk similarity index 59% rename from pythonforandroid/bootstraps/webview/build/jni/src/Android.mk rename to pythonforandroid/bootstraps/webview/build/jni/application/src/Android.mk index b431059f12..d0e27227bc 100644 --- a/pythonforandroid/bootstraps/webview/build/jni/src/Android.mk +++ b/pythonforandroid/bootstraps/webview/build/jni/application/src/Android.mk @@ -9,13 +9,13 @@ LOCAL_MODULE := main # Add your application source files here... LOCAL_SRC_FILES := start.c pyjniusjni.c -LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS) +LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS) LOCAL_SHARED_LIBRARIES := python_shared LOCAL_LDLIBS := -llog $(EXTRA_LDLIBS) -LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS) +LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS) include $(BUILD_SHARED_LIBRARY) diff --git a/pythonforandroid/bootstraps/sdl2/build/jni/src/Android_static.mk b/pythonforandroid/bootstraps/webview/build/jni/application/src/Android_static.mk similarity index 100% rename from pythonforandroid/bootstraps/sdl2/build/jni/src/Android_static.mk rename to pythonforandroid/bootstraps/webview/build/jni/application/src/Android_static.mk diff --git a/pythonforandroid/bootstraps/webview/build/jni/src/pyjniusjni.c b/pythonforandroid/bootstraps/webview/build/jni/application/src/pyjniusjni.c similarity index 100% rename from pythonforandroid/bootstraps/webview/build/jni/src/pyjniusjni.c rename to pythonforandroid/bootstraps/webview/build/jni/application/src/pyjniusjni.c diff --git a/pythonforandroid/bootstraps/webview/build/jni/src/start.c b/pythonforandroid/bootstraps/webview/build/jni/application/src/start.c similarity index 100% rename from pythonforandroid/bootstraps/webview/build/jni/src/start.c rename to pythonforandroid/bootstraps/webview/build/jni/application/src/start.c diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 2dd406c3e4..994b07a27c 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -141,6 +141,9 @@ def wrapper_func(self, args): user_ndk_ver=self.ndk_version, user_ndk_api=self.ndk_api) 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: if dist.folder_exists(): # possible if the dist is being replaced dist.delete() @@ -183,7 +186,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)