Skip to content

Commit 21f44d8

Browse files
committed
Got python3 recipe to the point of configure working
1 parent fb3c7d6 commit 21f44d8

File tree

4 files changed

+106
-19
lines changed

4 files changed

+106
-19
lines changed

pythonforandroid/recipe.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,13 @@ class PythonRecipe(Recipe):
711711
setup_extra_args = []
712712
'''List of extra arugments to pass to setup.py'''
713713

714+
def __init__(self, *args, **kwargs):
715+
super(PythonRecipe, self).__init__(*args, **kwargs)
716+
depends = self.depends
717+
depends.append(('python2', 'python3', 'python3crystax'))
718+
depends = list(set(depends))
719+
self.depends = depends
720+
714721
def clean_build(self, arch=None):
715722
super(PythonRecipe, self).clean_build(arch=arch)
716723
name = self.folder_name

pythonforandroid/recipes/hostpython3/__init__.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,32 @@ def get_build_dir(self, arch=None):
2323

2424
def build_arch(self, arch):
2525
recipe_build_dir = self.get_build_dir(arch.arch)
26-
with current_directory(recipe_build_dir):
27-
# Create a subdirectory to actually perform the build
28-
build_dir = join(recipe_build_dir, 'native-build')
29-
ensure_dir(build_dir)
3026

31-
env = {} # The command line environment we will use
27+
# Create a subdirectory to actually perform the build
28+
build_dir = join(recipe_build_dir, 'native-build')
29+
ensure_dir(build_dir)
3230

31+
if not exists(join(build_dir, 'python')):
32+
with current_directory(recipe_build_dir):
33+
env = {} # The command line environment we will use
3334

34-
# Configure the build
35-
with current_directory(build_dir):
36-
if not exists('config.status'):
37-
shprint(sh.Command(join(recipe_build_dir, 'configure')))
3835

39-
# Create the Setup file. This copying from Setup.dist
40-
# seems to be the normal and expected procedure.
41-
assert exists(join(build_dir, 'Modules')), (
42-
'Expected dir {} does not exist'.format(join(build_dir, 'Modules')))
43-
shprint(sh.cp, join('Modules', 'Setup.dist'), join(build_dir, 'Modules', 'Setup'))
36+
# Configure the build
37+
with current_directory(build_dir):
38+
if not exists('config.status'):
39+
shprint(sh.Command(join(recipe_build_dir, 'configure')))
4440

45-
result = shprint(sh.make, '-C', build_dir)
41+
# Create the Setup file. This copying from Setup.dist
42+
# seems to be the normal and expected procedure.
43+
assert exists(join(build_dir, 'Modules')), (
44+
'Expected dir {} does not exist'.format(join(build_dir, 'Modules')))
45+
shprint(sh.cp, join('Modules', 'Setup.dist'), join(build_dir, 'Modules', 'Setup'))
46+
47+
result = shprint(sh.make, '-C', build_dir)
48+
else:
49+
info('Skipping hostpython3 build as it has already been completed')
4650

4751
self.ctx.hostpython = join(build_dir, 'python')
4852
self.ctx.hostpgen = '/usr/bin/false' # is this actually used for anything?
4953

50-
print('result is', result)
51-
exit(1)
52-
5354
recipe = Hostpython3Recipe()

pythonforandroid/recipes/python3/__init__.py

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from pythonforandroid.toolchain import shprint, current_directory, info
33
from pythonforandroid.patching import (is_darwin, is_api_gt,
44
check_all, is_api_lt, is_ndk)
5+
from pythonforandroid.util import ensure_dir
56
from os.path import exists, join, realpath
7+
from os import environ
68
import sh
79

810

@@ -13,6 +15,82 @@ class Python3Recipe(TargetPythonRecipe):
1315

