8000 new recipes · ssppkenny/python-for-android@6891eaa · GitHub
[go: up one dir, main page]

Skip to content

Commit 6891eaa

Browse files
committed
new recipes
1 parent b339493 commit 6891eaa

File tree

5 files changed

+217
-0
lines changed
  • sortedcontainers
  • utils
  • 5 files changed

    +217
    -0
    lines changed
    Lines changed: 14 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,14 @@
    1+
    from pythonforandroid.recipe import PythonRecipe
    2+
    3+
    4+
    class IntervaltreeRecipe(PythonRecipe):
    5+
    site_packages_name = 'intervaltree'
    6+
    version = '3.1.0'
    7+
    url = 'https://github.com/chaimleib/intervaltree/archive/refs/tags/{version}.zip'
    8+
    call_hostpython_via_targetpython = False
    9+
    # to be detected by the matplotlib install script
    10+
    install_in_hostpython = True
    11+
    depends = ['setuptools', 'sortedcontainers']
    12+
    13+
    14+
    recipe = IntervaltreeRecipe()
    Lines changed: 37 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,37 @@
    1+
    from multiprocessing import cpu_count
    2+
    import os
    3+
    from os.path import exists, join
    4+
    from pythonforandroid.toolchain import info
    5+
    import sh
    6+
    import sys
    7+
    8+
    from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe
    9+
    from pythonforandroid.logger import shprint, info_notify
    10+
    from pythonforandroid.util import current_directory, touch
    11+
    12+
    13+
    class MydjvulibRecipe(CppCompiledComponentsPythonRecipe):
    14+
    """This is a two-in-one recipe:
    15+
    - build labraru `libprotobuf.so`
    16+
    - build and install python binding for protobuf_cpp
    17+
    """
    18+
    name = 'mydjvulib'
    19+
    version = '0.1.2'
    20+
    url = 'https://github.com/ssppkenny/djvu_utils/archive/refs/tags/{version}.zip'
    21+
    call_hostpython_via_targetpython = False
    22+
    depends = ['setuptools']
    23+
    site_packages_name = 'mydjvulib'
    24+
    stl_lib_name = 'c++_shared'
    25+
    26+
    def get_recipe_env(self, arch):
    27+
    env = super().get_recipe_env(arch)
    28+
    env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE'
    29+
    env['CXXFLAGS'] += ' -fno-omit-frame-pointer -fsanitize=bool'
    30+
    env['CPPFLAGS'] += ' -fno-omit-frame-pointer -fsanitize=bool'
    31+
    # env['CPPFLAGS'] += ' -femulated-tls=1'
    32+
    # env['LDFLAGS'] += ' -lstdc++ -stdlib=libc++ -static'
    33+
    env['LDFLAGS'] += ' -fsanitize=bool'
    34+
    return env
    35+
    36+
    37+
    recipe = MydjvulibRecipe()
    Lines changed: 16 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,16 @@
    1+
    from pythonforandroid.recipe import CompiledComponentsPythonRecipe
    2+
    3+
    4+
    class RlsaFastRecipe(CompiledComponentsPythonRecipe):
    5+
    """This is a two-in-one recipe:
    6+
    - build labraru `libprotobuf.so`
    7+
    - build and install python binding for protobuf_cpp
    8+
    """
    9+
    name = 'rlsa_fast'
    10+
    version = '0.0.2'
    11+
    url = 'https://github.com/ssppkenny/pythonRLSA/archive/refs/tags/{version}.zip'
    12+
    call_hostpython_via_targetpython = False
    13+
    depends = ['numpy', 'setuptools']
    14+
    site_packages_name = 'rlsa_fast'
    15+
    16+
    recipe = RlsaFastRecipe()
    Lines changed: 13 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,13 @@
    1+
    from pythonforandroid.recipe import PythonRecipe
    2+
    3+
    class SortedcontainersRecipe(PythonRecipe):
    4+
    site_packages_name = 'sortedcontainers'
    5+
    version = 'v2.1.0'
    6+
    url = 'https://github.com/grantjenks/python-sortedcontainers/archive/refs/tags/{version}.zip'
    7+
    call_hostpython_via_targetpython = False
    8+
    # to be detected by the matplotlib install script
    9+
    install_in_hostpython = True
    10+
    depends = ['setuptools']
    11+
    12+
    13+
    recipe = SortedcontainersRecipe()
    Lines changed: 137 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,137 @@
    1+
    '''A dummy recipe to build my custom lib
    2+
    '''
    3+
    from os.path import basename, dirname, exists, isdir, isfile, join, realpath, split
    4+
    5+
    import fnmatch
    6+
    from os import listdir, unlink, environ, curdir, walk
    7+
    import sh
    8+
    from pythonforandroid.util import (
    9+
    current_directory, ensure_dir, BuildInterruptingException, rmdir, move,
    10+
    touch)
    11+
    from pythonforandroid.recipe import Recipe, CythonRecipe, IncludedFilesBehaviour, CompiledComponentsPythonRecipe
    12+
    from pythonforandroid.logger import (
    13+
    logger, info, warning, debug, shprint, info_main)
    14+
    15+
    16+
    17+
    18+
    class UtilsRecipe(CythonRecipe):
    19+
    version = '0.1.7'
    20+
    url = 'https://github.com/ssppkenny/myutils/archive/refs/tags/0.1.7.zip'
    21+
    site_packages_name = 'utils'
    22+
    depends = ['setuptools', 'cython']
    23+
    install_in_hostpython = False
    24+
    call_hostpython_via_targetpython = False
    25+
    26+
    27+
    def build_arch(self, arch):
    28+
    info("build_arch utils")
    29+
    '''Build any cython components, then install the Python module by
    30+
    calling setup.py install with the target Python dir.
    31+
    '''
    32+
    Recipe.build_arch(self, arch)
    33+
    self.build_cython_components(arch)
    34+
    self.install_python_package(arch)
    35+
    36+
    def build_cython_components(self, arch):
    37+
    info("build_cython_components utils")
    38+
    info('Cythonizing anything necessary in {}'.format(self.name))
    39+
    40+
    env = self.get_recipe_env(arch)
    41+
    42+
    with current_directory(self.get_build_dir(arch.arch)):
    43+
    hostpython = sh.Command(self.ctx.hostpython)
    44+
    shprint(hostpython, '-c', 'import sys; print(sys.path)', _env=env)
    45+
    debug('cwd is {}'.format(realpath(curdir)))
    46+
    info('Trying first build of {} to get cython files: this is '
    47+
    'expected to fail'.format(self.name))
    48+
    49+
    manually_cythonise = False
    50+
    try:
    51+
    shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
    52+
    *self.setup_extra_args)
    53+
    except sh.ErrorReturnCode_1:
    54+
    print()
    55+
    info('{} first build failed (as expected)'.format(self.name))
    56+
    manually_cythonise = True
    57+
    58+
    if manually_cythonise:
    59+
    self.cythonize_build(env=env)
    60+
    shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
    61+
    _tail=20, _critical=True, *self.setup_extra_args)
    62+
    else:
    63+
    info('First build appeared to complete correctly, skipping manual'
    64+
    'cythonising.')
    65+
    66+
    if not self.ctx.with_debug_symbols:
    67+
    self.strip_object_files(arch, env)
    68+
    69+
    def strip_object_files(self, arch, env, build_dir=None):
    70+
    if build_dir is None:
    71+
    build_dir = self.get_build_dir(arch.arch)
    72+
    with current_directory(build_dir):
    73+
    info('Stripping object files')
    74+
    shprint(sh.find, '.', '-iname', '*.so', '-exec',
    75+
    '/usr/bin/echo', '{}', ';', _env=env)
    76+
    shprint(sh.find, '.', '-iname', '*.so', '-exec',
    77+
    env['STRIP'].split(' ')[0], '--strip-unneeded',
    78+
    # '/usr/bin/strip', '--strip-unneeded',
    79+
    '{}', ';', _env=env)
    80+
    81+
    def cythonize_file(self, env, build_dir, filename):
    82+
    info("cythonize file utils " + filename)
    83+
    short_filename = filename
    84+
    if filename.startswith(build_dir):
    85+
    short_filename = filename[len(build_dir) + 1:]
    86+
    info(u"Cythonize {}".format(short_filename))
    87+
    cyenv = env.copy()
    88+
    if 'CYTHONPATH' in cyenv:
    89+
    cyenv['PYTHONPATH'] = cyenv['CYTHONPATH']
    90+
    elif 'PYTHONPATH' in cyenv:
    91+
    del cyenv['PYTHONPATH']
    92+
    if 'PYTHONNOUSERSITE' in cyenv:
    93+
    cyenv.pop('PYTHONNOUSERSITE')
    94+
    python_command = sh.Command("python{}".format(
    95+
    self.ctx.python_recipe.major_minor_version_string.split(".")[0]
    96+
    ))
    97+
    shprint(python_command, "-c"
    98+
    "import sys; from Cython.Compiler.Main import setuptools_main; sys.exit(setuptools_main());",
    99+
    filename, *self.cython_args, _env=cyenv)
    100+
    101+
    def cythonize_build(self, env, build_dir="."):
    102+
    info("cythonize_build utils")
    103+
    if not self.cythonize:
    104+
    info('Running cython cancelled per recipe setting')
    105+
    return
    106+
    info('Running cython where appropriate')
    107+
    for root, dirnames, filenames in walk("."):
    108+
    for filename in fnmatch.filter(filenames, "*.pyx"):
    109+
    self.cythonize_file(env, build_dir, join(root, filename))
    110+
    111+
    def get_recipe_env(self, arch, with_flags_in_cc=True):
    112+
    info("get_recipe_env utils")
    113+
    env = super().get_recipe_env(arch, with_flags_in_cc)
    114+
    env['LDFLAGS'] = env['LDFLAGS'] + ' -L{} '.format(
    115+
    self.ctx.get_libs_dir(arch.arch) +
    116+
    ' -L{} '.format(self.ctx.libs_dir) +
    117+
    ' -L{}'.format(join(self.ctx.bootstrap.build_dir, 'obj', 'local',
    118+
    arch.arch)))
    119+
    120+
    env['LDSHARED'] = env['CC'] + ' -shared'
    121+
    # shprint(sh.whereis, env['LDSHARED'], _env=env)
    122+
    env['LIBLINK'] = 'NOTNONE'
    123+
    if self.ctx.copy_libs:
    124+
    env['COPYLIBS'] = '1'
    125+
    126+
    # Every recipe uses its own liblink path, object files are
    127+
    # collected and biglinked later
    128+
    liblink_path = join(self.get_build_container_dir(arch.arch),
    129+
    'objects_{}'.format(self.name))
    130+
    env['LIBLINK_PATH'] = liblink_path
    131+
    ensure_dir(liblink_path)
    132+
    ## env['LDFLAGS'] += ' -framework CoreFoundation -framework CoreGraphics'
    133+
    134+
    return env
    135+
    136+
    137+
    recipe = UtilsRecipe()

    0 commit comments

    Comments
     (0)
    0