Skip to content

Commit 9838eab

Browse files
committed
Changed toolchain to use per-build paths
Now the libs dir, python-install and javaclass dirs are all per-build
1 parent 519092f commit 9838eab

File tree

4 files changed

+93
-57
lines changed

4 files changed

+93
-57
lines changed

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ def run_distribute(self):
3030

3131
hostpython = sh.Command(self.ctx.hostpython)
3232
# AND: This *doesn't* need to be in arm env?
33-
shprint(hostpython, '-OO', '-m', 'compileall', join(self.ctx.build_dir, 'python-install'))
33+
shprint(hostpython, '-OO', '-m', 'compileall',
34+
self.ctx.get_python_install_dir())
3435
if not exists('python-install'):
35-
shprint(sh.cp, '-a', join(self.ctx.build_dir, 'python-install'), '.')
36+
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
3637

3738
info('Copying libs')
3839
# AND: Hardcoding armeabi - naughty!
3940
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
40-
for lib in glob.glob(join(self.ctx.libs_dir, '*')):
41+
for lib in glob.glob(join(self.ctx.get_libs_dir('armeabi'), '*')):
4142
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
4243

4344
info('Copying java files')
44-
for filename in glob.glob(join(self.ctx.build_dir, 'java', '*')):
45+
for filename in glob.glob(self.ctx.javaclass_dir):
4546
shprint(sh.cp, '-a', filename, 'src')
4647

4748
info('Filling private directory')

pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1212
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
1313
start.c
1414

15-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../python-install/include/python2.7
15+
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/include/python2.7
1616

1717
LOCAL_SHARED_LIBRARIES := SDL2
1818

1919
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -lpython2.7
2020

21-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
21+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
2222

2323
include $(BUILD_SHARED_LIBRARY)

pythonforandroid/recipes/python2/__init__.py

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchAndroid
3-
from os.path import exists, join
2+
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchAndroid, info
3+
from os.path import exists, join, realpath
44
from os import uname
55
import glob
66
import sh
77

8+
89
class Python2Recipe(Recipe):
910
version = "2.7.2"
1011
url = 'http://python.org/ftp/python/{version}/Python-{version}.tar.bz2'
@@ -40,6 +41,35 @@ def prebuild_armeabi(self):
4041
shprint(sh.touch, join(build_dir, '.patched'))
4142

4243
def build_armeabi(self):
44+
45+
if not exists(join(self.get_build_dir('armeabi'), 'libpython2.7.so')):
46+
self.do_python_build()
47+
48+
if not exists(self.ctx.get_python_install_dir()):
49+
shprint(sh.cp, '-a', join(self.get_build_dir('armeabi'), 'python-install'),
50+
self.ctx.get_python_install_dir())
51+
52+
# This should be safe to run every time
53+
info('Copying hostpython binary to targetpython folder')
54+
shprint(sh.cp, self.ctx.hostpython,
55+
join(self.ctx.get_python_install_dir(), 'bin', 'python.host'))
56+
self.ctx.hostpython = join(self.ctx.get_python_install_dir(), 'bin', 'python.host')
57+
58+
if not exists(join(self.ctx.get_libs_dir('armeabi'), 'libpython2.7.so')):
59+
shprint(sh.cp, join(self.get_build_dir('armeabi'), 'libpython2.7.so'), self.ctx.get_libs_dir('armeabi'))
60+
61+
62+
# # if exists(join(self.get_build_dir('armeabi'), 'libpython2.7.so')):
63+
# if exists(join(self.ctx.libs_dir, 'libpython2.7.so')):
64+
# info('libpython2.7.so already exists, skipping python build.')
65+
# if not exists(join(self.ctx.get_python_install_dir(), 'libpython2.7.so')):
66+
# info('Copying python-install to dist-dependent location')
67+
# shprint(sh.cp, '-a', 'python-install', self.ctx.get_python_install_dir())
68+
# self.ctx.hostpython = join(self.ctx.get_python_install_dir(), 'bin', 'python.host')
69+
70+
# return
71+
72+
def do_python_build(self):
4373
if 'sqlite' in self.ctx.recipe_build_order or 'openssl' in self.ctx.recipe_build_order:
4474
print('sqlite or openssl support not yet enabled in python recipe')
4575
exit(1)
@@ -50,15 +80,6 @@ def build_armeabi(self):
5080
hostpython = join(self.get_build_dir('armeabi'), 'hostpython')
5181
hostpgen = join(self.get_build_dir('armeabi'), 'hostpython')
5282

