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