Gentoo Archives: gentoo-dev

From: Alexis Ballier <aballier@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] New eclass: ros-catkin.eclass, new USE_EXPAND: ROS_MESSAGES, new categories: dev-ros and ros-meta for review.
Date: Thu, 17 Sep 2015 16:36:30
Message-Id: 20150917183606.7a74139b@gentoo.org
1 Hi all,
2
3 As part of an effort of bringing ros (http://www.ros.org/) to Gentoo,
4 I've come up with the following design:
5
6 ros-catkin.eclass that is a template, merging all common code for
7 catkinized ros packages.
8
9 ROS_MESSAGES will be a new USE_EXPANDed variable: ROS is message
10 based, processes write and listen to some topic, and a topic is typed
11 with a message. Messages are defined by simple text files but are then
12 pre-processed for easy usage in C++, Python & co.
13
14 Several packages are usually bundled in a single repository, with a
15 meta-package pulling all the others. Hence, I came with two new
16 categories: dev-ros for single packages, ros-meta for those
17 meta-packages.
18
19 Some numbers:
20 /bin/ls ros-meta | wc -l
21 52
22 /bin/ls dev-ros | wc -l
23 350
24
25
26 I think maybe half of them are in a state that they can be added to
27 gentoo-x86.
28
29
30 ebuild example:
31
32 $ cat roslib-1.12.2.ebuild
33 # Copyright 1999-2014 Gentoo Foundation
34 # Distributed under the terms of the GNU General Public License v2
35 # $Header: $
36
37 EAPI=5
38
39 ROS_REPO_URI="https://github.com/ros/ros"
40 KEYWORDS="~amd64 ~arm"
41 PYTHON_COMPAT=( python{2_7,3_3,3_4} )
42 ROS_SUBDIR=core/${PN}
43
44 inherit ros-catkin
45
46 DESCRIPTION="Base dependencies and support libraries for ROS"
47 LICENSE="BSD"
48 SLOT="0"
49 IUSE=""
50
51 RDEPEND="
52 dev-python/rospkg[${PYTHON_USEDEP}]
53 dev-libs/boost:=[threads]
54 dev-ros/rospack
55 "
56 DEPEND="${RDEPEND}
57 test? ( dev-ros/rosmake ros-meta/ros )"
58
59
60
61
62
63 Eclass inlined at the end.
64
65 Best regards,
66
67 Alexis.
68
69 # Copyright 1999-2015 Gentoo Foundation
70 # Distributed under the terms of the GNU General Public License v2
71 # $Id$
72
73 # @ECLASS: ros-catkin.eclass
74 # @MAINTAINER:
75 # ros@g.o
76 # @AUTHOR:
77 # Alexis Ballier <aballier@g.o>
78 # @BLURB: Template eclass for catkin based ROS packages.
79 # @DESCRIPTION:
80 # Provides function for building ROS packages on Gentoo.
81 # It supports selectively building messages, multi-python installation, live ebuilds (git only).
82
83 # @ECLASS-VARIABLE: ROS_REPO_URI
84 # @DESCRIPTION:
85 # URL of the upstream repository. Usually on github.
86 # Serves for fetching tarballs, live ebuilds and inferring the meta-package name.
87 EGIT_REPO_URI="${ROS_REPO_URI}"
88
89 # @ECLASS-VARIABLE: ROS_SUBDIR
90 # @DEFAULT_UNSET
91 # @DESCRIPTION:
92 # Subdir in which current packages is located.
93 # Usually, a repository contains several packages, hence a typical value is:
94 # ROS_SUBDIR=${PN}
95
96 SCM=""
97 if [ "${PV#9999}" != "${PV}" ] ; then
98 SCM="git-r3"
99 fi
100
101 # @ECLASS-VARIABLE: PYTHON_COMPAT
102 # @DESCRIPTION:
103 # Tells the eclass the package has python code and forwards it to python-r1.eclass.
104 PYTHON_ECLASS=""
105 CATKIN_PYTHON_USEDEP=""
106 if [ -n "${PYTHON_COMPAT}" ] ; then
107 PYTHON_ECLASS="python-r1 python-utils-r1"
108 fi
109
110 inherit ${SCM} ${PYTHON_ECLASS} cmake-utils
111
112 CATKIN_DO_PYTHON_MULTIBUILD=""
113 if [ -n "${PYTHON_COMPAT}" ] ; then
114 CATKIN_PYTHON_USEDEP="[${PYTHON_USEDEP}]"
115 CATKIN_DO_PYTHON_MULTIBUILD="yes"
116 fi
117
118 IUSE="test"
119 RDEPEND="
120 dev-util/catkin${CATKIN_PYTHON_USEDEP}
121 dev-python/empy${CATKIN_PYTHON_USEDEP}
122 "
123 DEPEND="${RDEPEND}"
124
125 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
126 RDEPEND="${RDEPEND} dev-lang/python-exec:2"
127 fi
128
129 # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
130 # @DESCRIPTION:
131 # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
132 # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
133
134 # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
135 # @DESCRIPTION:
136 # Some messages have dependencies on other messages.
137 # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
138 # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
139 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
140 IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp"
141 RDEPEND="${RDEPEND}
142 ros_messages_cxx? ( dev-ros/gencpp:=${CATKIN_PYTHON_USEDEP} )
143 ros_messages_eus? ( dev-ros/geneus:=${CATKIN_PYTHON_USEDEP} )
144 ros_messages_python? ( dev-ros/genpy:=${CATKIN_PYTHON_USEDEP} )
145 ros_messages_lisp? ( dev-ros/genlisp:=${CATKIN_PYTHON_USEDEP} )
146 dev-ros/message_runtime
147 "
148 DEPEND="${DEPEND} ${RDEPEND}
149 dev-ros/message_generation
150 dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
151 "
152 if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
153 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
154 ds="${i}[ros_messages_python?,ros_messages_cxx?,ros_messages_lisp?,ros_messages_eus?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
155 RDEPEND="${RDEPEND} ${ds}"
156 DEPEND="${DEPEND} ${ds}"
157 done
158 fi
159 fi
160
161 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
162 # @DESCRIPTION:
163 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
164 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx"
165
166 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
167 # @DESCRIPTION:
168 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
169 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python,${PYTHON_USEDEP}"
170
171 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
172 # @DESCRIPTION:
173 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
174 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp"
175
176 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
177 # @DESCRIPTION:
178 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
179 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus"
180
181 if [ "${PV#9999}" != "${PV}" ] ; then
182 SRC_URI=""
183 KEYWORDS=""
184 S=${WORKDIR}/${P}/${ROS_SUBDIR}
185 else
186 SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
187 S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}/${ROS_SUBDIR}
188 fi
189
190 HOMEPAGE="http://wiki.ros.org/${PN}"
191
192 # @FUNCTION: ros-catkin_src_prepare
193 # @DESCRIPTION:
194 # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
195 # by installing a recursive CMakeLists.txt to handle bundles.
196 ros-catkin_src_prepare() {
197 cmake-utils_src_prepare
198
199 if [ ! -f "${S}/CMakeLists.txt" ] ; then
200 catkin_init_workspace || die
201 fi
202 }
203
204 # @FUNCTION: ros-catkin_src_configure_internal
205 # @DESCRIPTION:
206 # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
207 ros-catkin_src_configure_internal() {
208 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
209 local mycmakeargs=("${mycmakeargs[@]}" -DPYTHON_EXECUTABLE="${PYTHON}")
210 python_export PYTHON_SCRIPTDIR
211 fi
212 cmake-utils_src_configure
213 }
214
215 # @VARIABLE: mycatkincmakeargs
216 # @DEFAULT_UNSET
217 # @DESCRIPTION:
218 # Optional cmake defines as a bash array. Should be defined before calling
219 # src_configure.
220
221 # @FUNCTION: ros-catkin_src_configure
222 # @DESCRIPTION:
223 # Configures a catkin-based package.
224 ros-catkin_src_configure() {
225 export CMAKE_PREFIX_PATH="${EPREFIX}/usr"
226 export ROS_ROOT="${EPREFIX}/usr/share/ros"
227 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
228 ROS_LANG_DISABLE=""
229 use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
230 use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
231 use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
232 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
233 export ROS_LANG_DISABLE
234 fi
235 local mycmakeargs=(
236 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
237 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
238 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
239 "${mycatkincmakeargs[@]}"
240 )
241 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
242 python_foreach_impl ros-catkin_src_configure_internal
243 else
244 ros-catkin_src_configure_internal
245 fi
246 }
247
248 # @FUNCTION: ros-catkin_src_compile
249 # @DESCRIPTION:
250 # Builds a catkin-based package.
251 ros-catkin_src_compile() {
252 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
253 python_foreach_impl cmake-utils_src_compile
254 else
255 cmake-utils_src_compile
256 fi
257 }
258
259 # @FUNCTION: ros-catkin_src_test_internal
260 # @DESCRIPTION:
261 # Decorator around cmake-utils_src_test to ensure tests are built before running them.
262 ros-catkin_src_test_internal() {
263 cd "${BUILD_DIR}"
264 if nonfatal emake tests -n &> /dev/null ; then
265 emake VERBOSE=1 tests || die
266 fi
267 cmake-utils_src_test
268 }
269
270 # @FUNCTION: ros-catkin_src_test
271 # @DESCRIPTION:
272 # Run the tests of a catkin-based package.
273 ros-catkin_src_test() {
274 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
275 python_foreach_impl ros-catkin_src_test_internal
276 else
277 ros-catkin_src_test_internal
278 fi
279 }
280
281 # @FUNCTION: ros-catkin_src_install_with_python
282 # @DESCRIPTION:
283 # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
284 ros-catkin_src_install_with_python() {
285 python_export PYTHON_SCRIPTDIR
286 cmake-utils_src_install
287 if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
288 dodir /usr/bin
289 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
290 dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}" || die
291 done
292 touch "${T}/.catkin_python_symlinks_generated"
293 fi
294 }
295
296 # @FUNCTION: ros-catkin_src_install
297 # @DESCRIPTION:
298 # Installs a catkin-based package.
299 ros-catkin_src_install() {
300 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
301 python_foreach_impl ros-catkin_src_install_with_python
302 else
303 cmake-utils_src_install
304 fi
305 }
306
307 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install

Replies