Skip to content

Commit 59f97d0

Browse files
str4dinclement
authored andcommitted
Generate project.properties for bootstraps with configured target Android API
1 parent dab2a8a commit 59f97d0

File tree

6 files changed

+41
-89
lines changed

6 files changed

+41
-89
lines changed

pythonforandroid/bootstraps/pygame/build/default.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

pythonforandroid/bootstraps/sdl2/build/default.properties

Lines changed: 0 additions & 11 deletions
This file was deleted.

pythonforandroid/bootstraps/sdl2/build/project.properties

Lines changed: 0 additions & 14 deletions
This file was deleted.

pythonforandroid/bootstraps/sdl2python3/build/default.properties

Lines changed: 0 additions & 11 deletions
This file was deleted.

pythonforandroid/bootstraps/sdl2python3/build/project.properties

Lines changed: 0 additions & 14 deletions
This file was deleted.

pythonforandroid/toolchain.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def is_exe(fpath):
206206
return exe_file
207207

208208
return None
209-
210-
209+
210+
211211
@contextlib.contextmanager
212212
def current_directory(new_dir):
213213
cur_dir = getcwd()
@@ -218,7 +218,7 @@ def current_directory(new_dir):
218218
logger.info(''.join((Fore.CYAN, '<- directory context ', cur_dir,
219219
Fore.RESET)))
220220
chdir(cur_dir)
221-
221+
222222

223223

224224
def cache_execution(f):
@@ -328,9 +328,9 @@ def get_env(self):
328328
env["CFLAGS"] = " ".join([
329329
"-DANDROID", "-mandroid", "-fomit-frame-pointer",
330330
"--sysroot", self.ctx.ndk_platform])
331-
331+
332332
env["CXXFLAGS"] = env["CFLAGS"]
333-
333+
334334
env["LDFLAGS"] = " ".join(['-lm'])
335335

336336
py_platform = sys.platform
@@ -367,7 +367,7 @@ def get_env(self):
367367
env['READELF'] = '{}-readelf'.format(toolchain_prefix)
368368

