Skip to content

Commit 2b9f8b8

Browse files
committed
Added clean_recipe_build command
1 parent 287165c commit 2b9f8b8

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

pythonforandroid/toolchain.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,32 @@ def prepare_build_dir(self, arch):
15751575
'''
15761576
self.unpack(arch)
15771577

1578+
def clean_build(self, arch=None):
1579+
'''Deletes all the build information of the recipe.
1580+
1581+
If arch is not None, only this arch dir is deleted. Otherwise
1582+
(the default) all builds for all archs are deleted.
1583+
1584+
By default, this just deletes the main build dir. If the
1585+
recipe has e.g. object files biglinked, or .so files stored
1586+
elsewhere, you should override this method.
1587+
1588+
This method is intended for testing purposes, it may have
1589+
strange results. Rebuild everything if this seems to happen.
1590+
1591+
'''
1592+
if arch is None:
1593+
dir = join(self.ctx.build_dir, 'other_builds', self.name)
1594+
else:
1595+
dir = self.get_build_container_dir(arch)
1596+
if exists(dir):
1597+
shutil.rmtree(dir)
1598+
else:
1599+
warning(('Attempted to clean build for {} but build'
1600+
'did not exist').format(self.name))
1601+
1602+
1603+
15781604
@classmethod
15791605
def list_recipes(cls):
15801606
forbidden_dirs = ('__pycache__', )
@@ -1913,7 +1939,11 @@ def run_pymodules_install(ctx, modules):
19131939
'probably means the package cannot be installed with '
19141940
'pip as it needs a compilation recipe.')
19151941

1916-
shprint(sh.bash, '-c', '''source venv/bin/activate && env CC=/bin/false CXX=/bin/false PYTHONPATH= pip install --target '{}' -r requirements.txt'''.format(ctx.get_site_packages_dir()))
1942+
# This bash method is what old-p4a used
1943+
# It works but should be replaced with something better
1944+
shprint(sh.bash, '-c', (
1945+
"source venv/bin/activate && env CC=/bin/false CXX=/bin/false"
1946+
"PYTHONPATH= pip install --target '{}' -r requirements.txt").format(ctx.get_site_packages_dir()))
19171947

19181948
def biglink(ctx, arch):
19191949
# First, collate object files from each recipe
@@ -2245,9 +2275,12 @@ def clean_dists(self, args):
22452275
shutil.rmtree(ctx.dist_dir)
22462276

22472277
def clean_builds(self, args):
2248-
'''Delete all build caches for each recipe.
2278+
'''Delete all build caches for each recipe, python-install, java code
2279+
and compiled libs collection.
22492280
22502281
This does *not* delete the package download cache or the final distributions.
2282+
2283+
You can also use clean_recipe_build to delete the build of a specific recipe.
22512284
'''
22522285
parser = argparse.ArgumentParser(
22532286
description="Delete all build files (but not download caches)")
@@ -2263,7 +2296,27 @@ def clean_builds(self, args):
22632296
if exists(libs_dir):
22642297
shutil.rmtree(libs_dir)
22652298

2299+
def clean_recipe_build(self, args):
2300+
'''Deletes the build files of the given recipe.
2301+
2302+
This is intended for debug purposes, you may experience
2303+
strange behaviour or problems with some recipes (if their
2304+
build has done unexpected state changes). If this happens, run
2305+
clean_builds, or attempt to clean other recipes until things
2306+
work again.
2307+
'''
2308+
parser = argparse.ArgumentParser(
2309+
description="Delete all build files for the given recipe name.")
2310+
parser.add_argument('recipe', help='The recipe name')
2311+
args = parser.parse_args(args)
2312+
2313+
recipe = Recipe.get_recipe(args.recipe, self.ctx)
2314+
info('Cleaning build for {} recipe.'.format(recipe.name))
2315+
recipe.clean_build()
2316+
2317+
22662318
def clean_download_cache(self, args):
2319+
22672320
'''
22682321
Deletes any downloaded recipe packages.
22692322

0 commit comments

Comments
 (0)