patching.py (#2868)
"""Helper functions for recipes.Recipes must supply a list of patches.Patches consist of a filename and an optional conditional, which isany function of the form:def patch_check(arch: string, recipe : Recipe) -> boolThis library provides some helpful conditionals and mechanisms tojoin multiple conditionals.Example:patches = [("linux_or_darwin_only.patch",check_any(is_linux, is_darwin),("recent_android_API.patch",is_apt_gte(27)),]"""from platform import unamefrom packaging.version import Version# Platform checksdef is_platform(platform):"""Returns true if the host platform matches the parameter given."""def check(arch, recipe):return uname().system.lower() == platform.lower()return checkis_linux = is_platform("Linux")is_darwin = is_platform("Darwin")is_windows = is_platform("Windows")def is_arch(xarch):"""Returns true if the target architecture platform matches the parametergiven."""def check(arch):return arch.arch == xarchreturn check# Android API comparisons:# Return true if the Android API level being targeted# is equal (or >, >=, <, <= as appropriate) the given parameterdef is_api(apiver: int):def check(arch, recipe):return recipe.ctx.android_api == apiverreturn checkdef is_api_gt(apiver: int):def check(arch, recipe):return recipe.ctx.android_api > apiverreturn checkdef is_api_gte(apiver: int):def check(arch, recipe):return recipe.ctx.android_api >= apiverreturn checkdef is_api_lt(apiver: int):def check(arch, recipe):return recipe.ctx.android_api < apiverreturn checkdef is_api_lte(apiver: int):def check(arch, recipe):return recipe.ctx.android_api <= apiverreturn check# Android API comparisons:def is_ndk(ndk):"""Return true if the Minimum Supported Android NDK level being targetedis equal the given parameter (which should be an AndroidNDK instance)"""def check(arch, recipe):return recipe.ctx.ndk == ndkreturn check# Recipe Version comparisons:# These compare the Recipe's version with the provided string (or# Packaging.Version).## Warning: Both strings must conform to PEP 440 - e.g. "3.2.1" or "1.0rc1"def is_version_gt(version):"""Return true if the Recipe's version is greater"""def check(arch, recipe):return Version(recipe.version) > Version(version)return checkdef is_version_lt(version):"""Return true if the Recipe's version is less than"""def check(arch, recipe):return Version(recipe.version) < Version(version)return checkdef version_starts_with(version_prefix):def check(arch, recipe):return recipe.version.startswith(version_prefix)return check# Will Builddef will_build(recipe_name):"""Return true if the recipe with this name is planned to be included inthe distribution."""def check(arch, recipe):return recipe_name in recipe.ctx.recipe_build_orderreturn check# Conjunctionsdef check_all(*patch_checks):"""Given a collection of patch_checks as params, return if all returned true."""def check(arch, recipe):return all(patch_check(arch, recipe) for patch_check in patch_checks)return checkdef check_any(*patch_checks):"""Given a collection of patch_checks as params, return if any returned true."""def check(arch, recipe):return any(patch_check(arch, recipe) for patch_check in patch_checks)return check
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。