53-
# ctypes: Need to set buildarch?
54-
55-
if exists(join(self.get_build_dir('armeabi'), 'libpython2.7.so')):
56-
print('libpython2.7.so already exists, skipping python build.')
57-
self.ctx.hostpython = join(self.ctx.build_dir, 'python-install',
58-
'bin', 'python.host')
59-
60-
return
61-
6283
with current_directory(self.get_build_dir('armeabi')):
6384

6485

@@ -80,10 +101,10 @@ def build_armeabi(self):
80101
'--host={}'.format(env['HOSTARCH']),
81102
'--build={}'.format(env['BUILDARCH']),
82103
# 'OPT={}'.format(env['OFLAG']),
83-
'--prefix={}'.format(join(self.ctx.build_dir, 'python-install')),
104+
'--prefix={}'.format(realpath('./python-install')),
84105
'--enable-shared',
85106
'--disable-toolbox-glue',
86-
'--disable-framefork',
107+
'--disable-framework',
87108
_env=env)
88109

89110
# AND: tito left this comment in the original source. It's still true!
@@ -115,32 +136,30 @@ def build_armeabi(self):
115136

116137
if uname()[0] == 'Darwin':
117138
shprint(sh.cp, join(self.get_recipe_dir(), 'patches', '_scproxy.py'),
118-
join(self.get_build_dir(), 'Lib'))
139+
join('python-install', 'Lib'))
119140
shprint(sh.cp, join(self.get_recipe_dir(), 'patches', '_scproxy.py'),
120-
join(self.ctx.build_dir, 'python-install', 'lib', 'python2.7'))
121-
122-
print('Ready to copy .so for python arm')
123-
shprint(sh.cp, 'libpython2.7.so', self.ctx.libs_dir)
124-
# for filen in glob.glob('build/lib.*-2.7/_ctypes*.so'):
125-
# shprint(sh.cp, '-a', filen, self.ctx.libs_dir)
126-
127-
print('Copying hostpython binary to targetpython folder')
128-
shprint(sh.cp, self.ctx.hostpython,
129-
join(self.ctx.build_dir, 'python-install', 'bin',
130-
'python.host'))
131-
self.ctx.hostpython = join(self.ctx.build_dir, 'python-install',
132-
'bin', 'python.host')
133-
141+
join('python-install', 'lib', 'python2.7'))
134142

