ros-catkin.eclass 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: ros-catkin.eclass
  4. # @MAINTAINER:
  5. # ros@gentoo.org
  6. # @AUTHOR:
  7. # Alexis Ballier <aballier@gentoo.org>
  8. # @BLURB: Template eclass for catkin based ROS packages.
  9. # @DESCRIPTION:
  10. # Provides function for building ROS packages on Gentoo.
  11. # It supports selectively building messages, multi-python installation, live ebuilds (git only).
  12. case "${EAPI:-0}" in
  13. 0|1|2|3|4)
  14. die "EAPI='${EAPI}' is not supported"
  15. ;;
  16. *)
  17. ;;
  18. esac
  19. # @ECLASS-VARIABLE: ROS_REPO_URI
  20. # @DESCRIPTION:
  21. # URL of the upstream repository. Usually on github.
  22. # Serves for fetching tarballs, live ebuilds and inferring the meta-package name.
  23. EGIT_REPO_URI="${ROS_REPO_URI}"
  24. # @ECLASS-VARIABLE: ROS_SUBDIR
  25. # @DEFAULT_UNSET
  26. # @DESCRIPTION:
  27. # Subdir in which current packages is located.
  28. # Usually, a repository contains several packages, hence a typical value is:
  29. # ROS_SUBDIR=${PN}
  30. # @ECLASS-VARIABLE: CATKIN_IN_SOURCE_BUILD
  31. # @DEFAULT_UNSET
  32. # @DESCRIPTION:
  33. # Set to enable in-source build.
  34. SCM=""
  35. if [ "${PV#9999}" != "${PV}" ] ; then
  36. SCM="git-r3"
  37. fi
  38. # @ECLASS-VARIABLE: PYTHON_COMPAT
  39. # @DESCRIPTION:
  40. # Tells the eclass the package has python code and forwards it to python-r1.eclass.
  41. PYTHON_ECLASS=""
  42. CATKIN_PYTHON_USEDEP=""
  43. if [ -n "${PYTHON_COMPAT}" ] ; then
  44. PYTHON_ECLASS="python-r1 python-utils-r1"
  45. fi
  46. inherit ${SCM} ${PYTHON_ECLASS} cmake-utils flag-o-matic
  47. CATKIN_DO_PYTHON_MULTIBUILD=""
  48. if [ -n "${PYTHON_COMPAT}" ] ; then
  49. CATKIN_PYTHON_USEDEP="[${PYTHON_USEDEP}]"
  50. CATKIN_DO_PYTHON_MULTIBUILD="yes"
  51. fi
  52. IUSE="test"
  53. RDEPEND="
  54. dev-util/catkin${CATKIN_PYTHON_USEDEP}
  55. dev-python/empy${CATKIN_PYTHON_USEDEP}
  56. "
  57. DEPEND="${RDEPEND}"
  58. if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
  59. RDEPEND="${RDEPEND} dev-lang/python-exec:2 ${PYTHON_DEPS}"
  60. DEPEND="${DEPEND} ${PYTHON_DEPS}"
  61. fi
  62. # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
  63. # @DESCRIPTION:
  64. # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
  65. # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
  66. # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
  67. # @DESCRIPTION:
  68. # Some messages have dependencies on other messages.
  69. # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
  70. # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
  71. if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
  72. IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp ros_messages_nodejs"
  73. RDEPEND="${RDEPEND}
  74. ros_messages_cxx? ( dev-ros/gencpp:=${CATKIN_PYTHON_USEDEP} )
  75. ros_messages_eus? ( dev-ros/geneus:=${CATKIN_PYTHON_USEDEP} )
  76. ros_messages_python? ( dev-ros/genpy:=${CATKIN_PYTHON_USEDEP} )
  77. ros_messages_lisp? ( dev-ros/genlisp:=${CATKIN_PYTHON_USEDEP} )
  78. ros_messages_nodejs? ( dev-ros/gennodejs:=${CATKIN_PYTHON_USEDEP} )
  79. dev-ros/message_runtime
  80. "
  81. DEPEND="${DEPEND} ${RDEPEND}
  82. dev-ros/message_generation
  83. dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
  84. "
  85. if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
  86. for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
  87. ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
  88. RDEPEND="${RDEPEND} ${ds}"
  89. DEPEND="${DEPEND} ${ds}"
  90. done
  91. fi
  92. fi
  93. # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
  94. # @DESCRIPTION:
  95. # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
  96. CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
  97. # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
  98. # @DESCRIPTION:
  99. # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
  100. CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
  101. # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
  102. # @DESCRIPTION:
  103. # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
  104. CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
  105. # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
  106. # @DESCRIPTION:
  107. # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
  108. CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
  109. # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
  110. # @DESCRIPTION:
  111. # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
  112. CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
  113. if [ "${PV#9999}" != "${PV}" ] ; then
  114. SRC_URI=""
  115. KEYWORDS=""
  116. S=${WORKDIR}/${P}/${ROS_SUBDIR}
  117. else
  118. SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
  119. S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}${VER_SUFFIX}/${ROS_SUBDIR}
  120. fi
  121. HOMEPAGE="http://wiki.ros.org/${PN}"
  122. # @FUNCTION: ros-catkin_src_prepare
  123. # @DESCRIPTION:
  124. # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
  125. # by installing a recursive CMakeLists.txt to handle bundles.
  126. ros-catkin_src_prepare() {
  127. # If no multibuild, just use cmake IN_SOURCE support
  128. [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && [ -z "${CATKIN_DO_PYTHON_MULTIBUILD}" ] && export CMAKE_IN_SOURCE_BUILD=yes
  129. cmake-utils_src_prepare
  130. if [ ! -f "${S}/CMakeLists.txt" ] ; then
  131. catkin_init_workspace || die
  132. fi
  133. # If python multibuild, copy the sources
  134. [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] && python_copy_sources
  135. # Most packages require C++11 these days. Do it here, in src_prepare so that
  136. # ebuilds can override it in src_configure.
  137. append-cxxflags '-std=c++11'
  138. }
  139. # @FUNCTION: ros-catkin_src_configure_internal
  140. # @DESCRIPTION:
  141. # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
  142. ros-catkin_src_configure_internal() {
  143. if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
  144. local sitedir="$(python_get_sitedir)"
  145. local mycmakeargs=(
  146. "${mycmakeargs[@]}"
  147. -DPYTHON_EXECUTABLE="${PYTHON}"
  148. -DPYTHON_INSTALL_DIR="${sitedir#${EPREFIX}/usr/}"
  149. )
  150. python_export PYTHON_SCRIPTDIR
  151. if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
  152. export CMAKE_USE_DIR="${BUILD_DIR}"
  153. fi
  154. fi
  155. cmake-utils_src_configure "${@}"
  156. }
  157. # @VARIABLE: mycatkincmakeargs
  158. # @DEFAULT_UNSET
  159. # @DESCRIPTION:
  160. # Optional cmake defines as a bash array. Should be defined before calling
  161. # src_configure.
  162. # @FUNCTION: ros-catkin_src_configure
  163. # @DESCRIPTION:
  164. # Configures a catkin-based package.
  165. ros-catkin_src_configure() {
  166. export CATKIN_PREFIX_PATH="${EPREFIX}/usr"
  167. export ROS_ROOT="${EPREFIX}/usr/share/ros"
  168. if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
  169. ROS_LANG_DISABLE=""
  170. use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
  171. use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
  172. use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
  173. use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
  174. use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
  175. export ROS_LANG_DISABLE
  176. fi
  177. local mycmakeargs=(
  178. "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
  179. "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
  180. "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
  181. "${mycatkincmakeargs[@]}"
  182. )
  183. if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
  184. python_foreach_impl ros-catkin_src_configure_internal "${@}"
  185. else
  186. ros-catkin_src_configure_internal "${@}"
  187. fi
  188. }
  189. # @FUNCTION: ros-catkin_src_compile
  190. # @DESCRIPTION:
  191. # Builds a catkin-based package.
  192. ros-catkin_src_compile() {
  193. if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
  194. if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
  195. export CMAKE_USE_DIR="${BUILD_DIR}"
  196. fi
  197. python_foreach_impl cmake-utils_src_compile "${@}"
  198. else
  199. cmake-utils_src_compile "${@}"
  200. fi
  201. }
  202. # @FUNCTION: ros-catkin_src_test_internal
  203. # @DESCRIPTION:
  204. # Decorator around cmake-utils_src_test to ensure tests are built before running them.
  205. ros-catkin_src_test_internal() {
  206. cd "${BUILD_DIR}" || die
  207. # Regenerate env for tests, PYTHONPATH is not set properly otherwise...
  208. if [ -f catkin_generated/generate_cached_setup.py ] ; then
  209. einfo "Regenerating setup_cached.sh for tests"
  210. ${PYTHON:-python} catkin_generated/generate_cached_setup.py || die
  211. fi
  212. # Using cmake-utils_src_make with nonfatal does not work and breaks e.g.
  213. # dev-ros/rviz.
  214. if nonfatal emake tests -n &> /dev/null ; then
  215. cmake-utils_src_make tests
  216. fi
  217. cmake-utils_src_test "${@}"
  218. }
  219. # @FUNCTION: ros-catkin_src_test
  220. # @DESCRIPTION:
  221. # Run the tests of a catkin-based package.
  222. ros-catkin_src_test() {
  223. if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
  224. python_foreach_impl ros-catkin_src_test_internal "${@}"
  225. else
  226. ros-catkin_src_test_internal "${@}"
  227. fi
  228. }
  229. # @FUNCTION: ros-catkin_src_install_with_python
  230. # @DESCRIPTION:
  231. # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
  232. ros-catkin_src_install_with_python() {
  233. python_export PYTHON_SCRIPTDIR
  234. if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
  235. export CMAKE_USE_DIR="${BUILD_DIR}"
  236. fi
  237. cmake-utils_src_install "${@}"
  238. if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
  239. dodir /usr/bin
  240. for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
  241. dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
  242. done
  243. touch "${T}/.catkin_python_symlinks_generated" || die
  244. fi
  245. }
  246. # @FUNCTION: ros-catkin_src_install
  247. # @DESCRIPTION:
  248. # Installs a catkin-based package.
  249. ros-catkin_src_install() {
  250. if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
  251. python_foreach_impl ros-catkin_src_install_with_python "${@}"
  252. else
  253. cmake-utils_src_install "${@}"
  254. fi
  255. }
  256. EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install