Skip to content

Commit 54afc33

Browse files
committed
Merge pull request #720 from kived/osx-build
add --storage-dir option
2 parents 1ac0abc + 260ff87 commit 54afc33

File tree

4 files changed

+48
-35
lines changed

4 files changed

+48
-35
lines changed

pythonforandroid/archs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def get_env(self, with_flags_in_cc=True):
6161
ccache = self.ctx.ccache + ' '
6262
env['USE_CCACHE'] = '1'
6363
env['NDK_CCACHE'] = self.ctx.ccache
64+
env.update({k: v for k, v in environ.items() if k.startswith('CCACHE_')})
6465

6566
print('path is', environ['PATH'])
6667
cc = find_executable('{command_prefix}-gcc'.format(

pythonforandroid/build.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99
import re
1010
import sh
11-
from appdirs import user_data_dir
1211

1312
from pythonforandroid.util import (ensure_dir, current_directory)
1413
from pythonforandroid.logger import (info, warning, error, info_notify,
@@ -88,19 +87,22 @@ def get_python_install_dir(self):
8887
dir = join(self.python_installs_dir, self.bootstrap.distribution.name)
8988
return dir
9089

91-
def setup_dirs(self):
90+
def setup_dirs(self, storage_dir):
9291
'''Calculates all the storage and build dirs, and makes sure
9392
the directories exist where necessary.'''
94-
self.root_dir = realpath(dirname(__file__))
95-
96-
# AND: TODO: Allow the user to set the build_dir
97-
self.storage_dir = user_data_dir('python-for-android')
93+
self.storage_dir = expanduser(storage_dir)
94+
if ' ' in self.storage_dir:
95+
raise ValueError('storage dir path cannot contain spaces, please '
96+
'specify a path with --storage-dir')
9897
self.build_dir = join(self.storage_dir, 'build')
9998
self.dist_dir = join(self.storage_dir, 'dists')
10099

100+
def ensure_dirs(self):
101101
ensure_dir(self.storage_dir)
102102
ensure_dir(self.build_dir)
103103
ensure_dir(self.dist_dir)
104+
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
105+
ensure_dir(join(self.build_dir, 'other_builds'))
104106

105107
@property
106108
def android_api(self):
@@ -163,6 +165,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
163165
164166
'''
165167

168+
self.ensure_dirs()
169+
166170
if self._build_env_prepared:
167171
return
168172

@@ -434,9 +438,6 @@ def __init__(self):
434438
self.local_recipes = None
435439
self.copy_libs = False
436440

437-
# root of the toolchain
438-
self.setup_dirs()
439-
440441
# this list should contain all Archs, it is pruned later
441442
self.archs = (
442443
ArchARM(self),
@@ -445,9 +446,7 @@ def __init__(self):
445446
ArchAarch_64(self),
446447
)
447448

448-
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
449-
ensure_dir(join(self.build_dir, 'other_builds'))
450-
# other_builds: where everything else is built
449+
self.root_dir = realpath(dirname(__file__))
451450

452451
# remove the most obvious flags that can break the compilation
453452
self.env.pop("LDFLAGS", None)

pythonforandroid/recipe.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,13 @@ def clean_build(self, arch=None):
565565
info('Deleting {}'.format(directory))
566566
shutil.rmtree(directory)
567567

568-
def install_libs(self, arch, lib, *libs):
568+
def install_libs(self, arch, *libs):
569569
libs_dir = self.ctx.get_libs_dir(arch.arch)
570-
shprint(sh.cp, '-t', libs_dir, lib, *libs)
570+
if not libs:
571+
warning('install_libs called with no libraries to install!')
572+
return
573+
args = libs + (libs_dir,)
574+
shprint(sh.cp, *args)
571575

572576
def has_libs(self, arch, *libs):
573577
return all(map(lambda l: self.ctx.has_lib(arch.arch, l), libs))
@@ -577,8 +581,9 @@ def recipe_dirs(cls, ctx):
577581
recipe_dirs = []
578582
if ctx.local_recipes is not None:
579583
recipe_dirs.append(ctx.local_recipes)
580-
recipe_dirs.extend([join(ctx.storage_dir, 'recipes'),
581-
join(ctx.root_dir, "recipes")])
584+
if ctx.storage_dir:
585+
recipe_dirs.append(join(ctx.storage_dir, 'recipes'))
586+
recipe_dirs.append(join(ctx.root_dir, "recipes"))
582587
return recipe_dirs
583588

584589
@classmethod

pythonforandroid/toolchain.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import argparse
2424
import sh
25-
25+
from appdirs import user_data_dir
2626

2727
from pythonforandroid.recipe import (Recipe, PythonRecipe, CythonRecipe,
2828
CompiledComponentsPythonRecipe,
@@ -171,8 +171,6 @@ def split_argument_list(l):
171171
class ToolchainCL(object):
172172

173173
def __init__(self):
174-
self._ctx = None
175-
176174
parser = argparse.ArgumentParser(
177175
description="Tool for managing the Android / Python toolchain",
178176
usage="""toolchain <command> [<args>]
@@ -206,18 +204,23 @@ def __init__(self):
206204
'--debug', dest='debug', action='store_true',
207205
help='Display debug output and all build info')
208206
parser.add_argument(
209-
'--sdk_dir', dest='sdk_dir', default='',
207+
'--sdk-dir', '--sdk_dir', dest='sdk_dir', default='',
210208
help='The filepath where the Android SDK is installed')
211209
parser.add_argument(
212-
'--ndk_dir', dest='ndk_dir', default='',
210+
'--ndk-dir', '--ndk_dir', dest='ndk_dir', default='',
213211
help='The filepath where the Android NDK is installed')
214212
parser.add_argument(
215-
'--android_api', dest='android_api', default=0, type=int,
213+
'--android-api', '--android_api', dest='android_api', default=0, type=int,
216214
help='The Android API level to build against.')
217215
parser.add_argument(
218-
'--ndk_version', dest='ndk_version', default='',
216+
'--ndk-version', '--ndk_version', dest='ndk_version', default='',
219217
help=('The version of the Android NDK. This is optional, '
220218
'we try to work it out automatically from the ndk_dir.'))
219+
parser.add_argument(
220+
'--storage-dir', dest='storage_dir',
221+
default=self.default_storage_dir,
222+
help=('Primary storage directory for downloads and builds '
223+
'(default: {})'.format(self.default_storage_dir)))
221224

222225
# AND: This option doesn't really fit in the other categories, the
223226
# arg structure needs a rethink
@@ -228,7 +231,7 @@ def __init__(self):
228231

229232
# Options for specifying the Distribution
230233
parser.add_argument(
231-
'--dist_name',
234+
'--dist-name', '--dist_name',
232235
help='The name of the distribution to use or create',
233236
default='')
234237
parser.add_argument(
@@ -291,6 +294,10 @@ def __init__(self):
291294

292295
if args.debug:
293296
logger.setLevel(logging.DEBUG)
297+
298+
self.ctx = Context()
299+
self.storage_dir = args.storage_dir
300+
self.ctx.setup_dirs(self.storage_dir)
294301
self.sdk_dir = args.sdk_dir
295302
self.ndk_dir = args.ndk_dir
296303
self.android_api = args.android_api
@@ -322,6 +329,13 @@ def __init__(self):
322329

323330
getattr(self, args.command)(unknown)
324331

332+
@property
333+
def default_storage_dir(self):
334+
udd = user_data_dir('python-for-android')
335+
if ' ' in udd:
336+
udd = '~/.python-for-android'
337+
return udd
338+
325339
def _read_configuration(self):
326340
# search for a .p4a configuration file in the current directory
327341
if not exists(".p4a"):
@@ -335,12 +349,6 @@ def _read_configuration(self):
335349
for arg in line:
336350
sys.argv.append(arg)
337351

338-
@property
339-
def ctx(self):
340-
if self._ctx is None:
341-
self._ctx = Context()
342-
return self._ctx
343-
344352
def recipes(self, args):
345353
parser = argparse.ArgumentParser(
346354
description="List all the available recipes")
@@ -409,7 +417,7 @@ def clean_dists(self, args):
409417
parser = argparse.ArgumentParser(
410418
description="Delete any distributions that have been built.")
411419
args = parser.parse_args(args)
412-
ctx = Context()
420+
ctx = self.ctx
413421
if exists(ctx.dist_dir):
414422
shutil.rmtree(ctx.dist_dir)
415423

@@ -424,7 +432,7 @@ def clean_builds(self, args):
424432
parser = argparse.ArgumentParser(
425433
description="Delete all build files (but not download caches)")
426434
args = parser.parse_args(args)
427-
ctx = Context()
435+
ctx = self.ctx
428436
# if exists(ctx.dist_dir):
429437
# shutil.rmtree(ctx.dist_dir)
430438
if exists(ctx.build_dir):
@@ -462,7 +470,7 @@ def clean_download_cache(self, args):
462470
parser = argparse.ArgumentParser(
463471
description="Delete all download caches")
464472
args = parser.parse_args(args)
465-
ctx = Context()
473+
ctx = self.ctx
466474
if exists(ctx.packages_path):
467475
shutil.rmtree(ctx.packages_path)
468476

@@ -627,7 +635,7 @@ def print_context_info(self, args):
627635
python-for-android will internally use for package building, along
628636
with information about where the Android SDK and NDK will be called
629637
from.'''
630-
ctx = Context()
638+
ctx = self.ctx
631639
for attribute in ('root_dir', 'build_dir', 'dist_dir', 'libs_dir',
632640
'ccache', 'cython', 'sdk_dir', 'ndk_dir',
633641
'ndk_platform', 'ndk_ver', 'android_api'):
@@ -647,7 +655,7 @@ def dists(self, args):
647655
def distributions(self, args):
648656
'''Lists all distributions currently available (i.e. that have already
649657
been built).'''
650-
ctx = Context()
658+
ctx = self.ctx
651659
dists = Distribution.get_distributions(ctx)
652660

653661
if dists:

0 commit comments

Comments
 (0)