You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.9 KiB

  1. #
  2. # Copyright (C) 2016 Yousong Zhou <yszhou4tech@gmail.com>
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. PKG_NAME:=python-packages
  9. PKG_VERSION:=1.0
  10. PKG_RELEASE:=1
  11. PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>
  12. #
  13. # NOTE: move the host module installation to Host/Compile when
  14. # HOST_CONFIG_DEPENDS is supported
  15. #
  16. # NOTE: PKG_CONFIG_DEPENDS cannot correctly track changes of string type config
  17. # options, so you may want to do manual cleanup on config change.
  18. #
  19. PKG_CONFIG_DEPENDS:= \
  20. CONFIG_PACKAGE_python-packages-list-host \
  21. CONFIG_PACKAGE_python-packages-list \
  22. CONFIG_PACKAGE_python-packages-list-cleanup \
  23. CONFIG_PACKAGE_python-packages-envs \
  24. CONFIG_PACKAGE_python-packages-extra-deps \
  25. CONFIG_PACKAGE_python-packages-index-url \
  26. CONFIG_PACKAGE_python-packages-pip-opts \
  27. PKG_BUILD_DEPENDS:=python python/host
  28. include $(INCLUDE_DIR)/package.mk
  29. $(call include_mk, python-package.mk)
  30. define Package/python-packages
  31. SUBMENU:=Python
  32. SECTION:=lang
  33. CATEGORY:=Languages
  34. TITLE:=A dummy package for packaging python modules with pip
  35. DEPENDS:=@DEVEL +python
  36. endef
  37. define Package/python-packages/config
  38. if PACKAGE_python-packages
  39. config PACKAGE_python-packages-list-host
  40. string "List of python packages to install on host"
  41. config PACKAGE_python-packages-list
  42. string "List of python packages to install on target"
  43. config PACKAGE_python-packages-list-cleanup
  44. string "List of python packages to cleanup to avoid clash with existing packages"
  45. config PACKAGE_python-packages-envs
  46. string "Extra environment variables to pass on to pip and its children on target build"
  47. config PACKAGE_python-packages-extra-deps
  48. string "List of deps fulfilled but not tracked by the build system"
  49. config PACKAGE_python-packages-index-url
  50. string "Index URL passed to pip with --index-url"
  51. config PACKAGE_python-packages-pip-opts
  52. string "Additional arguments to pip command line"
  53. endif
  54. endef
  55. CONFIG_PACKAGE_python-packages-list-host:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-host))
  56. CONFIG_PACKAGE_python-packages-list:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list))
  57. CONFIG_PACKAGE_python-packages-list-cleanup:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-cleanup))
  58. CONFIG_PACKAGE_python-packages-envs:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-envs))
  59. CONFIG_PACKAGE_python-packages-extra-deps:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-extra-deps))
  60. CONFIG_PACKAGE_python-packages-pip-opts:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-pip-opts))
  61. HOST_PYTHON_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON_VERSION)
  62. decr=$(word $(1),0 1 2 3 4 5 6 7 8 9 10)
  63. recur=$(if $(subst 0,,$(2)),$(call recur,$(1),$(call decr,$(2)),$(call $(1)$(2),$(3))),$(3))
  64. _req2dir1=$(subst >,gt,$(1))
  65. _req2dir2=$(subst <,lt,$(1))
  66. _req2dir3=$(subst >=,geq,$(1))
  67. _req2dir4=$(subst <=,leq,$(1))
  68. _req2dir5=$(subst ://,:::,$(1))
  69. _req2dir6=$(subst *,_,$(1))
  70. _req2dir7=$(subst ?,_,$(1))
  71. req2dir=$(call recur,_req2dir,7,$(1))
  72. # --ignore-installed, it may happen that host pip will ignore target install if
  73. # it was already installed as host module, e.g. cffi deps of cryptograph
  74. HOST_PYTHON_PIP_INSTALL=$(HOST_PYTHON_PIP) install \
  75. --root=$(1) \
  76. --prefix=$(2) \
  77. --ignore-installed \
  78. --no-compile \
  79. $(if $(CONFIG_PACKAGE_python-packages-index-url), --index-url $(CONFIG_PACKAGE_python-packages-index-url)) \
  80. $(if $(CONFIG_PACKAGE_python-packages-pip-opts), $(CONFIG_PACKAGE_python-packages-pip-opts)) \
  81. HOST_PYTHON_PIP_INSTALL_HOST:=$(call HOST_PYTHON_PIP_INSTALL,$(STAGING_DIR_HOSTPKG),"")
  82. HOST_PYTHON_PIP_INSTALL_TARGET=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg)),/usr)
  83. HOST_PYTHON_PIP_INSTALL_CLEANUP:=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/_cleanup,/usr)
  84. define Build/Compile
  85. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-host),
  86. $(call Build/Compile/HostPyRunHost,,$(HOST_PYTHON_PIP_INSTALL_HOST) $(pkg))
  87. )
  88. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
  89. $(call Build/Compile/HostPyRunTarget,,$(call HOST_PYTHON_PIP_INSTALL_TARGET,$(pkg)) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
  90. )
  91. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-cleanup),
  92. $(call Build/Compile/HostPyRunTarget,,$(HOST_PYTHON_PIP_INSTALL_CLEANUP) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
  93. )
  94. endef
  95. define Package/python-packages/install
  96. $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
  97. $(CP) "$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg))"/* $(1)
  98. )
  99. find "$(PKG_INSTALL_DIR)/_cleanup" -mindepth 1 -depth | while read sf; do \
  100. tf="$$$${sf#$(PKG_INSTALL_DIR)/_cleanup/}"; \
  101. tf="$(1)/$$$$tf"; \
  102. if [ -f "$$$$tf" -o -L "$$$$tf" ]; then \
  103. rm -vf "$$$$tf"; \
  104. elif [ -d "$$$$tf" ]; then \
  105. rmdir -v -p "$$$$tf" || true; \
  106. fi \
  107. done
  108. endef
  109. define Package/python-packages/extra_provides
  110. echo $(CONFIG_PACKAGE_python-packages-extra-deps) | tr ' ' '\n'
  111. endef
  112. $(eval $(call BuildPackage,python-packages))