369369
hostpython_recipe = Recipe.get_recipe('hostpython2', self.ctx)
370-
370+
371371
# AND: This hardcodes python version 2.7, needs fixing
372372
# AND: This also hardcodes armeabi, which isn't even correct, don't forget to fix!
373373
env['BUILDLIB_PATH'] = join(hostpython_recipe.get_build_dir('armeabi'),
@@ -417,7 +417,7 @@ class ArchAndroid(Arch):
417417
# triple = "aarch64-apple-darwin13"
418418
# version_min = "-miphoneos-version-min=7.0"
419419
# sysroot = sh.xcrun("--sdk", "iphoneos", "--show-sdk-path").strip()
420-
420+
421421

422422
class Graph(object):
423423
# Taken from the old python-for-android/depsort
@@ -665,7 +665,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
665665
if sdk_dir is None: # This is the old P4A-specific var
666666
sdk_dir = environ.get('ANDROIDSDK', None)
667667
if sdk_dir is None: # This seems used more conventionally
668-
sdk_dir = environ.get('ANDROID_HOME', None)
668+
sdk_dir = environ.get('ANDROID_HOME', None)
669669
if sdk_dir is None: # Checks in the buildozer SDK dir, useful
670670
# for debug tests of p4a
671671
possible_dirs = glob.glob(expanduser(join(
@@ -682,7 +682,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
682682
warning('Android SDK dir was not specified, exiting.')
683683
exit(1)
684684
self.sdk_dir = realpath(sdk_dir)
685-
685+
686686
# Check what Android API we're using
687687
android_api = None
688688
if user_android_api:
@@ -913,7 +913,7 @@ def __init__(self):
913913
self.archs = (
914914
ArchAndroid(self),
915915
)
916-
916+
917917
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
918918
ensure_dir(join(self.build_dir, 'other_builds')) # where everything else is built
919919

@@ -1013,7 +1013,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10131013
extra_dist_dirs : list
10141014
Any extra directories in which to search for dists.
10151015
require_perfect_match : bool
1016-
If True, will only match distributions with precisely the
1016+
If True, will only match distributions with precisely the
10171017
correct set of recipes.
10181018
'''
10191019

@@ -1022,7 +1022,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10221022
# possibilities
10231023

10241024
existing_dists = Distribution.get_distributions(ctx)
1025-
1025+
10261026
needs_build = True # whether the dist needs building, will be returned
10271027

10281028
possible_dists = existing_dists
@@ -1047,7 +1047,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10471047
pretty_log_dists(possible_dists)
10481048
else:
10491049
info('No existing dists meet the given requirements!')
1050-
1050+
10511051

10521052
# If any dist has perfect recipes, return it
10531053
for dist in possible_dists:
@@ -1073,7 +1073,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10731073
# 'sdl2_mixer', 'sdl2_ttf',
10741074
# 'python2', 'sdl2',
10751075
# 'pyjniussdl2', 'kivysdl2'],
1076-
# 'https://github.com/inclement/sdl2-example-dist/archive/master.zip'),
1076+
# 'https://github.com/inclement/sdl2-example-dist/archive/master.zip'),
10771077
# ]
10781078
# _possible_dists = []
10791079
# for dist_name, dist_recipes, dist_url in online_dists:
@@ -1086,7 +1086,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10861086
# dist.url = dist_url
10871087
# _possible_dists.append(dist)
10881088
# # if _possible_dists
1089-
1089+
10901090

10911091
# If we got this far, we need to build a new dist
10921092
dist = Distribution(ctx)
@@ -1180,7 +1180,7 @@ class Bootstrap(object):
11801180
satisfies user requirements. If False, it will not be returned
11811181
from Bootstrap.get_bootstrap_from_recipes.
11821182
'''
1183-
1183+
11841184
# Other things a Bootstrap might need to track (maybe separately):
11851185
# ndk_main.c
11861186
# whitelist.txt
@@ -1194,7 +1194,7 @@ def dist_dir(self):
11941194
'is None'.format(self, self))
11951195
exit(1)
11961196
return self.distribution.dist_dir
1197-
1197+
11981198

11991199
@property
12001200
def jni_dir(self):
@@ -1221,6 +1221,9 @@ def prepare_build_dir(self):
12211221
# 'bootstrap_templates',
12221222
# self.name),
12231223
self.build_dir)
1224+
with current_directory(self.build_dir):
1225+
with open('project.properties', 'w') as fileh:
1226+
fileh.write('target=android-{}'.format(self.ctx.android_api))
12241227

12251228
def prepare_dist_dir(self, name):
12261229
# self.dist_dir = self.get_dist_dir(name)
@@ -1646,7 +1649,7 @@ def unpack(self, arch):
16461649
return
16471650

16481651
filename = shprint(sh.basename, self.versioned_url).stdout[:-1].decode('utf-8')
1649-
1652+
16501653
# AND: TODO: Use tito's better unpacking method
16511654
with current_directory(build_dir):
16521655
directory_name = self.get_build_dir(arch)
@@ -1806,8 +1809,8 @@ def clean_build(self, arch=None):
18061809
else:
18071810
warning(('Attempted to clean build for {} but build'
18081811
'did not exist').format(self.name))
1809-
1810-
1812+
1813+
18111814

18121815
@classmethod
18131816
def list_recipes(cls):
@@ -1885,7 +1888,7 @@ def get_jni_dir(self):
18851888
# info_main('Unpacking {} for {}'.format(self.name, arch))
18861889
# info('{} is included in the bootstrap, unpacking currently '
18871890
# 'unnecessary, so skipping'.format(self.name))
1888-
1891+
18891892

18901893
class PythonRecipe(Recipe):
18911894
site_packages_name = None # The name of the module in
@@ -1905,9 +1908,9 @@ def should_build(self):
19051908
return False
19061909
info('{} apparently isn\'t already in site-packages'.format(name))
19071910
return True
1908-
19091911

1910-
1912+
1913+
19111914
def build_arch(self, arch):
19121915
'''Install the Python module by calling setup.py install with
19131916
the target Python dir.'''
@@ -1952,15 +1955,15 @@ def build_arch(self, arch):
19521955

19531956
def build_compiled_components(self, arch):
19541957
info('Building compiled components in {}'.format(self.name))
1955-
1958+
19561959
env = self.get_recipe_env(arch)
19571960
with current_directory(self.get_build_dir(arch.arch)):
19581961
hostpython = sh.Command(self.ctx.hostpython)
19591962
shprint(hostpython, 'setup.py', 'build_ext', '-v')
19601963
build_dir = glob.glob('build/lib.*')[0]
19611964
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
19621965
env['STRIP'], '{}', ';', _env=env)
1963-
1966+
19641967

19651968
class CythonRecipe(PythonRecipe):
19661969
pre_build_ext = False
@@ -2006,7 +2009,7 @@ def build_cython_components(self, arch):
20062009
env['STRIP'], '{}', ';', _env=env)
20072010
print('stripped!?')
20082011
# exit(1)
2009-
2012+
20102013
# def cythonize_file(self, filename):
20112014
# if filename.startswith(self.build_dir):
20122015
# filename = filename[len(self.build_dir) + 1:]
@@ -2087,7 +2090,7 @@ def build_recipes(build_order, python_modules, ctx):
20872090
info('{} said it is already built, skipping'.format(recipe.name))
20882091

