Skip to content

Commit f3be32b

Browse files
committed
Enhance openssl recipe and remove lib_version
Several actions done: - The openssl recipe has been enhanced by introducing a couple of methods (include_flags and link_flags) which should help us to link other recipes with the openssl libs. - Remove lib_version introduced in the last openssl version update, so we don't have to modify all dependant recipes - Add a new variable `url_version`, used to download our recipe in the subclassed method versioned_url (this replaces the removed lib_version) - Add D__ANDROID_API__ to the configure command (needed to successfully build the libraries and link them with python) - Add documentation
1 parent b45d074 commit f3be32b

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

pythonforandroid/recipes/openssl/__init__.py

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,73 @@
1+
import time
2+
from os.path import join
13
from functools import partial
24

35
from pythonforandroid.toolchain import Recipe, shprint, current_directory
46
import sh
57

68

79
class OpenSSLRecipe(Recipe):
8-
version = '1.1.1'
9-
lib_version = '1.1'
10-
url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
10+
'''
11+
The OpenSSL libraries for python-for-android. This recipe will generate the
12+
following libraries as shared libraries (*.so):
13+
14+
- crypto
15+
- ssl
16+
17+
The generated openssl libraries are versioned, where the version is the
18+
recipe attribute :attr:`version` e.g.: ``libcrypto1.1.so``,
19+
``libssl1.1.so``...so...to link your recipe with the openssl libs,
20+
remember to add the version at the end, e.g.:
21+
``-lcrypto1.1 -lssl1.1``. Or better, you could do it dynamically
22+
using the methods: :meth:`include_flags` and :meth:`link_flags`.
23+
24+
.. warning:: This recipe is very sensitive because is used for our core
25+
recipes, the python recipes. The used API should match with the one
26+
used in our python build, otherwise we will be unable to build the
27+
_ssl.so python module.
28+
29+
.. versionchanged:: 0.6.0
30+
31+
- The gcc compiler has been deprecated in favour of clang and libraries
32+
updated to version 1.1.1 (LTS - supported until 11th September 2023)
33+
- Added two new methods to make easier to link with openssl:
34+
:meth:`include_flags` and :meth:`link_flags`
35+
- subclassed versioned_url
36+
- Adapted method :meth:`select_build_arch` to API 21+
37+
38+
'''
39+
40+
version = '1.1'
41+
'''the major minor version used to link our recipes'''
42+
43+
url_version = '1.1.1'
44+
'''the version used to download our libraries'''
45+
46+
url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz'
47+
48+
@property
49+
def versioned_url(self):
50+
if self.url is None:
51+
return None
52+
return self.url.format(url_version=self.url_version)
53+
54+
def include_flags(self, arch):
55+
'''Returns a string with the include folders'''
56+
openssl_includes = join(self.get_build_dir(arch.arch), 'include')
57+
return ' -I' + openssl_includes + \
58+
' -I' + join(openssl_includes, 'internal') + \
59+
' -I' + join(openssl_includes, 'openssl')
60+
61+
def link_flags(self, arch):
62+
'''Returns a string with the right link flags to compile against the
63+
openssl libraries'''
64+
build_dir = self.get_build_dir(arch.arch)
65+
return ' -L' + build_dir + \
66+
' -lcrypto{version} -lssl{version}'.format(version=self.version)
1167

1268
def should_build(self, arch):
13-
return not self.has_libs(arch, 'libssl' + self.lib_version + '.so',
14-
'libcrypto' + self.lib_version + '.so')
69+
return not self.has_libs(arch, 'libssl' + self.version + '.so',
70+
'libcrypto' + self.version + '.so')
1571

1672
def check_symbol(self, env, sofile, symbol):
1773
nm = env.get('NM', 'nm')
@@ -24,7 +80,7 @@ def check_symbol(self, env, sofile, symbol):
2480

2581
def get_recipe_env(self, arch=None):
2682
env = super(OpenSSLRecipe, self).get_recipe_env(arch, clang=True)
27-
env['OPENSSL_VERSION'] = self.lib_version
83+
env['OPENSSL_VERSION'] = self.version
2884
env['MAKE'] = 'make' # This removes the '-j5', which isn't safe
2985
env['ANDROID_NDK'] = self.ctx.ndk_dir
3086
return env
@@ -54,21 +110,22 @@ def build_arch(self, arch):
54110
# ^
55111
# crypto/aes/bsaes-armv7.S:1434:14: error: immediate operand must be in the range [0,4095]
56112
# sub r6, r8, #.LREVM0SR-.LSR @ pass constants
57-
shprint(perl, 'Configure', 'shared', 'no-dso', 'no-asm', buildarch, _env=env)
113+
shprint(perl, 'Configure', 'shared', 'no-dso', 'no-asm', buildarch,
114+
'-D__ANDROID_API__={}'.format(self.ctx.ndk_api),
115+
_env=env)
58116
self.apply_patch('disable-sover.patch', arch.arch)
59117

60118
# check_ssl = partial(self.check_symbol, env, 'libssl' + self.version + '.so')
61-
check_crypto = partial(self.check_symbol, env, 'libcrypto' + self.lib_version + '.so')
119+
check_crypto = partial(self.check_symbol, env, 'libcrypto' + self.version + '.so')
62120
while True:
63121
shprint(sh.make, 'build_libs', _env=env)
64122
if all(map(check_crypto, ('MD5_Transform', 'MD4_Init'))):
65123
break
66-
import time
67124
time.sleep(3)
68125
shprint(sh.make, 'clean', _env=env)
69126

70-
self.install_libs(arch, 'libssl' + self.lib_version + '.so',
71-
'libcrypto' + self.lib_version + '.so')
127+
self.install_libs(arch, 'libssl' + self.version + '.so',
128+
'libcrypto' + self.version + '.so')
72129

73130

74131
recipe = OpenSSLRecipe()

0 commit comments

Comments
 (0)