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