20892092
# 4) biglink everything
2090-
# AND: Should make this optional (could use
2093+
# AND: Should make this optional (could use
20912094
info_main('# Biglinking object files')
20922095
biglink(ctx, arch)
20932096

@@ -2099,7 +2102,7 @@ def build_recipes(build_order, python_modules, ctx):
20992102

21002103
info_main('# Installing pure Python modules')
21012104
run_pymodules_install(ctx, python_modules)
2102-
2105+
21032106
return
21042107

21052108
def run_pymodules_install(ctx, modules):
@@ -2130,7 +2133,7 @@ def run_pymodules_install(ctx, modules):
21302133
shprint(sh.bash, '-c', (
21312134
"source venv/bin/activate && env CC=/bin/false CXX=/bin/false"
21322135
"PYTHONPATH= pip install --target '{}' -r requirements.txt").format(ctx.get_site_packages_dir()))
2133-
2136+
21342137
def biglink(ctx, arch):
21352138
# First, collate object files from each recipe
21362139
info('Collating object files from each recipe')
@@ -2149,7 +2152,7 @@ def biglink(ctx, arch):
21492152
info('{} recipe has object files, copying'.format(recipe.name))
21502153
files.append(obj_dir)
21512154
shprint(sh.cp, '-r', *files)
2152-
2155+
21532156
# AND: Shouldn't hardcode ArchAndroid! In reality need separate
21542157
# build dirs for each arch
21552158
arch = ArchAndroid(ctx)
@@ -2207,7 +2210,7 @@ def biglink_function(soname, objs_paths, extra_link_dirs=[], env=None):
22072210
link = '-L{}'.format(dir)
22082211
if link not in unique_args:
22092212
unique_args.append(link)
2210-
2213+
22112214
# print('Biglink create %s library' % soname)
22122215
# print('Biglink arguments:')
22132216
# for arg in unique_args:
@@ -2450,10 +2453,10 @@ def __init__(self):
24502453
'perfectly match those requested.'),
24512454
type=bool, default=False)
24522455

2453-
2456+
24542457
args, unknown = parser.parse_known_args(sys.argv[1:])
24552458
self.dist_args = args
2456-
2459+
24572460
if args.debug:
24582461
logger.setLevel(logging.DEBUG)
24592462
self.sdk_dir = args.sdk_dir
@@ -2476,7 +2479,7 @@ def __init__(self):
24762479
# warning('Received --allow_build but this arg currently is not '
24772480
# 'handled, exiting.')
24782481
# exit(1)
2479-
2482+
24802483
if not hasattr(self, args.command):
24812484
print('Unrecognized command')
24822485
parser.print_help()
@@ -2562,7 +2565,7 @@ def clean_dists(self, args):
25622565
ctx = Context()
25632566
if exists(ctx.dist_dir):
25642567
shutil.rmtree(ctx.dist_dir)
2565-
2568+
25662569
def clean_builds(self, args):
25672570
'''Delete all build caches for each recipe, python-install, java code
25682571
and compiled libs collection.
@@ -2602,7 +2605,7 @@ def clean_recipe_build(self, args):
26022605
recipe = Recipe.get_recipe(args.recipe, self.ctx)
26032606
info('Cleaning build for {} recipe.'.format(recipe.name))
26042607
recipe.clean_build()
2605-
2608+
26062609

26072610
def clean_download_cache(self, args):
26082611

@@ -2720,7 +2723,7 @@ def apk(self, args):
27202723
info('More than one built APK found...guessing you '
27212724
'just built {}'.format(apks[-1]))
27222725
shprint(sh.cp, apks[-1], './')
2723-
2726+
27242727

27252728
@require_prebuilt_dist
27262729
def create(self, args):
@@ -2799,7 +2802,7 @@ def sdk_tools(self, args):
27992802
for line in output:
28002803
sys.stdout.write(line)
28012804
sys.stdout.flush()
2802-
2805+
28032806
def adb(self, args):
28042807
'''Runs the adb binary from the detected SDK directory, passing all
28052808
arguments straight to it. This is intended as a convenience

0 commit comments

Comments
 (0)