Skip to content

✨ Compression libraries - episode II: liblzma #2096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile.py3
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ RUN dpkg --add-architecture i386 \
&& ${RETRY} apt -y install -qq --no-install-recommends \
autoconf \
automake \
autopoint \
build-essential \
ccache \
cmake \
Expand Down
78 changes: 78 additions & 0 deletions pythonforandroid/recipes/liblzma/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import sh

from multiprocessing import cpu_count
from os.path import exists, join

from pythonforandroid.archs import Arch
from pythonforandroid.logger import shprint
from pythonforandroid.recipe import Recipe
from pythonforandroid.util import current_directory, ensure_dir


class LibLzmaRecipe(Recipe):

version = '5.2.4'
url = 'https://tukaani.org/xz/xz-{version}.tar.gz'
built_libraries = {'liblzma.so': 'install/lib'}

def build_arch(self, arch: Arch) -> None:
env = self.get_recipe_env(arch)
install_dir = join(self.get_build_dir(arch.arch), 'install')
with current_directory(self.get_build_dir(arch.arch)):
if not exists('configure'):
shprint(sh.Command('./autogen.sh'), _env=env)
shprint(sh.Command('autoreconf'), '-vif', _env=env)
shprint(sh.Command('./configure'),
'--host=' + arch.command_prefix,
'--prefix=' + install_dir,
'--disable-builddir',
'--disable-static',
'--enable-shared',

'--disable-xz',
'--disable-xzdec',
'--disable-lzmadec',
'--disable-lzmainfo',
'--disable-scripts',
'--disable-doc',

_env=env)
shprint(
sh.make, '-j', str(cpu_count()),
_env=env
)

ensure_dir('install')
shprint(sh.make, 'install', _env=env)

def get_library_includes(self, arch: Arch) -> str:
"""
Returns a string with the appropriate `-I<lib directory>` to link
with the lzma lib. This string is usually added to the environment
variable `CPPFLAGS`.
"""
return " -I" + join(
self.get_build_dir(arch.arch), 'install', 'include',
)

def get_library_ldflags(self, arch: Arch) -> str:
"""
Returns a string with the appropriate `-L<lib directory>` to link
with the lzma lib. This string is usually added to the environment
variable `LDFLAGS`.
"""
return " -L" + join(
self.get_build_dir(arch.arch), self.built_libraries['liblzma.so'],
)

@staticmethod
def get_library_libs_flag() -> str:
"""
Returns a string with the appropriate `-l<lib>` flags to link with
the lzma lib. This string is usually added to the environment
variable `LIBS`.
"""
return " -llzma"


recipe = LibLzmaRecipe()
35 changes: 35 additions & 0 deletions tests/recipes/test_liblzma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from os.path import join
from tests.recipes.recipe_lib_test import BaseTestForMakeRecipe


class TestLibLzmaRecipe(BaseTestForMakeRecipe, unittest.TestCase):
"""TestCase for recipe :mod:`~pythonforandroid.recipes.liblzma`."""
recipe_name = "liblzma"
sh_command_calls = ["./autogen.sh", "autoreconf", "./configure"]

def test_get_library_includes(self):
"""
Test :meth:`~pythonforandroid.recipes.liblzma.get_library_includes`.
"""
recipe_build_dir = self.recipe.get_build_dir(self.arch.arch)
self.assertEqual(
self.recipe.get_library_includes(self.arch),
f" -I{join(recipe_build_dir, 'install/include')}",
)

def test_get_library_ldflags(self):
"""
Test :meth:`~pythonforandroid.recipes.liblzma.get_library_ldflags`.
"""
recipe_build_dir = self.recipe.get_build_dir(self.arch.arch)
self.assertEqual(
self.recipe.get_library_ldflags(self.arch),
f" -L{join(recipe_build_dir, 'install/lib')}",
)

def test_link_libs_flags(self):
"""
Test :meth:`~pythonforandroid.recipes.liblzma.get_library_libs_flag`.
"""
self.assertEqual(self.recipe.get_library_libs_flag(), " -llzma")