Skip to content

Commit ceb5df6

Browse files
committed
Merge pull request kivy#459 from str4d/recipes
Recipes
2 parents ef49f93 + 8ae9acc commit ceb5df6

File tree

9 files changed

+187
-2
lines changed

9 files changed

+187
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from pythonforandroid.toolchain import PythonRecipe
3+
4+
5+
class Enum34Recipe(PythonRecipe):
6+
version = '1.0.4'
7+
url = 'https://pypi.python.org/packages/source/e/enum34/enum34-{version}.tar.gz'
8+
depends = ['python2']
9+
10+
recipe = Enum34Recipe()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
from pythonforandroid.toolchain import Recipe, shprint, current_directory
3+
from os.path import exists, join
4+
import sh
5+
6+
7+
class OpenSSLRecipe(Recipe):
8+
version = '1.0.2d'
9+
url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
10+
11+
def should_build(self):
12+
return not exists(join(self.get_build_dir('armeabi'), 'libssl.a'))
13+
14+
def build_arch(self, arch):
15+
env = self.get_recipe_env(arch)
16+
with current_directory(self.get_build_dir(arch.arch)):
17+
# sh fails with code 255 trying to execute ./Configure
18+
# so instead we manually run perl passing in Configure
19+
perl = sh.Command('perl')
20+
shprint(perl, 'Configure', 'no-dso', 'no-krb5', 'linux-armv4', _env=env)
21+
shprint(sh.make, 'build_libs', _env=env)
22+
23+
recipe = OpenSSLRecipe()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from pythonforandroid.toolchain import PythonRecipe
3+
4+
5+
class PyASN1Recipe(PythonRecipe):
6+
version = '0.1.8'
7+
url = 'https://pypi.python.org/packages/source/p/pyasn1/pyasn1-{version}.tar.gz'
8+
depends = ['python2']
9+
10+
recipe = PyASN1Recipe()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
from pythonforandroid.toolchain import (
3+
CompiledComponentsPythonRecipe,
4+
Recipe,
5+
current_directory,
6+
info,
7+
shprint,
8+
)
9+
from os.path import exists, join, realpath
10+
import sh
11+
import glob
12+
13+
14+
class PyCryptoRecipe(CompiledComponentsPythonRecipe):
15+
version = '2.6.1'
16+
url = 'https://pypi.python.org/packages/source/p/pycrypto/pycrypto-{version}.tar.gz'
17+
depends = ['openssl', 'python2']
18+
19+
def prebuild_arch(self, arch):
20+
super(PyCryptoRecipe, self).prebuild_arch(arch)
21+
build_dir = self.get_build_dir(arch.arch)
22+
if exists(join(build_dir, '.patched')):
23+
print('pycrypto already patched, skipping')
24+
return
25+
self.apply_patch('add_length.patch')
26+
shprint(sh.touch, join(build_dir, '.patched'))
27+
28+
def get_recipe_env(self, arch):
29+
env = super(PyCryptoRecipe, self).get_recipe_env(arch)
30+
openssl_build_dir = Recipe.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
31+
env['CC'] = '%s -I%s' % (env['CC'], join(openssl_build_dir, 'include'))
32+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
33+
self.ctx.get_libs_dir(arch.arch) +
34+
'-L{}'.format(self.ctx.libs_dir)) + ' -L{}'.format(
35+
openssl_build_dir)
36+
env['EXTRA_CFLAGS'] = '--host linux-armv'
37+
env['ac_cv_func_malloc_0_nonnull'] = 'yes'
38+
return env
39+
40+
def build_compiled_components(self, arch):
41+
info('Configuring compiled components in {}'.format(self.name))
42+
43+
env = self.get_recipe_env(arch)
44+
with current_directory(self.get_build_dir(arch.arch)):
45+
configure = sh.Command('./configure')
46+
shprint(configure, '--host=arm-eabi',
47+
'--prefix={}'.format(self.ctx.get_python_install_dir()),
48+
'--enable-shared', _env=env)
49+
super(PyCryptoRecipe, self).build_compiled_components(arch)
50+
51+
recipe = PyCryptoRecipe()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- pycrypto-2.6.1/src/hash_SHA2_template.c.orig 2013-10-14 14:38:10.000000000 -0700
2+
+++ pycrypto-2.6.1/src/hash_SHA2_template.c 2014-05-19 10:15:51.000000000 -0700
3+
@@ -87,7 +87,7 @@
4+
* return 1 on success
5+
* return 0 if the length overflows
6+
*/
7+
-int add_length(hash_state *hs, sha2_word_t inc) {
8+
+static int add_length(hash_state *hs, sha2_word_t inc) {
9+
sha2_word_t overflow_detector;
10+
overflow_detector = hs->length_lower;
11+
hs->length_lower += inc;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
from pythonforandroid.toolchain import (
3+
CompiledComponentsPythonRecipe,
4+
Recipe,
5+
current_directory,
6+
info,
7+
shprint,
8+
)
9+
from os.path import exists, join
10+
import sh
11+
import glob
12+
13+
14+
class PyOpenSSLRecipe(CompiledComponentsPythonRecipe):
15+
version = '0.13'
16+
url = 'https://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-{version}.tar.gz'
17+
depends = ['openssl', 'python2']
18+
19+
def prebuild_arch(self, arch):
20+
super(PyOpenSSLRecipe, self).prebuild_arch(arch)
21+
build_dir = self.get_build_dir(arch.arch)
22+
if exists(join(build_dir, '.patched')):
23+
print('pyOpenSSL already patched, skipping')
24+
return
25+
self.apply_patch('fix-dlfcn.patch')
26+
shprint(sh.touch, join(build_dir, '.patched'))
27+
28+
def get_recipe_env(self, arch):
29+
env = super(PyOpenSSLRecipe, self).get_recipe_env(arch)
30+
openssl_build_dir = Recipe.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
31+
env['CC'] = '%s -I%s' % (env['CC'], join(openssl_build_dir, 'include'))
32+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
33+
self.ctx.get_libs_dir(arch.arch) +
34+
'-L{}'.format(self.ctx.libs_dir)) + ' -L{}'.format(
35+
openssl_build_dir)
36+
return env
37+
38+
recipe = PyOpenSSLRecipe()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--- pyOpenSSL-0.13.orig/OpenSSL/__init__.py 2011-09-02 17:46:13.000000000 +0200
2+
+++ pyOpenSSL-0.13/OpenSSL/__init__.py 2013-07-29 17:20:15.750079894 +0200
3+
@@ -12,6 +12,11 @@
4+
except AttributeError:
5+
from OpenSSL import crypto
6+
else:
7+
+ # XXX android fix
8+
+ # linux: RTLD_NOW (0x2) | RTLD_GLOBAL (0x100 / 256)
9+
+ # android: RTLD_NOW (0x0) | RTLD_GLOBAL (0x2)
10+
+ flags = 0x2
11+
+ '''
12+
try:
13+
import DLFCN
14+
except ImportError:
15+
@@ -31,6 +36,7 @@
16+
else:
17+
flags = DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL
18+
del DLFCN
19+
+ '''
20+
21+
sys.setdlopenflags(flags)
22+
from OpenSSL import crypto

pythonforandroid/recipes/python2/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Python2Recipe(Recipe):
1313

1414
depends = ['hostpython2']
1515
conflicts = ['python3']
16+
opt_depends = ['openssl']
1617

1718
def prebuild_armeabi(self):
1819
build_dir = self.get_build_container_dir('armeabi')
@@ -74,8 +75,8 @@ def build_armeabi(self):
7475
# return
7576

7677
def do_python_build(self):
77-
if 'sqlite' in self.ctx.recipe_build_order or 'openssl' in self.ctx.recipe_build_order:
78-
print('sqlite or openssl support not yet enabled in python recipe')
78+
if 'sqlite' in self.ctx.recipe_build_order:
79+
print('sqlite support not yet enabled in python recipe')
7980
exit(1)
8081

8182
hostpython_recipe = Recipe.get_recipe('hostpython2', self.ctx)
@@ -99,6 +100,15 @@ def do_python_build(self):
99100
env['BUILDARCH'] = shprint(sh.gcc, '-dumpmachine').stdout.split('\n')[0]
100101
env['CFLAGS'] = ' '.join([env['CFLAGS'], '-DNO_MALLINFO'])
101102

103+
# TODO need to add a should_build that checks if optional
104+
# dependencies have changed (possibly in a generic way)
105+
if 'openssl' in self.ctx.recipe_build_order:
106+
openssl_build_dir = Recipe.get_recipe('openssl', self.ctx).get_build_dir('armeabi')
107+
env['CFLAGS'] = ' '.join([env['CFLAGS'],
108+
'-I{}'.format(join(openssl_build_dir, 'include'))])
109+
env['LDFLAGS'] = ' '.join([env['LDFLAGS'],
110+
'-L{}'.format(openssl_build_dir)])
111+
102112
configure = sh.Command('./configure')
103113
# AND: OFLAG isn't actually set, should it be?
104114
shprint(configure,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from pythonforandroid.toolchain import PythonRecipe
3+
4+
5+
class SixRecipe(PythonRecipe):
6+
version = '1.9.0'
7+
url = 'https://pypi.python.org/packages/source/s/six/six-{version}.tar.gz'
8+
depends = ['python2']
9+
10+
recipe = SixRecipe()

0 commit comments

Comments
 (0)