Skip to content

Commit 96469e2

Browse files
committed
Generate project.properties for bootstraps with configured target Android API
1 parent 21acd88 commit 96469e2

File tree

6 files changed

+43
-91
lines changed

6 files changed

+43
-91
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: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ def is_exe(fpath):
205205
return exe_file
206206

207207
return None
208-
209-
208+
209+
210210
@contextlib.contextmanager
211211
def current_directory(new_dir):
212212
cur_dir = getcwd()
@@ -217,7 +217,7 @@ def current_directory(new_dir):
217217
logger.info(''.join((Fore.CYAN, '<- directory context ', cur_dir,
218218
Fore.RESET)))
219219
chdir(cur_dir)
220-
220+
221221

222222

223223
def cache_execution(f):
@@ -327,9 +327,9 @@ def get_env(self):
327327
env["CFLAGS"] = " ".join([
328328
"-DANDROID", "-mandroid", "-fomit-frame-pointer",
329329
"--sysroot", self.ctx.ndk_platform])
330-
330+
331331
env["CXXFLAGS"] = env["CFLAGS"]
332-
332+
333333
env["LDFLAGS"] = " ".join(['-lm'])
334334

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

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

421421
class Graph(object):
422422
# Taken from the old python-for-android/depsort
@@ -664,7 +664,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
664664
if sdk_dir is None: # This is the old P4A-specific var
665665
sdk_dir = environ.get('ANDROIDSDK', None)
666666
if sdk_dir is None: # This seems used more conventionally
667-
sdk_dir = environ.get('ANDROID_HOME', None)
667+
sdk_dir = environ.get('ANDROID_HOME', None)
668668
if sdk_dir is None: # Checks in the buildozer SDK dir, useful
669669
# for debug tests of p4a
670670
possible_dirs = glob.glob(expanduser(join(
@@ -681,7 +681,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
681681
warning('Android SDK dir was not specified, exiting.')
682682
exit(1)
683683
self.sdk_dir = realpath(sdk_dir)
684-
684+
685685
# Check what Android API we're using
686686
android_api = None
687687
if user_android_api:
@@ -799,7 +799,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
799799
if not exists(self.ndk_platform):
800800
warning('ndk_platform doesn\'t exist')
801801
ok = False
802-
802+
803803
virtualenv = None
804804
if virtualenv is None:
805805
virtualenv = sh.which('virtualenv2')
@@ -826,7 +826,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
826826
if not self.cython:
827827
ok = False
828828
warning("Missing requirement: cython is not installed")
829-
829+
830830
# Modify the path so that sh finds modules appropriately
831831
py_platform = sys.platform
832832
if py_platform in ['linux2', 'linux3']:
@@ -890,7 +890,7 @@ def __init__(self):
890890
self.archs = (
891891
ArchAndroid(self),
892892
)
893-
893+
894894
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
895895
ensure_dir(join(self.build_dir, 'other_builds')) # where everything else is built
896896

@@ -990,7 +990,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
990990
extra_dist_dirs : list
991991
Any extra directories in which to search for dists.
992992
require_perfect_match : bool
993-
If True, will only match distributions with precisely the
993+
If True, will only match distributions with precisely the
994994
correct set of recipes.
995995
'''
996996

@@ -999,7 +999,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
999999
# possibilities
10001000

10011001
existing_dists = Distribution.get_distributions(ctx)
1002-
1002+
10031003
needs_build = True # whether the dist needs building, will be returned
10041004

10051005
possible_dists = existing_dists
@@ -1024,7 +1024,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10241024
pretty_log_dists(possible_dists)
10251025
else:
10261026
info('No existing dists meet the given requirements!')
1027-
1027+
10281028

10291029
# If any dist has perfect recipes, return it
10301030
for dist in possible_dists:
@@ -1050,7 +1050,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10501050
# 'sdl2_mixer', 'sdl2_ttf',
10511051
# 'python2', 'sdl2',
10521052
# 'pyjniussdl2', 'kivysdl2'],
1053-
# 'https://github.com/inclement/sdl2-example-dist/archive/master.zip'),
1053+
# 'https://github.com/inclement/sdl2-example-dist/archive/master.zip'),
10541054
# ]
10551055
# _possible_dists = []
10561056
# for dist_name, dist_recipes, dist_url in online_dists:
@@ -1063,7 +1063,7 @@ def get_distribution(cls, ctx, name=None, recipes=[], allow_download=True,
10631063
# dist.url = dist_url
10641064
# _possible_dists.append(dist)
10651065
# # if _possible_dists
1066-
1066+
10671067

10681068
# If we got this far, we need to build a new dist
10691069
dist = Distribution(ctx)
@@ -1157,7 +1157,7 @@ class Bootstrap(object):
11571157
satisfies user requirements. If False, it will not be returned
11581158
from Bootstrap.get_bootstrap_from_recipes.
11591159
'''
1160-
1160+
11611161
# Other things a Bootstrap might need to track (maybe separately):
11621162
# ndk_main.c
11631163
# whitelist.txt
@@ -1171,7 +1171,7 @@ def dist_dir(self):
11711171
'is None'.format(self, self))
11721172
exit(1)
11731173
return self.distribution.dist_dir
1174-
1174+
11751175

11761176
@property
11771177
def jni_dir(self):
@@ -1198,6 +1198,9 @@ def prepare_build_dir(self):
11981198
# 'bootstrap_templates',
11991199
# self.name),
12001200
self.build_dir)
1201+
with current_directory(self.build_dir):
1202+
with open('project.properties', 'w') as fileh:
1203+
fileh.write('target=android-{}'.format(self.ctx.android_api))
12011204

12021205
def prepare_dist_dir(self, name):
12031206
# self.dist_dir = self.get_dist_dir(name)
@@ -1598,7 +1601,7 @@ def unpack(self, arch):
15981601
return
15991602

16001603
filename = shprint(sh.basename, self.versioned_url).stdout[:-1].decode('utf-8')
1601-
1604+
16021605
# AND: TODO: Use tito's better unpacking method
16031606
with current_directory(build_dir):
16041607
directory_name = self.get_build_dir(arch)
@@ -1750,8 +1753,8 @@ def clean_build(self, arch=None):
17501753
else:
17511754
warning(('Attempted to clean build for {} but build'
17521755
'did not exist').format(self.name))
1753-
1754-
1756+
1757+
17551758

17561759
@classmethod
17571760
def list_recipes(cls):
@@ -1829,7 +1832,7 @@ def get_jni_dir(self):
18291832
# info_main('Unpacking {} for {}'.format(self.name, arch))
18301833
# info('{} is included in the bootstrap, unpacking currently '
18311834
# 'unnecessary, so skipping'.format(self.name))
1832-
1835+
18331836

18341837
class PythonRecipe(Recipe):
18351838
site_packages_name = None # The name of the module in
@@ -1849,9 +1852,9 @@ def should_build(self):
18491852
return False
18501853
info('{} apparently isn\'t already in site-packages'.format(name))
18511854
return True
1852-
18531855

1854-
1856+
1857+
18551858
def build_arch(self, arch):
18561859
'''Install the Python module by calling setup.py install with
18571860
the target Python dir.'''
@@ -1896,15 +1899,15 @@ def build_arch(self, arch):
18961899

18971900
def build_compiled_components(self, arch):
18981901
info('Building compiled components in {}'.format(self.name))
1899-
1902+
19001903
env = self.get_recipe_env(arch)
19011904
with current_directory(self.get_build_dir(arch.arch)):
19021905
hostpython = sh.Command(self.ctx.hostpython)
19031906
shprint(hostpython, 'setup.py', 'build_ext', '-v')
19041907
build_dir = glob.glob('build/lib.*')[0]
19051908
shprint(sh.find, build_dir, '-name', '"*.o"', '-exec',
19061909
env['STRIP'], '{}', ';', _env=env)
1907-
1910+
19081911

19091912
class CythonRecipe(PythonRecipe):
19101913
pre_build_ext = False
@@ -1950,7 +1953,7 @@ def build_cython_components(self, arch):
19501953
env['STRIP'], '{}', ';', _env=env)
19511954
print('stripped!?')
19521955
# exit(1)
1953-
1956+
19541957
# def cythonize_file(self, filename):
19551958
# if filename.startswith(self.build_dir):
19561959
# filename = filename[len(self.build_dir) + 1:]
@@ -2031,7 +2034,7 @@ def build_recipes(build_order, python_modules, ctx):
20312034
info('{} said it is already built, skipping'.format(recipe.name))
20322035

