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.

134 lines
5.1 KiB

  1. #
  2. # Copyright (C) 2019 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:=python3-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_python3-packages-list-host \
  21. CONFIG_PACKAGE_python3-packages-list \
  22. CONFIG_PACKAGE_python3-packages-list-cleanup \
  23. CONFIG_PACKAGE_python3-packages-envs \
  24. CONFIG_PACKAGE_python3-packages-extra-deps \
  25. CONFIG_PACKAGE_python3-packages-index-url \
  26. CONFIG_PACKAGE_python3-packages-pip-opts \
  27. PKG_BUILD_DEPENDS:=python3 python3/host
  28. include $(INCLUDE_DIR)/package.mk
  29. include ../python3-host.mk
  30. include ../python3-package.mk
  31. define Package/python3-packages
  32. SUBMENU:=Python
  33. SECTION:=lang
  34. CATEGORY:=Languages
  35. TITLE:=A dummy package for packaging python3 modules with pip
  36. DEPENDS:=@DEVEL +python3
  37. endef
  38. define Package/python3-packages/config
  39. if PACKAGE_python3-packages
  40. config PACKAGE_python3-packages-list-host
  41. string "List of python3 packages to install on host"
  42. config PACKAGE_python3-packages-list
  43. string "List of python3 packages to install on target"
  44. config PACKAGE_python3-packages-list-cleanup
  45. string "List of python3 packages to cleanup to avoid clash with existing packages"
  46. config PACKAGE_python3-packages-envs
  47. string "Extra environment variables to pass on to pip and its children on target build"
  48. config PACKAGE_python3-packages-extra-deps
  49. string "List of deps fulfilled but not tracked by the build system"
  50. config PACKAGE_python3-packages-index-url
  51. string "Index URL passed to pip with --index-url"
  52. config PACKAGE_python3-packages-pip-opts
  53. string "Additional arguments to pip command line"
  54. endif
  55. endef
  56. CONFIG_PACKAGE_python3-packages-list-host:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-list-host))
  57. CONFIG_PACKAGE_python3-packages-list:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-list))
  58. CONFIG_PACKAGE_python3-packages-list-cleanup:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-list-cleanup))
  59. CONFIG_PACKAGE_python3-packages-envs:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-envs))
  60. CONFIG_PACKAGE_python3-packages-extra-deps:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-extra-deps))
  61. CONFIG_PACKAGE_python3-packages-index-url:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-index-url))
  62. CONFIG_PACKAGE_python3-packages-pip-opts:=$(call qstrip,$(CONFIG_PACKAGE_python3-packages-pip-opts))
  63. decr=$(word $(1),0 1 2 3 4 5 6 7 8 9 10)
  64. recur=$(if $(subst 0,,$(2)),$(call recur,$(1),$(call decr,$(2)),$(call $(1)$(2),$(3))),$(3))
  65. _req2dir1=$(subst >,gt,$(1))
  66. _req2dir2=$(subst <,lt,$(1))
  67. _req2dir3=$(subst >=,geq,$(1))
  68. _req2dir4=$(subst <=,leq,$(1))
  69. _req2dir5=$(subst ://,:::,$(1))
  70. _req2dir6=$(subst *,_,$(1))
  71. _req2dir7=$(subst ?,_,$(1))
  72. req2dir=$(call recur,_req2dir,7,$(1))
  73. # --ignore-installed, it may happen that host pip will ignore target install if
  74. # it was already installed as host module, e.g. cffi deps of cryptograph
  75. #
  76. # --no-build-isolation, this is a new addition in pip3 and is needed when build
  77. # depends on host modules
  78. HOST_PYTHON3_PIP_INSTALL=$(HOST_PYTHON3_PIP) install \
  79. --root=$(1) \
  80. --prefix=$(2) \
  81. --ignore-installed \
  82. --no-build-isolation \
  83. --no-compile \
  84. $(if $(CONFIG_PACKAGE_python3-packages-index-url), --index-url "$(CONFIG_PACKAGE_python3-packages-index-url)") \
  85. $(if $(CONFIG_PACKAGE_python3-packages-pip-opts), $(CONFIG_PACKAGE_python3-packages-pip-opts)) \
  86. HOST_PYTHON3_PIP_INSTALL_HOST:=$(call HOST_PYTHON3_PIP_INSTALL,$(STAGING_DIR_HOSTPKG),"")
  87. HOST_PYTHON3_PIP_INSTALL_TARGET=$(call HOST_PYTHON3_PIP_INSTALL,$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg)),/usr)
  88. HOST_PYTHON3_PIP_INSTALL_CLEANUP:=$(call HOST_PYTHON3_PIP_INSTALL,$(PKG_INSTALL_DIR)/_cleanup,/usr)
  89. define Build/Compile
  90. $(foreach pkg,$(CONFIG_PACKAGE_python3-packages-list-host),
  91. $(call HostPython3/Run,,$(HOST_PYTHON3_PIP_INSTALL_HOST) $(pkg))
  92. )
  93. $(foreach pkg,$(CONFIG_PACKAGE_python3-packages-list),
  94. $(call Python3/Run,,$(call HOST_PYTHON3_PIP_INSTALL_TARGET,$(pkg)) $(pkg),$(CONFIG_PACKAGE_python3-packages-envs))
  95. )
  96. $(foreach pkg,$(CONFIG_PACKAGE_python3-packages-list-cleanup),
  97. $(call Python3/Run,,$(HOST_PYTHON3_PIP_INSTALL_CLEANUP) $(pkg),$(CONFIG_PACKAGE_python3-packages-envs))
  98. )
  99. endef
  100. define Package/python3-packages/install
  101. $(foreach pkg,$(CONFIG_PACKAGE_python3-packages-list),
  102. $(CP) "$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg))"/* $(1)
  103. )
  104. find "$(PKG_INSTALL_DIR)/_cleanup" -mindepth 1 -depth | while read sf; do \
  105. tf="$$$${sf#$(PKG_INSTALL_DIR)/_cleanup/}"; \
  106. tf="$(1)/$$$$tf"; \
  107. if [ -f "$$$$tf" -o -L "$$$$tf" ]; then \
  108. rm -vf "$$$$tf"; \
  109. elif [ -d "$$$$tf" ]; then \
  110. rmdir -v -p "$$$$tf" || true; \
  111. fi \
  112. done
  113. endef
  114. define Package/python3-packages/extra_provides
  115. echo $(CONFIG_PACKAGE_python3-packages-extra-deps) | tr ' ' '\n'
  116. endef
  117. $(eval $(call BuildPackage,python3-packages))