Skip to content

Commit cf1491a

Browse files
committed
Made bootstraps check the ndk api against the requested minsdk
1 parent 9b6436b commit cf1491a

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

pythonforandroid/bootstrap.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ def prepare_dist_dir(self, name):
106106
ensure_dir(self.dist_dir)
107107

108108
def run_distribute(self):
109-
# print('Default bootstrap being used doesn\'t know how '
110-
# 'to distribute...failing.')
111-
# exit(1)
109+
# TODO: Move this to Distribution.save_info
112110
with current_directory(self.dist_dir):
113111
info('Saving distribution info')
114112
with open('dist_info.json', 'w') as fileh:
115113
json.dump({'dist_name': self.ctx.dist_name,
116114
'bootstrap': self.ctx.bootstrap.name,
117115
'archs': [arch.arch for arch in self.ctx.archs],
116+
'ndk_api': self.ctx.ndk_api,
118117
'recipes': self.ctx.recipe_build_order + self.ctx.python_modules},
119118
fileh)
120119

pythonforandroid/bootstraps/sdl2/build/build.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import tarfile
1010
import time
11+
import json
1112
import subprocess
1213
import shutil
1314
from zipfile import ZipFile
@@ -497,6 +498,10 @@ def parse_args(args=None):
497498
help=('Minimum Android SDK version to use. Default to '
498499
'the value of ANDROIDAPI, or {} if not set'
499500
.format(default_android_api)))
501+
ap.add_argument('--allow-minsdk-ndkapi-mismatch', default=False,
502+
action='store_true',
503+
help=('Allow the --minsdk argument to be different from '
504+
'the discovered ndk_api in the dist'))
500505
ap.add_argument('--intent-filters', dest='intent_filters',
501506
help=('Add intent-filters xml rules to the '
502507
'AndroidManifest.xml file. The argument is a '
@@ -529,8 +534,27 @@ def parse_args(args=None):
529534
if args.name and args.name[0] == '"' and args.name[-1] == '"':
530535
args.name = args.name[1:-1]
531536

532-
# if args.sdk_version == -1:
533-
# args.sdk_version = args.min_sdk_version
537+
with open('dist_info.json', 'r') as fileh:
538+
info = json.load(fileh)
539+
if 'ndk_api' not in info:
540+
print('Failed to read ndk_api from dist info')
541+
ndk_api = args.min_sdk_version
542+
else:
543+
ndk_api = info['ndk_api']
544+
if ndk_api != args.min_sdk_version:
545+
print(('WARNING: --minsdk argument does not match the api that is '
546+
'compiled against. Only proceed if you know what you are '
547+
'doing, otherwise use --minsdk={} or recompile against api '
548+
'{}').format(ndk_api, args.min_sdk_version))
549+
if not args.allow_minsdk_ndkapi_mismatch:
550+
print('You must pass --allow-minsdk-ndkapi-mismatch to build '
551+
'with --minsdk different to the target NDK api from the '
552+
'build step')
553+
exit(1)
554+
else:
555+
print('Proceeding with --minsdk not matching build target api')
556+
557+
534558

535559
if args.sdk_version != -1:
536560
print('WARNING: Received a --sdk argument, but this argument is '

pythonforandroid/distribution.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,29 @@ def get_distributions(cls, ctx, extra_dist_dirs=[]):
182182
dists.append(dist)
183183
return dists
184184

185-
def save_info(self):
186-
'''
187-
Save information about the distribution in its dist_dir.
188-
'''
189-
with current_directory(self.dist_dir):
190-
info('Saving distribution info')
191-
with open('dist_info.json', 'w') as fileh:
192-
json.dump({'dist_name': self.name,
193-
'archs': [arch.arch for arch in self.ctx.archs],
194-
'recipes': self.ctx.recipe_build_order},
195-
fileh)
196-
197-
def load_info(self):
198-
'''Load information about the dist from the info file that p4a
199-
automatically creates.'''
200-
with current_directory(self.dist_dir):
201-
filen = 'dist_info.json'
202-
if not exists(filen):
203-
return None
204-
with open('dist_info.json', 'r') as fileh:
205-
dist_info = json.load(fileh)
206-
return dist_info
185+
# def save_info(self):
186+
# '''
187+
# Save information about the distribution in its dist_dir.
188+
# '''
189+
# with current_directory(self.dist_dir):
190+
# info('Saving distribution info')
191+
# with open('dist_info.json', 'w') as fileh:
192+
# json.dump({'dist_name': self.name,
193+
# 'archs': [arch.arch for arch in self.ctx.archs],
194+
# 'ndk_api': self.ctx.ndk_api,
195+
# 'recipes': self.ctx.recipe_build_order},
196+
# fileh)
197+
198+
# def load_info(self):
199+
# '''Load information about the dist from the info file that p4a
200+
# automatically creates.'''
201+
# with current_directory(self.dist_dir):
202+
# filen = 'dist_info.json'
203+
# if not exists(filen):
204+
# return None
205+
# with open('dist_info.json', 'r') as fileh:
206+
# dist_info = json.load(fileh)
207+
# return dist_info
207208

208209

209210
def pretty_log_dists(dists, log_func=info):

0 commit comments

Comments
 (0)