Skip to content

Commit f3748b4

Browse files
authored
✨ Compression libraries - episode II: liblzma (kivy#2096)
* ✨ Add `liblzma` recipe (liblzma.so) * ✅ Add tests for `liblzma` recipe * 💚 Add new dependency (`autopoint`) To fix travis CI tests when trying to build `liblzma` recipe
1 parent 31cad00 commit f3748b4

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

Dockerfile.py3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ RUN dpkg --add-architecture i386 \
5252
&& ${RETRY} apt -y install -qq --no-install-recommends \
5353
autoconf \
5454
automake \
55+
autopoint \
5556
build-essential \
5657
ccache \
5758
cmake \
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import sh
2+
3+
from multiprocessing import cpu_count
4+
from os.path import exists, join
5+
6+
from pythonforandroid.archs import Arch
7+
from pythonforandroid.logger import shprint
8+
from pythonforandroid.recipe import Recipe
9+
from pythonforandroid.util import current_directory, ensure_dir
10+
11+
12+
class LibLzmaRecipe(Recipe):
13+
14+
version = '5.2.4'
15+
url = 'https://tukaani.org/xz/xz-{version}.tar.gz'
16+
built_libraries = {'liblzma.so': 'install/lib'}
17+
18+
def build_arch(self, arch: Arch) -> None:
19+
env = self.get_recipe_env(arch)
20+
install_dir = join(self.get_build_dir(arch.arch), 'install')
21+
with current_directory(self.get_build_dir(arch.arch)):
22+
if not exists('configure'):
23+
shprint(sh.Command('./autogen.sh'), _env=env)
24+
shprint(sh.Command('autoreconf'), '-vif', _env=env)
25+
shprint(sh.Command('./configure'),
26+
'--host=' + arch.command_prefix,
27+
'--prefix=' + install_dir,
28+
'--disable-builddir',
29+
'--disable-static',
30+
'--enable-shared',
31+
32+
'--disable-xz',
33+
'--disable-xzdec',
34+
'--disable-lzmadec',
35+
'--disable-lzmainfo',
36+
'--disable-scripts',
37+
'--disable-doc',
38+
39+
_env=env)
40+
shprint(
41+
sh.make, '-j', str(cpu_count()),
42+
_env=env
43+
)
44+
45+
ensure_dir('install')
46+
shprint(sh.make, 'install', _env=env)
47+
48+
def get_library_includes(self, arch: Arch) -> str:
49+
"""
50+
Returns a string with the appropriate `-I<lib directory>` to link
51+
with the lzma lib. This string is usually added to the environment
52+
variable `CPPFLAGS`.
53+
"""
54+
return " -I" + join(
55+
self.get_build_dir(arch.arch), 'install', 'include',
56+
)
57+
58+
def get_library_ldflags(self, arch: Arch) -> str:
59+
"""
60+
Returns a string with the appropriate `-L<lib directory>` to link
61+
with the lzma lib. This string is usually added to the environment
62+
variable `LDFLAGS`.
63+
"""
64+
return " -L" + join(
65+
self.get_build_dir(arch.arch), self.built_libraries['liblzma.so'],
66+
)
67+
68+
@staticmethod
69+
def get_library_libs_flag() -> str:
70+
"""
71+
Returns a string with the appropriate `-l<lib>` flags to link with
72+
the lzma lib. This string is usually added to the environment
73+
variable `LIBS`.
74+
"""
75+
return " -llzma"
76+
77+
78+
recipe = LibLzmaRecipe()

tests/recipes/test_liblzma.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import unittest
2+
from os.path import join
3+
from tests.recipes.recipe_lib_test import BaseTestForMakeRecipe
4+
5+
6+
class TestLibLzmaRecipe(BaseTestForMakeRecipe, unittest.TestCase):
7+
"""TestCase for recipe :mod:`~pythonforandroid.recipes.liblzma`."""
8+
recipe_name = "liblzma"
9+
sh_command_calls = ["./autogen.sh", "autoreconf", "./configure"]
10+
11+
def test_get_library_includes(self):
12+
"""
13+
Test :meth:`~pythonforandroid.recipes.liblzma.get_library_includes`.
14+
"""
15+
recipe_build_dir = self.recipe.get_build_dir(self.arch.arch)
16+
self.assertEqual(
17+
self.recipe.get_library_includes(self.arch),
18+
f" -I{join(recipe_build_dir, 'install/include')}",
19+
)
20+
21+
def test_get_library_ldflags(self):
22+
"""
23+
Test :meth:`~pythonforandroid.recipes.liblzma.get_library_ldflags`.
24+
"""
25+
recipe_build_dir = self.recipe.get_build_dir(self.arch.arch)
26+
self.assertEqual(
27+
self.recipe.get_library_ldflags(self.arch),
28+
f" -L{join(recipe_build_dir, 'install/lib')}",
29+
)
30+
31+
def test_link_libs_flags(self):
32+
"""
33+
Test :meth:`~pythonforandroid.recipes.liblzma.get_library_libs_flag`.
34+
"""
35+
self.assertEqual(self.recipe.get_library_libs_flag(), " -llzma")

0 commit comments

Comments
 (0)