From 1538c8978cfca010a471977def5d97fc37dbd87b Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Mon, 28 Oct 2019 14:12:58 +0100 Subject: [PATCH 01/16] pygame recipe --- pythonforandroid/recipes/pygame2/__init__.py | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pythonforandroid/recipes/pygame2/__init__.py diff --git a/pythonforandroid/recipes/pygame2/__init__.py b/pythonforandroid/recipes/pygame2/__init__.py new file mode 100644 index 0000000000..e37282e785 --- /dev/null +++ b/pythonforandroid/recipes/pygame2/__init__.py @@ -0,0 +1,50 @@ +from pythonforandroid.recipe import CompiledComponentsPythonRecipe +from os.path import join +from shutil import copyfile +from pythonforandroid.toolchain import current_directory +import glob + +class Pygame2Recipe(CompiledComponentsPythonRecipe): + + version = '2.0.0-dev5' + url = 'https://github.com/pygame/pygame/archive/android.zip' + + site_packages_name = 'pygame' + name = 'pygame2' + + depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools'] + call_hostpython_via_targetpython = False # Due to setuptools + install_in_hostpython = False + + def cythonize_file(self, env, build_dir, filename): + # We can ignore a few files that aren't important to the + # android build, and may not work on Android anyway + do_not_cythonize = [] + if basename(filename) in do_not_cythonize: + return + super(Pygame2Recipe, self).cythonize_file(env, build_dir, filename) + + def prebuild_arch(self, arch): + super(Pygame2Recipe, self).prebuild_arch(arch) + with current_directory(self.get_build_dir(arch.arch)): + setup_template=open(join("buildconfig", "Setup.Android.SDL2.in")).read() + env=self.get_recipe_env(arch) + setup_file=setup_template.format( + sdl_includes=( + " -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') + + " -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch))), + sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), + sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'), + sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer')) + open("Setup", "w").write(setup_file) + + def get_recipe_env(self, arch): + env = super(Pygame2Recipe, self).get_recipe_env(arch) + if 'sdl2' in self.ctx.recipe_build_order: + env['USE_SDL2'] = '1' + + env["PYGAME_CROSS_COMPILE"]="TRUE" + env["PYGAME_ANDROID"]="TRUE" + return env + +recipe = Pygame2Recipe() From a10cd1324863803708bff1711b0beef335c0d0b8 Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Fri, 15 Nov 2019 13:54:31 +0100 Subject: [PATCH 02/16] include more dependencies --- pythonforandroid/recipes/pygame2/__init__.py | 52 +++++++++++--------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/pythonforandroid/recipes/pygame2/__init__.py b/pythonforandroid/recipes/pygame2/__init__.py index e37282e785..4b6f331277 100644 --- a/pythonforandroid/recipes/pygame2/__init__.py +++ b/pythonforandroid/recipes/pygame2/__init__.py @@ -1,50 +1,58 @@ from pythonforandroid.recipe import CompiledComponentsPythonRecipe from os.path import join -from shutil import copyfile from pythonforandroid.toolchain import current_directory -import glob + class Pygame2Recipe(CompiledComponentsPythonRecipe): - version = '2.0.0-dev5' + version = '2.0.0-dev7' url = 'https://github.com/pygame/pygame/archive/android.zip' site_packages_name = 'pygame' name = 'pygame2' - depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools'] + depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png'] call_hostpython_via_targetpython = False # Due to setuptools install_in_hostpython = False - def cythonize_file(self, env, build_dir, filename): - # We can ignore a few files that aren't important to the - # android build, and may not work on Android anyway - do_not_cythonize = [] - if basename(filename) in do_not_cythonize: - return - super(Pygame2Recipe, self).cythonize_file(env, build_dir, filename) - def prebuild_arch(self, arch): super(Pygame2Recipe, self).prebuild_arch(arch) with current_directory(self.get_build_dir(arch.arch)): - setup_template=open(join("buildconfig", "Setup.Android.SDL2.in")).read() - env=self.get_recipe_env(arch) - setup_file=setup_template.format( + setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read() + env = self.get_recipe_env(arch) + env['ANDROID_ROOT'] = join(self.ctx.ndk_platform, 'usr') + + ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') + ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') + + png = self.get_recipe('png', self.ctx) + png_lib_dir = join(png.get_build_dir(arch.arch), '.libs') + png_inc_dir = png.get_build_dir(arch) + + jpeg = self.get_recipe('jpeg', self.ctx) + jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch) + + setup_file = setup_template.format( sdl_includes=( " -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') + - " -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch))), - sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), + " -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) + + " -L" + png_lib_dir+ " -L" + jpeg_lib_dir+ " -L" + ndk_lib_dir ), + sdl_ttf_includes=" -I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'), - sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer')) + sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'), + jpeg_includes="-I"+jpeg_inc_dir, + png_includes="-I"+png_inc_dir, + freetype_includes="" + ) open("Setup", "w").write(setup_file) def get_recipe_env(self, arch): env = super(Pygame2Recipe, self).get_recipe_env(arch) if 'sdl2' in self.ctx.recipe_build_order: env['USE_SDL2'] = '1' - - env["PYGAME_CROSS_COMPILE"]="TRUE" - env["PYGAME_ANDROID"]="TRUE" + env["PYGAME_CROSS_COMPILE"] = "TRUE" + env["PYGAME_ANDROID"] = "TRUE" return env - + + recipe = Pygame2Recipe() From 7411f40e4ab748ce9731b6043ac98b2bbd52e92c Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Sun, 23 Feb 2020 15:27:37 +0100 Subject: [PATCH 03/16] asset paths --- pythonforandroid/bootstraps/common/build/build.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 4a53ae04ec..e5aa03f15e 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -357,6 +357,11 @@ def make_package(args): tar_dirs.append(python_bundle_dir) if get_bootstrap_name() == "webview": tar_dirs.append('webview_includes') + for asset in args.assets: + if isfile(asset): + shutil.copyfile(asset, join(assets_dir, asset)) + else: + shutil.copydir(asset, join(assets_dir, asset)) if args.private or args.launcher: make_tar( join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path, @@ -649,6 +654,9 @@ def parse_args(args=None): help='Custom key=value to add in application metadata') ap.add_argument('--uses-library', dest='android_used_libs', action='append', default=[], help='Used shared libraries included using tag in AndroidManifest.xml') + ap.add_argument('--asset', dest='assets', + action="append", + help=('Put this in the assets folder')) ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' 'the application.')) From c14aa27161072ceb55373a7ef9d169cdb6109e6d Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Sun, 23 Feb 2020 21:11:07 +0100 Subject: [PATCH 04/16] Asset paths in p4a command line tool --- .../bootstraps/common/build/build.py | 18 ++++++++++++------ pythonforandroid/toolchain.py | 7 +++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index e5aa03f15e..2238e7ac0a 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -288,10 +288,11 @@ def make_package(args): assets_dir = "src/main/assets" # Delete the old assets. - try_unlink(join(assets_dir, 'public.mp3')) - try_unlink(join(assets_dir, 'private.mp3')) ensure_dir(assets_dir) - + shutil.rmtree(assets_dir) + ensure_dir(assets_dir) + open(os.path.join(assets_dir, ".gitkeep"), 'a').close() + # In order to speedup import and initial depack, # construct a python27.zip make_python_zip() @@ -358,10 +359,15 @@ def make_package(args): if get_bootstrap_name() == "webview": tar_dirs.append('webview_includes') for asset in args.assets: - if isfile(asset): - shutil.copyfile(asset, join(assets_dir, asset)) + print(os.getcwd()) + asset_src, asset_dest=asset.split(":") + if isfile(realpath(asset_src)): + ensure_dir(dirname(join(assets_dir, asset_dest))) + shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) else: - shutil.copydir(asset, join(assets_dir, asset)) + #ensure_dir(dirname(join(assets_dir, asset_dest))) + shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest)) + if args.private or args.launcher: make_tar( join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path, diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 04cebfc673..3e569a3dc7 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -491,6 +491,9 @@ def add_parser(subparsers, *args, **kwargs): # However, it is also needed before the distribution is finally # assembled for locating the setup.py / other build systems, which # is why we also add it here: + parser_apk.add_argument('--add-asset', dest='assets', + action="append", + help=('Put this in the assets folder')) parser_apk.add_argument( '--private', dest='private', help='the directory with the app source code files' + @@ -576,6 +579,10 @@ def add_parser(subparsers, *args, **kwargs): if hasattr(args, "private") and args.private is not None: # Pass this value on to the internal bootstrap build.py: args.unknown_args += ["--private", args.private] + if hasattr(args, "assets") and args.assets is not None: + # Pass this value on to the internal bootstrap build.py: + for asset in args.assets: + args.unknown_args += ["--asset", os.path.abspath(asset)+":"+asset] if hasattr(args, "ignore_setup_py") and args.ignore_setup_py: args.use_setup_py = False From b693e80a1e22a416ebd61af0027421fd33b8aa7f Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Wed, 1 Apr 2020 12:53:52 +0200 Subject: [PATCH 05/16] fix openSSL download URL --- pythonforandroid/recipes/openssl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonforandroid/recipes/openssl/__init__.py b/pythonforandroid/recipes/openssl/__init__.py index a2ecb2c549..c3ac556b8f 100644 --- a/pythonforandroid/recipes/openssl/__init__.py +++ b/pythonforandroid/recipes/openssl/__init__.py @@ -47,7 +47,7 @@ class OpenSSLRecipe(Recipe): version = '1.1' '''the major minor version used to link our recipes''' - url_version = '1.1.1' + url_version = '1.1.1f' '''the version used to download our libraries''' url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz' From a86587688ea0f87785acffdfd950062a554778e9 Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Wed, 1 Apr 2020 14:23:23 +0200 Subject: [PATCH 06/16] handle absent command line parameter in build.py --- .../bootstraps/common/build/build.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 2238e7ac0a..96b744e15c 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -358,15 +358,14 @@ def make_package(args): tar_dirs.append(python_bundle_dir) if get_bootstrap_name() == "webview": tar_dirs.append('webview_includes') - for asset in args.assets: - print(os.getcwd()) - asset_src, asset_dest=asset.split(":") - if isfile(realpath(asset_src)): - ensure_dir(dirname(join(assets_dir, asset_dest))) - shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) - else: - #ensure_dir(dirname(join(assets_dir, asset_dest))) - shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest)) + if hasattr(args, "assets") and args.assets is not None: + for asset in args.assets: + asset_src, asset_dest=asset.split(":") + if isfile(realpath(asset_src)): + ensure_dir(dirname(join(assets_dir, asset_dest))) + shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) + else: + shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest)) if args.private or args.launcher: make_tar( From fb1c49ad9d71fa344c7bb7e1f919cdd2410446a5 Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Thu, 2 Apr 2020 10:02:20 +0200 Subject: [PATCH 07/16] pin pygame to tagged version, flake8 complicance --- pythonforandroid/recipes/pygame2/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pythonforandroid/recipes/pygame2/__init__.py b/pythonforandroid/recipes/pygame2/__init__.py index 4b6f331277..621d61a27e 100644 --- a/pythonforandroid/recipes/pygame2/__init__.py +++ b/pythonforandroid/recipes/pygame2/__init__.py @@ -6,7 +6,7 @@ class Pygame2Recipe(CompiledComponentsPythonRecipe): version = '2.0.0-dev7' - url = 'https://github.com/pygame/pygame/archive/android.zip' + url = 'https://github.com/pygame/pygame/archive/android-2.0.0-dev7.tar.gz' site_packages_name = 'pygame' name = 'pygame2' @@ -23,7 +23,6 @@ def prebuild_arch(self, arch): env['ANDROID_ROOT'] = join(self.ctx.ndk_platform, 'usr') ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') - ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') png = self.get_recipe('png', self.ctx) png_lib_dir = join(png.get_build_dir(arch.arch), '.libs') @@ -36,8 +35,8 @@ def prebuild_arch(self, arch): sdl_includes=( " -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') + " -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) + - " -L" + png_lib_dir+ " -L" + jpeg_lib_dir+ " -L" + ndk_lib_dir ), - sdl_ttf_includes=" -I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), + " -L" + png_lib_dir + " -L" + jpeg_lib_dir + " -L" + ndk_lib_dir), + sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'), sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'), jpeg_includes="-I"+jpeg_inc_dir, From 3390b9537ef00fde4a7e50f843810ddc9009554e Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Thu, 2 Apr 2020 20:57:37 +0200 Subject: [PATCH 08/16] flake8 complicance --- pythonforandroid/bootstraps/common/build/build.py | 2 +- pythonforandroid/toolchain.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 96b744e15c..e224690596 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -360,7 +360,7 @@ def make_package(args): tar_dirs.append('webview_includes') if hasattr(args, "assets") and args.assets is not None: for asset in args.assets: - asset_src, asset_dest=asset.split(":") + asset_src, asset_dest = asset.split(":") if isfile(realpath(asset_src)): ensure_dir(dirname(join(assets_dir, asset_dest))) shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 3e569a3dc7..83f5bf4a25 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -491,9 +491,10 @@ def add_parser(subparsers, *args, **kwargs): # However, it is also needed before the distribution is finally # assembled for locating the setup.py / other build systems, which # is why we also add it here: - parser_apk.add_argument('--add-asset', dest='assets', - action="append", - help=('Put this in the assets folder')) + parser_apk.add_argument( + '--add-asset', dest='assets', + action="append", + help=('Put this in the assets folder')) parser_apk.add_argument( '--private', dest='private', help='the directory with the app source code files' + From 3980e5f0c6a4775199a4ee7ebc42675178c7027f Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Fri, 3 Apr 2020 09:38:58 +0200 Subject: [PATCH 09/16] please don't tell me I just fixed a bug nobody else found for half a year --- pythonforandroid/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 8f0ac40a82..9540534a43 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -578,10 +578,11 @@ def build_recipes(build_order, python_modules, ctx, project_dir, info_main('Building {} for {}'.format(recipe.name, arch.arch)) if recipe.should_build(arch): recipe.build_arch(arch) - recipe.install_libraries(arch) else: info('{} said it is already built, skipping' .format(recipe.name)) + recipe.install_libraries(arch) + # 4) biglink everything info_main('# Biglinking object files') From 9686a98276b48e8409a910c0f920cbba7a0f346f Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Sat, 4 Apr 2020 13:54:40 +0200 Subject: [PATCH 10/16] command line option to add to the assets/ directory --- .../bootstraps/common/build/build.py | 17 +++++++++++++++-- pythonforandroid/toolchain.py | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 6b5c87b5c3..6cd67b7171 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -239,9 +239,10 @@ def make_package(args): assets_dir = "src/main/assets" # Delete the old assets. - try_unlink(join(assets_dir, 'public.mp3')) - try_unlink(join(assets_dir, 'private.mp3')) ensure_dir(assets_dir) + shutil.rmtree(assets_dir) + ensure_dir(assets_dir) + open(os.path.join(assets_dir, ".gitkeep"), 'a').close() # Add extra environment variable file into tar-able directory: env_vars_tarpath = tempfile.mkdtemp(prefix="p4a-extra-env-") @@ -304,6 +305,15 @@ def make_package(args): tar_dirs.append(python_bundle_dir) if get_bootstrap_name() == "webview": tar_dirs.append('webview_includes') + if hasattr(args, "assets") and args.assets is not None: + for asset in args.assets: + asset_src, asset_dest = asset.split(":") + if isfile(realpath(asset_src)): + ensure_dir(dirname(join(assets_dir, asset_dest))) + shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) + else: + shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest)) + if args.private or args.launcher: make_tar( join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path, @@ -598,6 +608,9 @@ def parse_args_and_make_package(args=None): help='Custom key=value to add in application metadata') ap.add_argument('--uses-library', dest='android_used_libs', action='append', default=[], help='Used shared libraries included using tag in AndroidManifest.xml') + ap.add_argument('--asset', dest='assets', + action="append", + help=('Put this in the assets folder')) ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' 'the application.')) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 955d8a8a52..0f481e5bb5 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -494,6 +494,10 @@ def add_parser(subparsers, *args, **kwargs): # However, it is also needed before the distribution is finally # assembled for locating the setup.py / other build systems, which # is why we also add it here: + parser_apk.add_argument( + '--add-asset', dest='assets', + action="append", + help=('Put this in the assets folder')) parser_apk.add_argument( '--private', dest='private', help='the directory with the app source code files' + @@ -582,6 +586,10 @@ def add_parser(subparsers, *args, **kwargs): args.unknown_args += ["--private", args.private] if hasattr(args, "build_mode") and args.build_mode == "release": args.unknown_args += ["--release"] + if hasattr(args, "assets") and args.assets is not None: + # Pass this value on to the internal bootstrap build.py: + for asset in args.assets: + args.unknown_args += ["--asset", os.path.abspath(asset)+":"+asset] if hasattr(args, "ignore_setup_py") and args.ignore_setup_py: args.use_setup_py = False From 975162e027f809c158c7245b9ecf784fdec6a891 Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Sat, 4 Apr 2020 14:06:57 +0200 Subject: [PATCH 11/16] allow custom destination paths --- pythonforandroid/bootstraps/common/build/build.py | 4 ++-- pythonforandroid/toolchain.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 6cd67b7171..07b61b527b 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -239,8 +239,8 @@ def make_package(args): assets_dir = "src/main/assets" # Delete the old assets. - ensure_dir(assets_dir) - shutil.rmtree(assets_dir) + if os.path.exists(assets_dir): + shutil.rmtree(assets_dir) ensure_dir(assets_dir) open(os.path.join(assets_dir, ".gitkeep"), 'a').close() diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 0f481e5bb5..eb56de244e 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -589,7 +589,11 @@ def add_parser(subparsers, *args, **kwargs): if hasattr(args, "assets") and args.assets is not None: # Pass this value on to the internal bootstrap build.py: for asset in args.assets: - args.unknown_args += ["--asset", os.path.abspath(asset)+":"+asset] + if ":" in asset: + asset_src, asset_dest = asset.split(":") + else: + asset_src = asset_dest = asset + args.unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest] if hasattr(args, "ignore_setup_py") and args.ignore_setup_py: args.use_setup_py = False From bd685027e74018205e905f9c8e2dd3659451b39b Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Sun, 26 Apr 2020 18:18:50 +0200 Subject: [PATCH 12/16] code review suggestions --- .../bootstraps/common/build/build.py | 32 +++++++------------ pythonforandroid/toolchain.py | 19 ++++++----- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 07b61b527b..a914c74402 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -86,17 +86,10 @@ def get_bootstrap_name(): environment = jinja2.Environment(loader=jinja2.FileSystemLoader( join(curdir, 'templates'))) - -def try_unlink(fn): - if exists(fn): - os.unlink(fn) - - def ensure_dir(path): if not exists(path): makedirs(path) - def render(template, dest, **kwargs): '''Using jinja2, render `template` to the filename `dest`, supplying the @@ -239,10 +232,8 @@ def make_package(args): assets_dir = "src/main/assets" # Delete the old assets. - if os.path.exists(assets_dir): - shutil.rmtree(assets_dir) + shutil.rmtree(assets_dir, ignore_errors=True) ensure_dir(assets_dir) - open(os.path.join(assets_dir, ".gitkeep"), 'a').close() # Add extra environment variable file into tar-able directory: env_vars_tarpath = tempfile.mkdtemp(prefix="p4a-extra-env-") @@ -305,14 +296,14 @@ def make_package(args): tar_dirs.append(python_bundle_dir) if get_bootstrap_name() == "webview": tar_dirs.append('webview_includes') - if hasattr(args, "assets") and args.assets is not None: - for asset in args.assets: - asset_src, asset_dest = asset.split(":") - if isfile(realpath(asset_src)): - ensure_dir(dirname(join(assets_dir, asset_dest))) - shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) - else: - shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest)) + + for asset in args.assets: + asset_src, asset_dest = asset.split(":") + if isfile(realpath(asset_src)): + ensure_dir(dirname(join(assets_dir, asset_dest))) + shutil.copy(realpath(asset_src), join(assets_dir, asset_dest)) + else: + shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest)) if args.private or args.launcher: make_tar( @@ -609,8 +600,9 @@ def parse_args_and_make_package(args=None): ap.add_argument('--uses-library', dest='android_used_libs', action='append', default=[], help='Used shared libraries included using tag in AndroidManifest.xml') ap.add_argument('--asset', dest='assets', - action="append", - help=('Put this in the assets folder')) + action="append", default=[], + metavar="/path/to/source:dest" + help='Put this in the assets folder at assets/dest') ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' 'the application.')) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index eb56de244e..3e73fe25a9 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -496,8 +496,8 @@ def add_parser(subparsers, *args, **kwargs): # is why we also add it here: parser_apk.add_argument( '--add-asset', dest='assets', - action="append", - help=('Put this in the assets folder')) + action="append", default=[], + help='Put this in the assets folder in the apk.') parser_apk.add_argument( '--private', dest='private', help='the directory with the app source code files' + @@ -586,14 +586,13 @@ def add_parser(subparsers, *args, **kwargs): args.unknown_args += ["--private", args.private] if hasattr(args, "build_mode") and args.build_mode == "release": args.unknown_args += ["--release"] - if hasattr(args, "assets") and args.assets is not None: - # Pass this value on to the internal bootstrap build.py: - for asset in args.assets: - if ":" in asset: - asset_src, asset_dest = asset.split(":") - else: - asset_src = asset_dest = asset - args.unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest] + for asset in args.assets: + if ":" in asset: + asset_src, asset_dest = asset.split(":") + else: + asset_src = asset_dest = asset + # take abspath now, because build.py will be run in bootstrap dir + args.unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest] if hasattr(args, "ignore_setup_py") and args.ignore_setup_py: args.use_setup_py = False From 223aa2753cac8d2ea1fb877bb2608155f1f4bd5e Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Mon, 27 Apr 2020 07:15:47 +0200 Subject: [PATCH 13/16] rename pygame2 to pygame again --- pythonforandroid/recipes/{pygame2 => pygame}/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) rename pythonforandroid/recipes/{pygame2 => pygame}/__init__.py (91%) diff --git a/pythonforandroid/recipes/pygame2/__init__.py b/pythonforandroid/recipes/pygame/__init__.py similarity index 91% rename from pythonforandroid/recipes/pygame2/__init__.py rename to pythonforandroid/recipes/pygame/__init__.py index 621d61a27e..abdde78012 100644 --- a/pythonforandroid/recipes/pygame2/__init__.py +++ b/pythonforandroid/recipes/pygame/__init__.py @@ -9,7 +9,7 @@ class Pygame2Recipe(CompiledComponentsPythonRecipe): url = 'https://github.com/pygame/pygame/archive/android-2.0.0-dev7.tar.gz' site_packages_name = 'pygame' - name = 'pygame2' + name = 'pygame' depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png'] call_hostpython_via_targetpython = False # Due to setuptools @@ -47,10 +47,9 @@ def prebuild_arch(self, arch): def get_recipe_env(self, arch): env = super(Pygame2Recipe, self).get_recipe_env(arch) - if 'sdl2' in self.ctx.recipe_build_order: - env['USE_SDL2'] = '1' - env["PYGAME_CROSS_COMPILE"] = "TRUE" - env["PYGAME_ANDROID"] = "TRUE" + env['USE_SDL2'] = '1' + env["PYGAME_CROSS_COMPILE"] = "TRUE" + env["PYGAME_ANDROID"] = "TRUE" return env From e5aff0c7b12ee42e1399d0877c326475ee584c71 Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Mon, 27 Apr 2020 07:18:25 +0200 Subject: [PATCH 14/16] fix bugs sleepliy introduced in commit "code review suggestions" --- .../bootstraps/common/build/build.py | 2 +- pythonforandroid/toolchain.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index 864f1ad4b6..a38713aaed 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -602,7 +602,7 @@ def parse_args_and_make_package(args=None): help='Used shared libraries included using tag in AndroidManifest.xml') ap.add_argument('--asset', dest='assets', action="append", default=[], - metavar="/path/to/source:dest" + metavar="/path/to/source:dest", help='Put this in the assets folder at assets/dest') ap.add_argument('--icon', dest='icon', help=('A png file to use as the icon for ' diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index d31002e576..90bcb5e149 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -491,7 +491,7 @@ def add_parser(subparsers, *args, **kwargs): # However, it is also needed before the distribution is finally # assembled for locating the setup.py / other build systems, which # is why we also add it here: - parser_packaging.add_argument( + parser_packaging.add_argument( '--add-asset', dest='assets', action="append", default=[], help='Put this in the assets folder in the apk.') @@ -593,13 +593,6 @@ def add_parser(subparsers, *args, **kwargs): args.unknown_args += ["--private", args.private] if hasattr(args, "build_mode") and args.build_mode == "release": args.unknown_args += ["--release"] - for asset in args.assets: - if ":" in asset: - asset_src, asset_dest = asset.split(":") - else: - asset_src = asset_dest = asset - # take abspath now, because build.py will be run in bootstrap dir - args.unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest] if hasattr(args, "ignore_setup_py") and args.ignore_setup_py: args.use_setup_py = False @@ -960,6 +953,14 @@ def _fix_args(args): fix_args = ('--dir', '--private', '--add-jar', '--add-source', '--whitelist', '--blacklist', '--presplash', '--icon') unknown_args = args.unknown_args + + for asset in args.assets: + if ":" in asset: + asset_src, asset_dest = asset.split(":") + else: + asset_src = asset_dest = asset + # take abspath now, because build.py will be run in bootstrap dir + unknown_args += ["--asset", os.path.abspath(asset_src)+":"+asset_dest] for i, arg in enumerate(unknown_args): argx = arg.split('=') if argx[0] in fix_args: From e97872e3273bc5340f3a8043f6cfb702064c616d Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Mon, 27 Apr 2020 09:31:23 +0200 Subject: [PATCH 15/16] flake8 compliance --- pythonforandroid/bootstraps/common/build/build.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pythonforandroid/bootstraps/common/build/build.py b/pythonforandroid/bootstraps/common/build/build.py index a38713aaed..6b902dd0b1 100644 --- a/pythonforandroid/bootstraps/common/build/build.py +++ b/pythonforandroid/bootstraps/common/build/build.py @@ -86,10 +86,12 @@ def get_bootstrap_name(): environment = jinja2.Environment(loader=jinja2.FileSystemLoader( join(curdir, 'templates'))) + def ensure_dir(path): if not exists(path): makedirs(path) + def render(template, dest, **kwargs): '''Using jinja2, render `template` to the filename `dest`, supplying the From e40807836898d58a6d2e99d799b902d55c005dd5 Mon Sep 17 00:00:00 2001 From: Robert Pfeiffer Date: Mon, 27 Apr 2020 18:24:10 +0200 Subject: [PATCH 16/16] . --- pythonforandroid/recipes/pygame/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonforandroid/recipes/pygame/__init__.py b/pythonforandroid/recipes/pygame/__init__.py index abdde78012..37238b8661 100644 --- a/pythonforandroid/recipes/pygame/__init__.py +++ b/pythonforandroid/recipes/pygame/__init__.py @@ -16,7 +16,7 @@ class Pygame2Recipe(CompiledComponentsPythonRecipe): install_in_hostpython = False def prebuild_arch(self, arch): - super(Pygame2Recipe, self).prebuild_arch(arch) + super().prebuild_arch(arch) with current_directory(self.get_build_dir(arch.arch)): setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read() env = self.get_recipe_env(arch)