1416
depends = ['hostpython3']
1517
conflicts = ['python3crystax', 'python2']
16-
opt_depends = ['openssl', 'sqlite3']
18+
# opt_depends = ['openssl', 'sqlite3']
19+
20+
def build_arch(self, arch):
21+
recipe_build_dir = self.get_build_dir(arch.arch)
22+
23+
# Create a subdirectory to actually perform the build
24+
build_dir = join(recipe_build_dir, 'android-build')
25+
ensure_dir(build_dir)
26+
27+
# TODO: Get these dynamically, like bpo-30386 does
28+
sys_prefix = '/usr/local'
29+
sys_exec_prefix = '/usr/local'
30+
31+
# Skipping "Ensure that nl_langinfo is broken" from the original bpo-30386
32+
33+
with current_directory(build_dir):
34+
env = environ.copy()
35+
36+
37+
# TODO: Get this information from p4a's arch system
38+
android_host = 'arm-linux-androideabi'
39+
android_build = sh.Command(join(recipe_build_dir, 'config.guess'))().stdout.strip().decode('utf-8')
40+
platform_dir = join(self.ctx.ndk_dir, 'platforms', 'android-19', 'arch-arm')
41+
toolchain = '{android_host}-4.9'.format(android_host=android_host)
42+
toolchain = join(self.ctx.ndk_dir, 'toolchains', toolchain, 'prebuilt', 'linux-x86_64')
43+
CC = '{clang} -target {target} -gcc-toolchain {toolchain}'.format(
44+
clang=join(self.ctx.ndk_dir, 'toolchains', 'llvm', 'prebuilt', 'linux-x86_64', 'bin', 'clang'),
45+
target='armv7-none-linux-androideabi',
46+
toolchain=toolchain)
47+
48+
AR = join(toolchain, 'bin', android_host) + '-ar'
49+
LD = join(toolchain, 'bin', android_host) + '-ld'
50+
RANLIB = join(toolchain, 'bin', android_host) + '-ranlib'
51+
READELF = join(toolchain, 'bin', android_host) + '-readelf'
52+
STRIP = join(toolchain, 'bin', android_host) + '-strip --strip-debug --strip-unneeded'
53+
54+
env['CC'] = CC
55+
env['AR'] = AR
56+
env['LD'] = LD
57+
env['RANLIB'] = RANLIB
58+
env['READELF'] = READELF
59+
env['STRIP'] = STRIP
60+
61+
ndk_flags = '--sysroot={ndk_sysroot} -D__ANDROID_API__=19 -isystem {ndk_android_host}'.format(
62+
ndk_sysroot=join(self.ctx.ndk_dir, 'sysroot'),
63+
ndk_android_host=join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include', android_host))
64+
sysroot = join(self.ctx.ndk_dir, 'platforms', 'android-19', 'arch-arm')
65+
env['CFLAGS'] = env.get('CFLAGS', '') + ' ' + ndk_flags
66+
env['CPPFLAGS'] = env.get('CPPFLAGS', '') + ' ' + ndk_flags
67+
env['LDFLAGS'] = env.get('LDFLAGS', '') + ' --sysroot={} -march=armv7-a -Wl,--fix-cortex-a8'.format(sysroot)
68+
69+
print('CPPflags', env['CPPFLAGS'])
70+
print('LDFLAGS', env['LDFLAGS'])
71+
72+
print('LD is', env['LD'])
73+
74+
shprint(sh.Command(join(recipe_build_dir, 'configure')),
75+
*(' '.join(('--host={android_host}',
76+
'--build={android_build}',
77+
'--enable-shared',
78+
'--disable-ipv6',
79+
'ac_cv_file__dev_ptmx=yes',
80+
'ac_cv_file__dev_ptc=no',
81+
'--without-ensurepip',
82+
'ac_cv_little_endian_double=yes',
83+
'--prefix={prefix}',
84+
'--exec-prefix={exec_prefix}')).format(
85+
android_host=android_host,
86+
android_build=android_build,
87+
prefix=sys_prefix,
88+
exec_prefix=sys_exec_prefix)).split(' '), _env=env)
89+
90+
# if not exists('config.status'):
91+
92+
93+
# shprint(sh.make, '-C', build_dir)
94+
1795

1896
recipe = Python3Recipe()

pythonforandroid/recipes/six/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class SixRecipe(PythonRecipe):
66
version = '1.9.0'
77
url = 'https://pypi.python.org/packages/source/s/six/six-{version}.tar.gz'
8+
depends = [('python2', 'python3', 'python3crystax')]
89

910

1011
recipe = SixRecipe()

0 commit comments

Comments
 (0)