Skip to content

Commit 53443c7

Browse files
committed
Made p4a use per-arch dist build dirs
1 parent 2f98b81 commit 53443c7

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

pythonforandroid/distribution.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Distribution(object):
2424
ndk_api = None
2525

2626
archs = []
27-
'''The arch targets that the dist is built for.'''
27+
'''The names of the arch targets that the dist is built for.'''
2828

2929
recipes = []
3030

@@ -44,6 +44,7 @@ def __repr__(self):
4444
@classmethod
4545
def get_distribution(cls, ctx, name=None, recipes=[],
4646
ndk_api=None,
47+
arch_name=None,
4748
force_build=False,
4849
extra_dist_dirs=[],
4950
require_perfect_match=False,
@@ -60,6 +61,12 @@ def get_distribution(cls, ctx, name=None, recipes=[],
6061
name : str
6162
The name of the distribution. If a dist with this name already '
6263
exists, it will be used.
64+
ndk_api : int
65+
The NDK API to compile against, included in the dist because it cannot
66+
be changed later during APK packaging.
67+
arch : Arch
68+
The target architecture to compile against, included in the dist because
69+
it cannot be changed later during APK packaging.
6370
recipes : list
6471
The recipes that the distribution must contain.
6572
force_download: bool
@@ -81,13 +88,14 @@ def get_distribution(cls, ctx, name=None, recipes=[],
8188

8289
possible_dists = existing_dists
8390

84-
name_match_dist = None
91+
name_match_dists = []
8592

86-
# 0) Check if a dist with that name already exists
93+
# 0) Check if a dist with that name and architecture already exists
94+
# There may be more than one dist with the same name but different arch targets
8795
if name is not None and name:
88-
possible_dists = [d for d in possible_dists if d.name == name]
89-
if possible_dists:
90-
name_match_dist = possible_dists[0]
96+
possible_dists = [
97+
d for d in possible_dists if
98+
(d.name == name) and (arch_name in d.archs)]
9199

92100
# 1) Check if any existing dists meet the requirements
93101
_possible_dists = []
@@ -110,12 +118,14 @@ def get_distribution(cls, ctx, name=None, recipes=[],
110118
else:
111119
info('No existing dists meet the given requirements!')
112120

113-
# If any dist has perfect recipes and ndk API, return it
121+
# If any dist has perfect recipes, arch and NDK API, return it
114122
for dist in possible_dists:
115123
if force_build:
116124
continue
117125
if ndk_api is not None and dist.ndk_api != ndk_api:
118126
continue
127+
if arch_name is not None and arch_name not in dist.archs:
128+
continue
119129
if (set(dist.recipes) == set(recipes) or
120130
(set(recipes).issubset(set(dist.recipes)) and
121131
not require_perfect_match)):
@@ -128,7 +138,7 @@ def get_distribution(cls, ctx, name=None, recipes=[],
128138
# If there was a name match but we didn't already choose it,
129139
# then the existing dist is incompatible with the requested
130140
# configuration and the build cannot continue
131-
if name_match_dist is not None and not allow_replace_dist:
141+
if name_match_dists and not allow_replace_dist:
132142
raise BuildInterruptingException(
133143
'Asked for dist with name {name} with recipes ({req_recipes}) and '
134144
'NDK API {req_ndk_api}, but a dist '
@@ -152,9 +162,14 @@ def get_distribution(cls, ctx, name=None, recipes=[],
152162
name = filen.format(i)
153163

154164
dist.name = name
155-
dist.dist_dir = join(ctx.dist_dir, dist.name)
165+
dist.dist_dir = join(
166+
ctx.dist_dir,
167+
generate_dist_folder_name(name, [arch_name])
168+
)
156169
dist.recipes = recipes
157170
dist.ndk_api = ctx.ndk_api
171+
dist.archs = [arch_name]
172+
158173

159174
return dist
160175

@@ -182,7 +197,7 @@ def get_distributions(cls, ctx, extra_dist_dirs=[]):
182197
with open(join(folder, 'dist_info.json')) as fileh:
183198
dist_info = json.load(fileh)
184199
dist = cls(ctx)
185-
dist.name = folder.split('/')[-1]
200+
dist.name = dist_info['dist_name']
186201
dist.dist_dir = folder
187202
dist.needs_build = False
188203
dist.recipes = dist_info['recipes']
@@ -236,3 +251,22 @@ def pretty_log_dists(dists, log_func=info):
236251

237252
for line in infos:
238253
log_func('\t' + line)
254+
255+
def generate_dist_folder_name(base_dist_name, arch_names=None):
256+
"""Generate the distribution folder name to use, based on a
257+
combination of the input arguments.
258+
259+
Parameters
260+
----------
261+
base_dist_name : str
262+
The core distribution identifier string
263+
arch_names : list of str
264+
The architecture compile targets
265+
"""
266+
if arch_names is None:
267+
arch_names = ["no_arch_specified"]
268+
269+
return '{}__{}'.format(
270+
base_dist_name,
271+
'_'.join(arch_names)
272+
)

pythonforandroid/toolchain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def dist_from_args(ctx, args):
163163
ctx,
164164
name=args.dist_name,
165165
recipes=split_argument_list(args.requirements),
166+
arch_name=args.arch,
166167
ndk_api=args.ndk_api,
167168
force_build=args.force_build,
168169
require_perfect_match=args.require_perfect_match,
@@ -304,7 +305,7 @@ def __init__(self):
304305
'(default: {})'.format(default_storage_dir)))
305306

306307
generic_parser.add_argument(
307-
'--arch', help='The archs to build for, separated by commas.',
308+
'--arch', help='The arch to build for.',
308309
default='armeabi-v7a')
309310

310311
# Options for specifying the Distribution

0 commit comments

Comments
 (0)