Skip to content

Commit 2c37ed6

Browse files
committed
add --storage-dir option
1 parent 1ac0abc commit 2c37ed6

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
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 & 13 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,21 @@ 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

101100
ensure_dir(self.storage_dir)
102101
ensure_dir(self.build_dir)
103102
ensure_dir(self.dist_dir)
103+
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
104+
ensure_dir(join(self.build_dir, 'other_builds'))
104105

105106
@property
106107
def android_api(self):
@@ -154,7 +155,7 @@ def ndk_dir(self):
154155
def ndk_dir(self, value):
155156
self._ndk_dir = value
156157

157-
def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
158+
def prepare_build_environment(self, storage_dir, user_sdk_dir, user_ndk_dir,
158159
user_android_api, user_ndk_ver):
159160
'''Checks that build dependencies exist and sets internal variables
160161
for the Android SDK etc.
@@ -163,6 +164,8 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
163164
164165
'''
165166

167+
self.setup_dirs(storage_dir)
168+
166169
if self._build_env_prepared:
167170
return
168171

@@ -434,9 +437,6 @@ def __init__(self):
434437
self.local_recipes = None
435438
self.copy_libs = False
436439

437-
# root of the toolchain
438-
self.setup_dirs()
439-
440440
# this list should contain all Archs, it is pruned later
441441
self.archs = (
442442
ArchARM(self),
@@ -445,9 +445,7 @@ def __init__(self):
445445
ArchAarch_64(self),
446446
)
447447

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
448+
self.root_dir = realpath(dirname(__file__))
451449

452450
# remove the most obvious flags that can break the compilation
453451
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: 21 additions & 7 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,
@@ -93,7 +93,8 @@ def require_prebuilt_dist(func):
9393
def wrapper_func(self, args):
9494
ctx = self.ctx
9595
ctx.set_archs(self._archs)
96-
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
96+
ctx.prepare_build_environment(storage_dir=self.storage_dir,
97+
user_sdk_dir=self.sdk_dir,
9798
user_ndk_dir=self.ndk_dir,
9899
user_android_api=self.android_api,
99100
user_ndk_ver=self.ndk_version)
@@ -206,18 +207,23 @@ def __init__(self):
206207
'--debug', dest='debug', action='store_true',
207208
help='Display debug output and all build info')
208209
parser.add_argument(
209-
'--sdk_dir', dest='sdk_dir', default='',
210+
'--sdk-dir', '--sdk_dir', dest='sdk_dir', default='',
210211
help='The filepath where the Android SDK is installed')
211212
parser.add_argument(
212-
'--ndk_dir', dest='ndk_dir', default='',
213+
'--ndk-dir', '--ndk_dir', dest='ndk_dir', default='',
213214
help='The filepath where the Android NDK is installed')
214215
parser.add_argument(
215-
'--android_api', dest='android_api', default=0, type=int,
216+
'--android-api', '--android_api', dest='android_api', default=0, type=int,
216217
help='The Android API level to build against.')
217218
parser.add_argument(
218-
'--ndk_version', dest='ndk_version', default='',
219+
'--ndk-version', '--ndk_version', dest='ndk_version', default='',
219220
help=('The version of the Android NDK. This is optional, '
220221
'we try to work it out automatically from the ndk_dir.'))
222+
parser.add_argument(
223+
'--storage-dir', dest='storage_dir',
224+
default=self.default_storage_dir,
225+
help=('Primary storage directory for downloads and builds '
226+
'(default: {})'.format(self.default_storage_dir)))
221227

222228
# AND: This option doesn't really fit in the other categories, the
223229
# arg structure needs a rethink
@@ -228,7 +234,7 @@ def __init__(self):
228234

229235
# Options for specifying the Distribution
230236
parser.add_argument(
231-
'--dist_name',
237+
'--dist-name', '--dist_name',
232238
help='The name of the distribution to use or create',
233239
default='')
234240
parser.add_argument(
@@ -291,6 +297,7 @@ def __init__(self):
291297

292298
if args.debug:
293299
logger.setLevel(logging.DEBUG)
300+
self.storage_dir = args.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"):

0 commit comments

Comments
 (0)