net-irc/limnoria: use HTTPS for GitHub and HOMEPAGE
[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 # This should be temporary. ROS only really works with one global python
46 # version. The idea here is to have a ROS_COMPAT in the same vein as
47 # PYTHON_COMPAT where packages would define what distro they can work on, then
48 # we'd have ros_distro_gentoo_python_2_7 & co plus the OSRF ones (lunar, etc.).
49 # Note that this uncondtionally pulls python but in the ROS world there will
50 # most certainly be something pulling python anyway.
51 PYTHON_COMPAT=( python2_7 )
52
53 inherit ${SCM} python-r1 cmake-utils flag-o-matic
54
55 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
56
57 IUSE="test"
58 RDEPEND="${PYTHON_DEPS}"
59 DEPEND="${RDEPEND}
60         dev-util/catkin[${PYTHON_USEDEP}]
61         dev-python/empy[${PYTHON_USEDEP}]
62 "
63
64 # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
65 # @DESCRIPTION:
66 # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
67 # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
68
69 # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
70 # @DESCRIPTION:
71 # Some messages have dependencies on other messages.
72 # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
73 # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
74 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
75         IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp ros_messages_nodejs"
76         RDEPEND="${RDEPEND}
77                 ros_messages_cxx?    ( dev-ros/gencpp:=    dev-ros/gencpp[${PYTHON_USEDEP}]    )
78                 ros_messages_eus?    ( dev-ros/geneus:=    dev-ros/geneus[${PYTHON_USEDEP}]    )
79                 ros_messages_python? ( dev-ros/genpy:=     dev-ros/genpy[${PYTHON_USEDEP}]     )
80                 ros_messages_lisp?   ( dev-ros/genlisp:=   dev-ros/genlisp[${PYTHON_USEDEP}]   )
81                 ros_messages_nodejs? ( dev-ros/gennodejs:= dev-ros/gennodejs[${PYTHON_USEDEP}] )
82                 dev-ros/message_runtime
83         "
84         DEPEND="${DEPEND} ${RDEPEND}
85                 dev-ros/message_generation
86                 dev-ros/genmsg[${PYTHON_USEDEP}]
87         "
88         if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
89                 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
90                         ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
91                         RDEPEND="${RDEPEND} ${ds}"
92                         DEPEND="${DEPEND} ${ds}"
93                 done
94         fi
95 fi
96
97 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
98 # @DESCRIPTION:
99 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
100 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
101
102 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
103 # @DESCRIPTION:
104 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
105 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
106
107 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
108 # @DESCRIPTION:
109 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
110 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
111
112 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
113 # @DESCRIPTION:
114 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
115 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
116
117 # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
118 # @DESCRIPTION:
119 # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
120 CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
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         # If no multibuild, just use cmake IN_SOURCE support
139         [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && export CMAKE_IN_SOURCE_BUILD=yes
140
141         cmake-utils_src_prepare
142
143         if [ ! -f "${S}/CMakeLists.txt" ] ; then
144                 catkin_init_workspace || die
145         fi
146
147         # Most packages require C++11 these days. Do it here, in src_prepare so that
148         # ebuilds can override it in src_configure.
149         append-cxxflags '-std=c++11'
150 }
151
152 # @FUNCTION: ros-catkin_python_setup
153 # @DESCRIPTION:
154 # Sets up python environment for ROS packages.
155 ros-catkin_python_setup() {
156         # Todo: Need to match this with ros distro.
157         local pyimpl="${PYTHON_COMPAT[0]}"
158         python_export "${pyimpl}" EPYTHON PYTHON
159         python_wrapper_setup
160         python_export PYTHON_SCRIPTDIR
161 }
162
163 # @VARIABLE: mycatkincmakeargs
164 # @DEFAULT_UNSET
165 # @DESCRIPTION:
166 # Optional cmake defines as a bash array. Should be defined before calling
167 # src_configure.
168
169 # @FUNCTION: ros-catkin_src_configure
170 # @DESCRIPTION:
171 # Configures a catkin-based package.
172 ros-catkin_src_configure() {
173         ros-catkin_python_setup
174
175         export CATKIN_PREFIX_PATH="${EPREFIX}/usr"
176         export ROS_ROOT="${EPREFIX}/usr/share/ros"
177         if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
178                 ROS_LANG_DISABLE=""
179                 use ros_messages_cxx    || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
180                 use ros_messages_eus    || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
181                 use ros_messages_lisp   || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
182                 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
183                 use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
184                 export ROS_LANG_DISABLE
185         fi
186
187         local mycmakeargs=(
188                 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
189                 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
190                 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
191                 "${mycatkincmakeargs[@]}"
192         )
193
194         local sitedir="$(python_get_sitedir)"
195         mycmakeargs+=(
196                 -DPYTHON_EXECUTABLE="${PYTHON}"
197                 -DPYTHON_INSTALL_DIR="${sitedir#${EPREFIX}/usr/}"
198         )
199         if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
200                 export CMAKE_USE_DIR="${BUILD_DIR}"
201         fi
202
203         cmake-utils_src_configure "${@}"
204 }
205
206 # @FUNCTION: ros-catkin_src_compile
207 # @DESCRIPTION:
208 # Builds a catkin-based package.
209 ros-catkin_src_compile() {
210         ros-catkin_python_setup
211         cmake-utils_src_compile "${@}"
212 }
213
214 # @FUNCTION: ros-catkin_src_test
215 # @DESCRIPTION:
216 # Run the tests of a catkin-based package.
217 ros-catkin_src_test() {
218         cd "${BUILD_DIR}" || die
219
220         ros-catkin_python_setup
221
222         # Regenerate env for tests, PYTHONPATH is not set properly otherwise...
223         if [ -f catkin_generated/generate_cached_setup.py ] ; then
224                 einfo "Regenerating setup_cached.sh for tests"
225                 ${PYTHON:-python} catkin_generated/generate_cached_setup.py || die
226         fi
227         # Using cmake-utils_src_make with nonfatal does not work and breaks e.g.
228         # dev-ros/rviz.
229         if nonfatal emake tests -n &> /dev/null ; then
230                 cmake-utils_src_make tests
231         fi
232         cmake-utils_src_test "${@}"
233 }
234
235 # @FUNCTION: ros-catkin_src_install
236 # @DESCRIPTION:
237 # Installs a catkin-based package.
238 ros-catkin_src_install() {
239         ros-catkin_python_setup
240
241         if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
242                 export CMAKE_USE_DIR="${BUILD_DIR}"
243         fi
244
245         cmake-utils_src_install "${@}"
246         if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
247                 dodir /usr/bin
248                 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
249                         dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
250                 done
251                 touch "${T}/.catkin_python_symlinks_generated" || die
252         fi
253 }
254
255 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install