x11-themes/gentoo10-backgrounds: Cleanup per bug #85210
[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 ros_messages_nodejs"
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                 ros_messages_nodejs? ( dev-ros/gennodejs:=${CATKIN_PYTHON_USEDEP} )
88                 dev-ros/message_runtime
89         "
90         DEPEND="${DEPEND} ${RDEPEND}
91                 dev-ros/message_generation
92                 dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
93         "
94         if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
95                 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
96                         ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
97                         RDEPEND="${RDEPEND} ${ds}"
98                         DEPEND="${DEPEND} ${ds}"
99                 done
100         fi
101 fi
102
103 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
104 # @DESCRIPTION:
105 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
106 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
107
108 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
109 # @DESCRIPTION:
110 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
111 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
112
113 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
114 # @DESCRIPTION:
115 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
116 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
117
118 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
119 # @DESCRIPTION:
120 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
121 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
122
123 # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
124 # @DESCRIPTION:
125 # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
126 CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
127
128 if [ "${PV#9999}" != "${PV}" ] ; then
129         SRC_URI=""
130         KEYWORDS=""
131         S=${WORKDIR}/${P}/${ROS_SUBDIR}
132 else
133         SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
134         S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}${VER_SUFFIX}/${ROS_SUBDIR}
135 fi
136
137 HOMEPAGE="http://wiki.ros.org/${PN}"
138
139 # @FUNCTION: ros-catkin_src_prepare
140 # @DESCRIPTION:
141 # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
142 # by installing a recursive CMakeLists.txt to handle bundles.
143 ros-catkin_src_prepare() {
144         cmake-utils_src_prepare
145
146         if [ ! -f "${S}/CMakeLists.txt" ] ; then
147                 catkin_init_workspace || die
148         fi
149 }
150
151 # @FUNCTION: ros-catkin_src_configure_internal
152 # @DESCRIPTION:
153 # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
154 ros-catkin_src_configure_internal() {
155         if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
156                 local mycmakeargs=("${mycmakeargs[@]}" -DPYTHON_EXECUTABLE="${PYTHON}")
157                 python_export PYTHON_SCRIPTDIR
158         fi
159         cmake-utils_src_configure "${@}"
160 }
161
162 # @VARIABLE: mycatkincmakeargs
163 # @DEFAULT_UNSET
164 # @DESCRIPTION:
165 # Optional cmake defines as a bash array. Should be defined before calling
166 # src_configure.
167
168 # @FUNCTION: ros-catkin_src_configure
169 # @DESCRIPTION:
170 # Configures a catkin-based package.
171 ros-catkin_src_configure() {
172         export CMAKE_PREFIX_PATH="${EPREFIX}/usr"
173         export ROS_ROOT="${EPREFIX}/usr/share/ros"
174         if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
175                 ROS_LANG_DISABLE=""
176                 use ros_messages_cxx    || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
177                 use ros_messages_eus    || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
178                 use ros_messages_lisp   || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
179                 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
180                 use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
181                 export ROS_LANG_DISABLE
182         fi
183         local mycmakeargs=(
184                 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
185                 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
186                 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
187                 "${mycatkincmakeargs[@]}"
188         )
189         if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
190                 python_foreach_impl ros-catkin_src_configure_internal "${@}"
191         else
192                 ros-catkin_src_configure_internal "${@}"
193         fi
194 }
195
196 # @FUNCTION: ros-catkin_src_compile
197 # @DESCRIPTION:
198 # Builds a catkin-based package.
199 ros-catkin_src_compile() {
200         if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
201                 python_foreach_impl cmake-utils_src_compile "${@}"
202         else
203                 cmake-utils_src_compile "${@}"
204         fi
205 }
206
207 # @FUNCTION: ros-catkin_src_test_internal
208 # @DESCRIPTION:
209 # Decorator around cmake-utils_src_test to ensure tests are built before running them.
210 ros-catkin_src_test_internal() {
211         cd "${BUILD_DIR}" || die
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
220 # @FUNCTION: ros-catkin_src_test
221 # @DESCRIPTION:
222 # Run the tests of a catkin-based package.
223 ros-catkin_src_test() {
224         if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
225                 python_foreach_impl ros-catkin_src_test_internal "${@}"
226         else
227                 ros-catkin_src_test_internal "${@}"
228         fi
229 }
230
231 # @FUNCTION: ros-catkin_src_install_with_python
232 # @DESCRIPTION:
233 # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
234 ros-catkin_src_install_with_python() {
235         python_export PYTHON_SCRIPTDIR
236         cmake-utils_src_install "${@}"
237         if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
238                 dodir /usr/bin
239                 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
240                         dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
241                 done
242                 touch "${T}/.catkin_python_symlinks_generated" || die
243         fi
244 }
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
257 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install