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