Skip to content

Commit 98d0461

Browse files
committed
optimize copy of bootstrap
1 parent 3f78877 commit 98d0461

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

pythonforandroid/bootstrap.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sh
88
import shlex
99
import shutil
10+
from pathlib import Path
1011

1112
from pythonforandroid.logger import (shprint, info, info_main, logger, debug)
1213
from pythonforandroid.util import (
@@ -40,6 +41,36 @@ def copy_files(src_root, dest_root, override=True, symlink=False):
4041
os.makedirs(dest_file)
4142

4243

44+
def copytree_filtered(src, dst, skip_dirs=None):
45+
"""
46+
Copy directory tree while skipping explicitly specified directories in src.
47+
"""
48+
49+
info(f"Copying {src} to {dst} with skip dirs: {skip_dirs}")
50+
51+
src = Path(src)
52+
dst = Path(dst)
53+
skip_dirs = set(Path(p) for p in (skip_dirs or []))
54+
55+
def should_skip(rel_path):
56+
# match exact directory path only
57+
return any(rel_path == skip or skip in rel_path.parents for skip in skip_dirs)
58+
59+
for item in src.rglob("*"):
60+
rel = item.relative_to(src)
61+
62+
if should_skip(rel):
63+
continue
64+
65+
target = dst / rel
66+
67+
if item.is_dir():
68+
target.mkdir(parents=True, exist_ok=True)
69+
else:
70+
target.parent.mkdir(parents=True, exist_ok=True)
71+
shutil.copy2(item, target)
72+
73+
4374
default_recipe_priorities = [
4475
"webview", "sdl2", "sdl3", "service_only" # last is highest
4576
]
@@ -91,6 +122,10 @@ class Bootstrap:
91122
from Bootstrap.get_bootstrap_from_recipes.
92123
'''
93124

125+
# Directories to exclude during copy (relative to src root).
126+
# Used to reduce final build size and exclude unnecessary sources for final build.
127+
skip_dirs = []
128+
94129
# Other things a Bootstrap might need to track (maybe separately):
95130
# ndk_main.c
96131
# whitelist.txt
@@ -201,6 +236,7 @@ def _assemble_distribution_for_arch(self, arch):
201236
self.strip_libraries(arch)
202237
self.fry_eggs(site_packages_dir)
203238

239+
204240
def assemble_distribution(self):
205241
"""Assemble the distribution by copying files and creating Python bundle.
206242
@@ -211,7 +247,7 @@ def assemble_distribution(self):
211247
info_main(f'# Creating Android project ({self.name})')
212248

213249
rmdir(self.dist_dir)
214-
shprint(sh.cp, '-r', self.build_dir, self.dist_dir)
250+
copytree_filtered(self.build_dir, self.dist_dir, skip_dirs=self.skip_dirs)
215251

216252
with current_directory(self.dist_dir):
217253
with open('local.properties', 'w') as fileh:

pythonforandroid/bootstraps/_sdl_common/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class SDLGradleBootstrap(Bootstrap):
99

1010
recipe_depends = []
1111

12+
skip_dirs = ["jni"]
13+
1214
def _assemble_distribution_for_arch(self, arch):
1315
"""SDL bootstrap skips distribute_aars() - handled differently."""
1416
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
2525
def is_kivy_less_than_3(recipe=None, arch=None):
2626
return packaging.version.parse(
2727
str(get_kivy_version(recipe, arch))
28-
) < packaging.version.Version("3.0.0")
28+
) < packaging.version.Version("3.0.0.dev0")
2929

3030

3131
class KivyRecipe(PyProjectRecipe):

0 commit comments

Comments
 (0)