20332036
# 4) biglink everything
2034-
# AND: Should make this optional (could use
2037+
# AND: Should make this optional (could use
20352038
info_main('# Biglinking object files')
20362039
biglink(ctx, arch)
20372040

@@ -2043,7 +2046,7 @@ def build_recipes(build_order, python_modules, ctx):
20432046

20442047
info_main('# Installing pure Python modules')
20452048
run_pymodules_install(ctx, python_modules)
2046-
2049+
20472050
return
20482051

20492052
def run_pymodules_install(ctx, modules):
@@ -2074,7 +2077,7 @@ def run_pymodules_install(ctx, modules):
20742077
shprint(sh.bash, '-c', (
20752078
"source venv/bin/activate && env CC=/bin/false CXX=/bin/false"
20762079
"PYTHONPATH= pip install --target '{}' -r requirements.txt").format(ctx.get_site_packages_dir()))
2077-
2080+
20782081
def biglink(ctx, arch):
20792082
# First, collate object files from each recipe
20802083
info('Collating object files from each recipe')
@@ -2093,7 +2096,7 @@ def biglink(ctx, arch):
20932096
info('{} recipe has object files, copying'.format(recipe.name))
20942097
files.append(obj_dir)
20952098
shprint(sh.cp, '-r', *files)
2096-
2099+
20972100
# AND: Shouldn't hardcode ArchAndroid! In reality need separate
20982101
# build dirs for each arch
20992102
arch = ArchAndroid(ctx)
@@ -2151,7 +2154,7 @@ def biglink_function(soname, objs_paths, extra_link_dirs=[], env=None):
21512154
link = '-L{}'.format(dir)
21522155
if link not in unique_args:
21532156
unique_args.append(link)
2154-
2157+
21552158
# print('Biglink create %s library' % soname)
21562159
# print('Biglink arguments:')
21572160
# for arg in unique_args:
@@ -2394,10 +2397,10 @@ def __init__(self):
23942397
'perfectly match those requested.'),
23952398
type=bool, default=False)
23962399