135-
# reduce python?
143+
# reduce python
136144
for dir_name in ('test', join('json', 'tests'), 'lib-tk',
137145
join('sqlite3', 'test'), join('unittest, test'),
138146
join('lib2to3', 'tests'), join('bsddb', 'tests'),
139147
join('distutils', 'tests'), join('email', 'test'),
140148
'curses'):
141-
shprint(sh.rm, '-rf', join(self.ctx.build_dir, 'python-install',
149+
shprint(sh.rm, '-rf', join('python-install',
142150
'lib', 'python2.7', dir_name))
143151

152+
153+
# info('Copying python-install to dist-dependent location')
154+
# shprint(sh.cp, '-a', 'python-install', self.ctx.get_python_install_dir())
155+
156+
# print('Copying hostpython binary to targetpython folder')
157+
# shprint(sh.cp, self.ctx.hostpython,
158+
# join(self.ctx.get_python_install_dir(), 'bin', 'python.host'))
159+
# self.ctx.hostpython = join(self.ctx.get_python_install_dir(), 'bin', 'python.host')
160+
161+
162+
144163
# print('python2 build done, exiting for debug')
145164
# exit(1)
146165

pythonforandroid/toolchain.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -479,24 +479,44 @@ def packages_path(self):
479479
def templates_dir(self):
480480
return join(self.root_dir, 'templates')
481481

482+
@property
483+
def libs_dir(self):
484+
# Was previously hardcoded as self.build_dir/libs
485+
dir = join(self.build_dir, 'libs_collections', self.bootstrap.distribution.name)
486+
ensure_dir(dir)
487+
return dir
488+
489+
@property
490+
def javaclass_dir(self):
491+
# Was previously hardcoded as self.build_dir/java
492+
dir = join(self.build_dir, 'javaclasses', self.bootstrap.distribution.name)
493+
ensure_dir(dir)
494+
return dir
495+
496+
@property
497+
def python_installs_dir(self):
498+
dir = join(self.build_dir, 'python-installs')
499+
ensure_dir(dir)
500+
return dir
501+
502+
def get_python_install_dir(self):
503+
dir = join(self.python_installs_dir, self.bootstrap.distribution.name)
504+
return dir
505+
482506
def setup_dirs(self):
483507
'''Calculates all the storage and build dirs, and makes sure
484508
the directories exist where necessary.'''
485509
self.root_dir = realpath(dirname(__file__))
486510

487511
# AND: TODO: Allow the user to set the build_dir
488512
self.storage_dir = user_data_dir('python-for-android')
489-
# self.storage_dir = self.root_dir
490513
self.build_dir = join(self.storage_dir, 'build')
491-
self.libs_dir = join(self.build_dir, 'libs')
492514
self.dist_dir = join(self.storage_dir, 'dists')
493-
self.javaclass_dir = join(self.build_dir, 'java')
494515

495516
ensure_dir(self.storage_dir)
496517
ensure_dir(self.build_dir)
497-
ensure_dir(self.libs_dir)
498518
ensure_dir(self.dist_dir)
499-
ensure_dir(self.javaclass_dir)
519+
500520

501521
@property
502522
def android_api(self):
@@ -806,8 +826,7 @@ def get_site_packages_dir(self, arch=None):
806826
# AND: This *must* be replaced with something more general in
807827
# order to support multiple python versions and/or multiple
808828
# archs.
809-
return join(self.build_dir, 'python-install', 'lib', 'python2.7',
810-
'site-packages')
829+
return join(self.get_python_install_dir(), 'lib', 'python2.7', 'site-packages')
811830

812831
def get_libs_dir(self, arch):
813832
'''The libs dir for a given arch.'''
@@ -1929,14 +1948,10 @@ def biglink(ctx, arch):
19291948
info('There seem to be no libraries to biglink, skipping.')
19301949
return
19311950
info('Biglinking')
1932-
# bl = sh.Command(join(ctx.root_dir, 'tools', 'biglink'))
1933-
print('ldflags are', env['LDFLAGS'])
1934-
# shprint(bl, join(ctx.libs_dir, 'libpymodules.so'),
1935-
# env['LIBLINK_PATH'], _env=env)
1951+
info('target', join(ctx.get_libs_dir(arch.arch), 'libpymodules.so'))
19361952
biglink_function(
1937-
join(ctx.libs_dir, 'libpymodules.so'),
1953+
join(ctx.get_libs_dir(arch.arch), 'libpymodules.so'),
19381954
obj_dir.split(' '),
1939-
# env['LIBLINK_PATH'].split(' '), # AND: This line should be obselete now
19401955
extra_link_dirs=[join(ctx.bootstrap.build_dir, 'obj', 'local', 'armeabi')],
19411956
env=env)
19421957

@@ -1997,7 +2012,6 @@ def biglink_function(soname, objs_paths, extra_link_dirs=[], env=None):
19972012
# sys.exit(subprocess.call(args))
19982013

19992014

2000-
20012015
def ensure_dir(filename):
20022016
if not exists(filename):
20032017
makedirs(filename)
@@ -2219,12 +2233,9 @@ def clean_all(self, args):
22192233
description="Clean the build cache, downloads and dists")
22202234
args = parser.parse_args(args)
22212235
ctx = Context()
2222-
if exists(ctx.build_dir):
2223-
shutil.rmtree(ctx.build_dir)
2224-
if exists(ctx.dist_dir):
2225-
shutil.rmtree(ctx.dist_dir)
2226-
if exists(ctx.packages_path):
2227-
shutil.rmtree(ctx.packages_path)
2236+
self.clean_dists(args)
2237+
self.clean_builds(args)
2238+
self.clean_download_cache(args)
22282239

22292240
def clean_dists(self, args):
22302241
'''Delete all compiled distributions in the internal distribution
@@ -2235,7 +2246,7 @@ def clean_dists(self, args):
22352246
ctx = Context()
22362247
if exists(ctx.dist_dir):
22372248
shutil.rmtree(ctx.dist_dir)
2238-
2249+
22392250
def clean_builds(self, args):
22402251
'''Delete all build caches for each recipe.
22412252
@@ -2249,6 +2260,11 @@ def clean_builds(self, args):
22492260
# shutil.rmtree(ctx.dist_dir)
22502261
if exists(ctx.build_dir):
22512262
shutil.rmtree(ctx.build_dir)
2263+
if exists(ctx.python_installs_dir):
2264+
shutil.rmtree(ctx.python_installs_dir)
2265+
libs_dir = join(self.ctx.build_dir, 'libs_collections')
2266+
if exists(libs_dir):
2267+
shutil.rmtree(libs_dir)
22522268

22532269
def clean_download_cache(self, args):
22542270
'''

0 commit comments

Comments
 (0)