|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +""" |
| 4 | +Continuous Integration helper script. |
| 5 | +Automatically detects recipes modified in a changeset (compares with master) |
| 6 | +and recompiles them. |
| 7 | +
|
| 8 | +To run locally, set the environment variables before running: |
| 9 | +``` |
| 10 | +ANDROID_SDK_HOME=~/.buildozer/android/platform/android-sdk-20 |
| 11 | +ANDROID_NDK_HOME=~/.buildozer/android/platform/android-ndk-r9c |
| 12 | +CRYSTAX_NDK_HOME=~/.buildozer/crystax-ndk |
| 13 | +./ci/rebuild_update_recipes.py |
| 14 | +``` |
| 15 | +
|
| 16 | +Current limitations: |
| 17 | +- handle the case with conflicting requirements |
| 18 | + e.g. https://travis-ci.org/AndreMiras/python-for-android/builds/438840800 |
| 19 | + the list was huge and result was: |
| 20 | + [ERROR]: Didn't find any valid dependency graphs. |
| 21 | + [ERROR]: This means that some of your requirements pull in conflicting dependencies. |
| 22 | +- currently only builds on target python3crystax (even though python2 is supported) |
| 23 | +- comprehensive list of working/broken recipes is not yet known |
| 24 | +- only rebuilds on sdl2 bootstrap |
| 25 | +""" |
| 26 | +import sh |
| 27 | +import os |
| 28 | +from enum import Enum |
| 29 | +from pythonforandroid.toolchain import current_directory |
| 30 | + |
| 31 | + |
| 32 | +class TargetPython(Enum): |
| 33 | + python2 = 0 |
| 34 | + python3crystax = 1 |
| 35 | + |
| 36 | + |
| 37 | +# recipes that currently break the build |
| 38 | +# a recipe could be broken for a target Python and not for the other, |
| 39 | +# hence we're maintaining one list per Python target |
| 40 | +BROKEN_RECIPES_PYTHON2 = set([]) |
| 41 | +BROKEN_RECIPES_PYTHON3_CRYSTAX = set([ |
| 42 | + # not yet python3crystax compatible |
| 43 | + 'apsw', 'atom', 'boost', 'brokenrecipe', 'cdecimal', 'cherrypy', |
| 44 | + 'coverage', |
| 45 | + # https://github.com/kivy/python-for-android/issues/550 |
| 46 | + 'audiostream', |
| 47 | + # enum34 is not compatible with Python 3.6 standard library |
| 48 | + # https://stackoverflow.com/a/45716067/185510 |
| 49 | + 'enum34', |
| 50 | + # https://github.com/kivy/python-for-android/issues/1398 |
| 51 | + 'ifaddrs', |
| 52 | + # https://github.com/kivy/python-for-android/issues/1399 |
| 53 | + 'libglob', |
| 54 | + # cannot find -lcrystax |
| 55 | + 'cffi', |
| 56 | +]) |
| 57 | +BROKEN_RECIPES = { |
| 58 | + TargetPython.python2: BROKEN_RECIPES_PYTHON2, |
| 59 | + TargetPython.python3crystax: BROKEN_RECIPES_PYTHON3_CRYSTAX, |
| 60 | +} |
| 61 | +# recipes that are were already built |
| 62 | +CORE_RECIPES = set([ |
| 63 | + 'pyjnius', 'kivy', 'openssl', 'requests', 'sqlite3', 'setuptools', |
| 64 | + 'numpy', 'android', |
| 65 | +]) |
| 66 | + |
| 67 | + |
| 68 | +def modified_recipes(branch='origin/master'): |
| 69 | + """ |
| 70 | + Returns a set of modified recipes between the current branch and the one |
| 71 | + in param. |
| 72 | + """ |
| 73 | + # using the contrib version on purpose rather than sh.git, since it comes |
| 74 | + # with a bunch of fixes, e.g. disabled TTY, see: |
| 75 | + # https://stackoverflow.com/a/20128598/185510 |
| 76 | + git_diff = sh.contrib.git.diff('--name-only', branch) |
| 77 | + recipes = set() |
| 78 | + for file_path in git_diff: |
| 79 | + if 'pythonforandroid/recipes/' in file_path: |
| 80 | + recipe = file_path.split('/')[2] |
| 81 | + recipes.add(recipe) |
| 82 | + return recipes |
| 83 | + |
| 84 | + |
| 85 | +def build(target_python, requirements): |
| 86 | + """ |
| 87 | + Builds an APK given a target Python and a set of requirements. |
| 88 | + """ |
| 89 | + if not requirements: |
| 90 | + return |
| 91 | + testapp = 'setup_testapp_python2.py' |
| 92 | + android_sdk_home = os.environ['ANDROID_SDK_HOME'] |
| 93 | + android_ndk_home = os.environ['ANDROID_NDK_HOME'] |
| 94 | + crystax_ndk_home = os.environ['CRYSTAX_NDK_HOME'] |
| 95 | + if target_python == TargetPython.python3crystax: |
| 96 | + android_ndk_home = crystax_ndk_home |
| 97 | + testapp = 'setup_testapp_python3.py' |
| 98 | + requirements.add(target_python.name) |
| 99 | + requirements = ','.join(requirements) |
| 100 | + print('requirements:', requirements) |
| 101 | + with current_directory('testapps/'): |
| 102 | + try: |
| 103 | + for line in sh.python( |
| 104 | + testapp, 'apk', '--sdk-dir', android_sdk_home, |
| 105 | + '--ndk-dir', android_ndk_home, '--bootstrap', 'sdl2', '--requirements', |
| 106 | + requirements, _err_to_out=True, _iter=True): |
| 107 | + print(line) |
| 108 | + except sh.ErrorReturnCode as e: |
| 109 | + raise |
| 110 | + |
| 111 | + |
| 112 | +def main(): |
| 113 | + target_python = TargetPython.python3crystax |
| 114 | + recipes = modified_recipes() |
| 115 | + print('recipes modified:', recipes) |
| 116 | + broken_recipes = BROKEN_RECIPES[target_python] |
| 117 | + recipes = recipes - (CORE_RECIPES | broken_recipes) |
| 118 | + print('recipes to build:', recipes) |
| 119 | + build(target_python, recipes) |
| 120 | + print(recipes) |
| 121 | + |
| 122 | + |
| 123 | +if __name__ == '__main__': |
| 124 | + main() |
0 commit comments