2397-
2400+
23982401
args, unknown = parser.parse_known_args(sys.argv[1:])
23992402
self.dist_args = args
2400-
2403+
24012404
if args.debug:
24022405
logger.setLevel(logging.DEBUG)
24032406
self.sdk_dir = args.sdk_dir
@@ -2420,7 +2423,7 @@ def __init__(self):
24202423
# warning('Received --allow_build but this arg currently is not '
24212424
# 'handled, exiting.')
24222425
# exit(1)
2423-
2426+
24242427
if not hasattr(self, args.command):
24252428
print('Unrecognized command')
24262429
parser.print_help()
@@ -2506,7 +2509,7 @@ def clean_dists(self, args):
25062509
ctx = Context()
25072510
if exists(ctx.dist_dir):
25082511
shutil.rmtree(ctx.dist_dir)
2509-
2512+
25102513
def clean_builds(self, args):
25112514
'''Delete all build caches for each recipe, python-install, java code
25122515
and compiled libs collection.
@@ -2546,7 +2549,7 @@ def clean_recipe_build(self, args):
25462549
recipe = Recipe.get_recipe(args.recipe, self.ctx)
25472550
info('Cleaning build for {} recipe.'.format(recipe.name))
25482551
recipe.clean_build()
2549-
2552+
25502553

25512554
def clean_download_cache(self, args):
25522555

@@ -2664,7 +2667,7 @@ def apk(self, args):
26642667
info('More than one built APK found...guessing you '
26652668
'just built {}'.format(apks[-1]))
26662669
shprint(sh.cp, apks[-1], './')
2667-
2670+
26682671

26692672
@require_prebuilt_dist
26702673
def create(self, args):
@@ -2743,7 +2746,7 @@ def sdk_tools(self, args):
27432746
for line in output:
27442747
sys.stdout.write(line)
27452748
sys.stdout.flush()
2746-
2749+
27472750
def adb(self, args):
27482751
'''Runs the adb binary from the detected SDK directory, passing all
27492752
arguments straight to it. This is intended as a convenience

0 commit comments

Comments
 (0)