ruby-ng.eclass 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: ruby-ng.eclass
  4. # @MAINTAINER:
  5. # Ruby herd <ruby@gentoo.org>
  6. # @AUTHOR:
  7. # Author: Diego E. Pettenò <flameeyes@gentoo.org>
  8. # Author: Alex Legler <a3li@gentoo.org>
  9. # Author: Hans de Graaff <graaff@gentoo.org>
  10. # @BLURB: An eclass for installing Ruby packages with proper support for multiple Ruby slots.
  11. # @DESCRIPTION:
  12. # The Ruby eclass is designed to allow an easier installation of Ruby packages
  13. # and their incorporation into the Gentoo Linux system.
  14. #
  15. # Currently available targets are:
  16. # * ruby19 - Ruby (MRI) 1.9.x
  17. # * ruby20 - Ruby (MRI) 2.0.x
  18. # * ruby21 - Ruby (MRI) 2.1.x
  19. # * ruby22 - Ruby (MRI) 2.2.x
  20. # * ruby23 - Ruby (MRI) 2.3.x
  21. # * ruby24 - Ruby (MRI) 2.4.x
  22. # * jruby - JRuby
  23. # * rbx - Rubinius
  24. #
  25. # This eclass does not define the implementation of the configure,
  26. # compile, test, or install phases. Instead, the default phases are
  27. # used. Specific implementations of these phases can be provided in
  28. # the ebuild either to be run for each Ruby implementation, or for all
  29. # Ruby implementations, as follows:
  30. #
  31. # * each_ruby_configure
  32. # * all_ruby_configure
  33. # @ECLASS-VARIABLE: USE_RUBY
  34. # @DEFAULT_UNSET
  35. # @REQUIRED
  36. # @DESCRIPTION:
  37. # This variable contains a space separated list of targets (see above) a package
  38. # is compatible to. It must be set before the `inherit' call. There is no
  39. # default. All ebuilds are expected to set this variable.
  40. # @ECLASS-VARIABLE: RUBY_PATCHES
  41. # @DEFAULT_UNSET
  42. # @DESCRIPTION:
  43. # A String or Array of filenames of patches to apply to all implementations.
  44. # @ECLASS-VARIABLE: RUBY_OPTIONAL
  45. # @DESCRIPTION:
  46. # Set the value to "yes" to make the dependency on a Ruby interpreter
  47. # optional and then ruby_implementations_depend() to help populate
  48. # DEPEND and RDEPEND.
  49. # @ECLASS-VARIABLE: RUBY_S
  50. # @DEFAULT_UNSET
  51. # @DESCRIPTION:
  52. # If defined this variable determines the source directory name after
  53. # unpacking. This defaults to the name of the package. Note that this
  54. # variable supports a wildcard mechanism to help with github tarballs
  55. # that contain the commit hash as part of the directory name.
  56. # @ECLASS-VARIABLE: RUBY_QA_ALLOWED_LIBS
  57. # @DEFAULT_UNSET
  58. # @DESCRIPTION:
  59. # If defined this variable contains a whitelist of shared objects that
  60. # are allowed to exist even if they don't link to libruby. This avoids
  61. # the QA check that makes this mandatory. This is most likely not what
  62. # you are looking for if you get the related "Missing links" QA warning,
  63. # since the proper fix is almost always to make sure the shared object
  64. # is linked against libruby. There are cases were this is not the case
  65. # and the shared object is generic code to be used in some other way
  66. # (e.g. selenium's firefox driver extension). When set this argument is
  67. # passed to "grep -E" to remove reporting of these shared objects.
  68. local inherits=""
  69. case ${EAPI} in
  70. 2|3|4|5)
  71. inherits="eutils"
  72. ;;
  73. esac
  74. inherit ${inherits} java-utils-2 multilib toolchain-funcs ruby-utils
  75. EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_test src_install pkg_setup
  76. case ${EAPI} in
  77. 0|1)
  78. die "Unsupported EAPI=${EAPI} (too old) for ruby-ng.eclass" ;;
  79. 2|3) ;;
  80. 4|5|6)
  81. # S is no longer automatically assigned when it doesn't exist.
  82. S="${WORKDIR}"
  83. ;;
  84. *)
  85. die "Unknown EAPI=${EAPI} for ruby-ng.eclass"
  86. esac
  87. # @FUNCTION: ruby_implementation_depend
  88. # @USAGE: target [comparator [version]]
  89. # @RETURN: Package atom of a Ruby implementation to be used in dependencies.
  90. # @DESCRIPTION:
  91. # This function returns the formal package atom for a Ruby implementation.
  92. #
  93. # `target' has to be one of the valid values for USE_RUBY (see above)
  94. #
  95. # Set `comparator' and `version' to include a comparator (=, >=, etc.) and a
  96. # version string to the returned string
  97. ruby_implementation_depend() {
  98. _ruby_implementation_depend $1
  99. }
  100. # @FUNCTION: ruby_samelib
  101. # @RETURN: use flag string with current ruby implementations
  102. # @DESCRIPTION:
  103. # Convenience function to output the use dependency part of a
  104. # dependency. Used as a building block for ruby_add_rdepend() and
  105. # ruby_add_bdepend(), but may also be useful in an ebuild to specify
  106. # more complex dependencies.
  107. ruby_samelib() {
  108. local res=
  109. for _ruby_implementation in $USE_RUBY; do
  110. has -${_ruby_implementation} $@ || \
  111. res="${res}ruby_targets_${_ruby_implementation}?,"
  112. done
  113. echo "[${res%,}]"
  114. }
  115. _ruby_atoms_samelib_generic() {
  116. eshopts_push -o noglob
  117. echo "RUBYTARGET? ("
  118. for token in $*; do
  119. case "$token" in
  120. "||" | "(" | ")" | *"?")
  121. echo "${token}" ;;
  122. *])
  123. echo "${token%[*}[RUBYTARGET,${token/*[}" ;;
  124. *)
  125. echo "${token}[RUBYTARGET]" ;;
  126. esac
  127. done
  128. echo ")"
  129. eshopts_pop
  130. }
  131. # @FUNCTION: ruby_implementation_command
  132. # @RETURN: the path to the given ruby implementation
  133. # @DESCRIPTION:
  134. # Not all implementations have the same command basename as the
  135. # target; This function translate between the two
  136. ruby_implementation_command() {
  137. local _ruby_name=$1
  138. # Add all USE_RUBY values where the flag name diverts from the binary here
  139. echo $(type -p ${_ruby_name} 2>/dev/null)
  140. }
  141. _ruby_atoms_samelib() {
  142. local atoms=$(_ruby_atoms_samelib_generic "$*")
  143. for _ruby_implementation in $USE_RUBY; do
  144. echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
  145. done
  146. }
  147. _ruby_wrap_conditions() {
  148. local conditions="$1"
  149. local atoms="$2"
  150. for condition in $conditions; do
  151. atoms="${condition}? ( ${atoms} )"
  152. done
  153. echo "$atoms"
  154. }
  155. # @FUNCTION: ruby_add_rdepend
  156. # @USAGE: dependencies
  157. # @DESCRIPTION:
  158. # Adds the specified dependencies, with use condition(s) to RDEPEND,
  159. # taking the current set of ruby targets into account. This makes sure
  160. # that all ruby dependencies of the package are installed for the same
  161. # ruby targets. Use this function for all ruby dependencies instead of
  162. # setting RDEPEND yourself. The list of atoms uses the same syntax as
  163. # normal dependencies.
  164. #
  165. # Note: runtime dependencies are also added as build-time test
  166. # dependencies.
  167. ruby_add_rdepend() {
  168. case $# in
  169. 1) ;;
  170. 2)
  171. [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_rdepend for $CATEGORY/$PF"
  172. ruby_add_rdepend "$(_ruby_wrap_conditions "$1" "$2")"
  173. return
  174. ;;
  175. *)
  176. die "bad number of arguments to $0"
  177. ;;
  178. esac
  179. local dependency=$(_ruby_atoms_samelib "$1")
  180. RDEPEND="${RDEPEND} $dependency"
  181. # Add the dependency as a test-dependency since we're going to
  182. # execute the code during test phase.
  183. DEPEND="${DEPEND} test? ( ${dependency} )"
  184. has test "$IUSE" || IUSE="${IUSE} test"
  185. }
  186. # @FUNCTION: ruby_add_bdepend
  187. # @USAGE: dependencies
  188. # @DESCRIPTION:
  189. # Adds the specified dependencies, with use condition(s) to DEPEND,
  190. # taking the current set of ruby targets into account. This makes sure
  191. # that all ruby dependencies of the package are installed for the same
  192. # ruby targets. Use this function for all ruby dependencies instead of
  193. # setting DEPEND yourself. The list of atoms uses the same syntax as
  194. # normal dependencies.
  195. ruby_add_bdepend() {
  196. case $# in
  197. 1) ;;
  198. 2)
  199. [[ "${GENTOO_DEV}" == "yes" ]] && eqawarn "You can now use the usual syntax in ruby_add_bdepend for $CATEGORY/$PF"
  200. ruby_add_bdepend "$(_ruby_wrap_conditions "$1" "$2")"
  201. return
  202. ;;
  203. *)
  204. die "bad number of arguments to $0"
  205. ;;
  206. esac
  207. local dependency=$(_ruby_atoms_samelib "$1")
  208. DEPEND="${DEPEND} $dependency"
  209. RDEPEND="${RDEPEND}"
  210. }
  211. # @FUNCTION: ruby_get_use_implementations
  212. # @DESCRIPTION:
  213. # Gets an array of ruby use targets enabled by the user
  214. ruby_get_use_implementations() {
  215. local i implementation
  216. for implementation in ${USE_RUBY}; do
  217. use ruby_targets_${implementation} && i+=" ${implementation}"
  218. done
  219. echo $i
  220. }
  221. # @FUNCTION: ruby_get_use_targets
  222. # @DESCRIPTION:
  223. # Gets an array of ruby use targets that the ebuild sets
  224. ruby_get_use_targets() {
  225. local t implementation
  226. for implementation in ${USE_RUBY}; do
  227. t+=" ruby_targets_${implementation}"
  228. done
  229. echo $t
  230. }
  231. # @FUNCTION: ruby_implementations_depend
  232. # @RETURN: Dependencies suitable for injection into DEPEND and RDEPEND.
  233. # @DESCRIPTION:
  234. # Produces the dependency string for the various implementations of ruby
  235. # which the package is being built against. This should not be used when
  236. # RUBY_OPTIONAL is unset but must be used if RUBY_OPTIONAL=yes. Do not
  237. # confuse this function with ruby_implementation_depend().
  238. #
  239. # @EXAMPLE:
  240. # EAPI=6
  241. # RUBY_OPTIONAL=yes
  242. #
  243. # inherit ruby-ng
  244. # ...
  245. # DEPEND="ruby? ( $(ruby_implementations_depend) )"
  246. # RDEPEND="${DEPEND}"
  247. ruby_implementations_depend() {
  248. local depend
  249. for _ruby_implementation in ${USE_RUBY}; do
  250. depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )"
  251. done
  252. echo "${depend}"
  253. }
  254. IUSE+=" $(ruby_get_use_targets)"
  255. # If you specify RUBY_OPTIONAL you also need to take care of
  256. # ruby useflag and dependency.
  257. if [[ ${RUBY_OPTIONAL} != yes ]]; then
  258. DEPEND="${DEPEND} $(ruby_implementations_depend)"
  259. RDEPEND="${RDEPEND} $(ruby_implementations_depend)"
  260. case ${EAPI:-0} in
  261. 4|5|6)
  262. REQUIRED_USE+=" || ( $(ruby_get_use_targets) )"
  263. ;;
  264. esac
  265. fi
  266. _ruby_invoke_environment() {
  267. old_S=${S}
  268. case ${EAPI} in
  269. 4|5|6)
  270. if [ -z "${RUBY_S}" ]; then
  271. sub_S=${P}
  272. else
  273. sub_S=${RUBY_S}
  274. fi
  275. ;;
  276. *)
  277. sub_S=${S#${WORKDIR}/}
  278. ;;
  279. esac
  280. # Special case, for the always-lovely GitHub fetches. With this,
  281. # we allow the star glob to just expand to whatever directory it's
  282. # called.
  283. if [[ "${sub_S}" = *"*"* ]]; then
  284. case ${EAPI} in
  285. 2|3)
  286. #The old method of setting S depends on undefined package
  287. # manager behaviour, so encourage upgrading to EAPI=4.
  288. eqawarn "Using * expansion of S is deprecated. Use EAPI and RUBY_S instead."
  289. ;;
  290. esac
  291. pushd "${WORKDIR}"/all &>/dev/null || die
  292. # use an array to trigger filename expansion
  293. # fun fact: this expansion fails in src_unpack() but the original
  294. # code did not have any checks for failed expansion, so we can't
  295. # really add one now without redesigning stuff hard.
  296. sub_S=( ${sub_S} )
  297. if [[ ${#sub_S[@]} -gt 1 ]]; then
  298. die "sub_S did expand to multiple paths: ${sub_S[*]}"
  299. fi
  300. popd &>/dev/null || die
  301. fi
  302. environment=$1; shift
  303. my_WORKDIR="${WORKDIR}"/${environment}
  304. S="${my_WORKDIR}"/"${sub_S}"
  305. if [[ -d "${S}" ]]; then
  306. pushd "$S" &>/dev/null || die
  307. elif [[ -d "${my_WORKDIR}" ]]; then
  308. pushd "${my_WORKDIR}" &>/dev/null || die
  309. else
  310. pushd "${WORKDIR}" &>/dev/null || die
  311. fi
  312. ebegin "Running ${_PHASE:-${EBUILD_PHASE}} phase for $environment"
  313. "$@"
  314. popd &>/dev/null || die
  315. S=${old_S}
  316. }
  317. _ruby_each_implementation() {
  318. local invoked=no
  319. for _ruby_implementation in ${USE_RUBY}; do
  320. # only proceed if it's requested
  321. use ruby_targets_${_ruby_implementation} || continue
  322. RUBY=$(ruby_implementation_command ${_ruby_implementation})
  323. invoked=yes
  324. if [[ -n "$1" ]]; then
  325. _ruby_invoke_environment ${_ruby_implementation} "$@"
  326. fi
  327. unset RUBY
  328. done
  329. if [[ ${invoked} == "no" ]]; then
  330. eerror "You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf."
  331. eerror "Compatible targets for this package are: ${USE_RUBY}"
  332. eerror
  333. eerror "See https://www.gentoo.org/proj/en/prog_lang/ruby/index.xml#doc_chap3 for more information."
  334. eerror
  335. die "No compatible Ruby target selected."
  336. fi
  337. }
  338. # @FUNCTION: ruby-ng_pkg_setup
  339. # @DESCRIPTION:
  340. # Check whether at least one ruby target implementation is present.
  341. ruby-ng_pkg_setup() {
  342. # This only checks that at least one implementation is present
  343. # before doing anything; by leaving the parameters empty we know
  344. # it's a special case.
  345. _ruby_each_implementation
  346. has ruby_targets_jruby ${IUSE} && use ruby_targets_jruby && java-pkg_setup-vm
  347. }
  348. # @FUNCTION: ruby-ng_src_unpack
  349. # @DESCRIPTION:
  350. # Unpack the source archive.
  351. ruby-ng_src_unpack() {
  352. mkdir "${WORKDIR}"/all
  353. pushd "${WORKDIR}"/all &>/dev/null || die
  354. # We don't support an each-unpack, it's either all or nothing!
  355. if type all_ruby_unpack &>/dev/null; then
  356. _ruby_invoke_environment all all_ruby_unpack
  357. else
  358. [[ -n ${A} ]] && unpack ${A}
  359. fi
  360. popd &>/dev/null || die
  361. }
  362. _ruby_apply_patches() {
  363. case ${EAPI} in
  364. 2|3|4|5)
  365. for patch in "${RUBY_PATCHES[@]}"; do
  366. if [ -f "${patch}" ]; then
  367. epatch "${patch}"
  368. elif [ -f "${FILESDIR}/${patch}" ]; then
  369. epatch "${FILESDIR}/${patch}"
  370. else
  371. die "Cannot find patch ${patch}"
  372. fi
  373. done
  374. ;;
  375. 6)
  376. if [[ -n ${RUBY_PATCHES[@]} ]]; then
  377. eqawarn "RUBY_PATCHES is no longer supported, use PATCHES instead"
  378. fi
  379. ;;
  380. esac
  381. # This is a special case: instead of executing just in the special
  382. # "all" environment, this will actually copy the effects on _all_
  383. # the other environments, and is thus executed before the copy
  384. type all_ruby_prepare &>/dev/null && all_ruby_prepare
  385. }
  386. _ruby_source_copy() {
  387. # Until we actually find a reason not to, we use hardlinks, this
  388. # should reduce the amount of disk space that is wasted by this.
  389. cp -prlP all ${_ruby_implementation} \
  390. || die "Unable to copy ${_ruby_implementation} environment"
  391. }
  392. # @FUNCTION: ruby-ng_src_prepare
  393. # @DESCRIPTION:
  394. # Apply patches and prepare versions for each ruby target
  395. # implementation. Also carry out common clean up tasks.
  396. ruby-ng_src_prepare() {
  397. # Way too many Ruby packages are prepared on OSX without removing
  398. # the extra data forks, we do it here to avoid repeating it for
  399. # almost every other ebuild.
  400. find . -name '._*' -delete
  401. # Handle PATCHES and user supplied patches via the default phase
  402. case ${EAPI} in
  403. 6)
  404. _ruby_invoke_environment all default
  405. ;;
  406. esac
  407. _ruby_invoke_environment all _ruby_apply_patches
  408. _PHASE="source copy" \
  409. _ruby_each_implementation _ruby_source_copy
  410. if type each_ruby_prepare &>/dev/null; then
  411. _ruby_each_implementation each_ruby_prepare
  412. fi
  413. }
  414. # @FUNCTION: ruby-ng_src_configure
  415. # @DESCRIPTION:
  416. # Configure the package.
  417. ruby-ng_src_configure() {
  418. if type each_ruby_configure &>/dev/null; then
  419. _ruby_each_implementation each_ruby_configure
  420. fi
  421. type all_ruby_configure &>/dev/null && \
  422. _ruby_invoke_environment all all_ruby_configure
  423. }
  424. # @FUNCTION: ruby-ng_src_compile
  425. # @DESCRIPTION:
  426. # Compile the package.
  427. ruby-ng_src_compile() {
  428. if type each_ruby_compile &>/dev/null; then
  429. _ruby_each_implementation each_ruby_compile
  430. fi
  431. type all_ruby_compile &>/dev/null && \
  432. _ruby_invoke_environment all all_ruby_compile
  433. }
  434. # @FUNCTION: ruby-ng_src_test
  435. # @DESCRIPTION:
  436. # Run tests for the package.
  437. ruby-ng_src_test() {
  438. if type each_ruby_test &>/dev/null; then
  439. _ruby_each_implementation each_ruby_test
  440. fi
  441. type all_ruby_test &>/dev/null && \
  442. _ruby_invoke_environment all all_ruby_test
  443. }
  444. _each_ruby_check_install() {
  445. local scancmd=scanelf
  446. # we have a Mach-O object here
  447. [[ ${CHOST} == *-darwin ]] && scancmd=scanmacho
  448. has "${EAPI}" 2 && ! use prefix && EPREFIX=
  449. local libruby_basename=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["LIBRUBY_SO"]')
  450. local libruby_soname=$(basename $(${scancmd} -F "%S#F" -qS "${EPREFIX}/usr/$(get_libdir)/${libruby_basename}") 2>/dev/null)
  451. local sitedir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitedir"]')
  452. local sitelibdir=$(${RUBY} -rrbconfig -e 'puts RbConfig::CONFIG["sitelibdir"]')
  453. # Look for wrong files in sitedir
  454. # if [[ -d "${D}${sitedir}" ]]; then
  455. # local f=$(find "${D}${sitedir}" -mindepth 1 -maxdepth 1 -not -wholename "${D}${sitelibdir}")
  456. # if [[ -n ${f} ]]; then
  457. # eerror "Found files in sitedir, outsite sitelibdir:"
  458. # eerror "${f}"
  459. # die "Misplaced files in sitedir"
  460. # fi
  461. # fi
  462. # The current implementation lacks libruby (i.e.: jruby)
  463. [[ -z ${libruby_soname} ]] && return 0
  464. # Check also the gems directory, since we could be installing compiled
  465. # extensions via ruby-fakegem; make sure to check only in sitelibdir, since
  466. # that's what changes between two implementations (otherwise you'd get false
  467. # positives now that Ruby 1.9.2 installs with the same sitedir as 1.8)
  468. ${scancmd} -qnR "${D}${sitelibdir}" "${D}${sitelibdir/site_ruby/gems}" \
  469. | fgrep -v "${libruby_soname}" \
  470. | grep -E -v "${RUBY_QA_ALLOWED_LIBS}" \
  471. > "${T}"/ruby-ng-${_ruby_implementation}-mislink.log
  472. if [[ -s "${T}"/ruby-ng-${_ruby_implementation}-mislink.log ]]; then
  473. ewarn "Extensions installed for ${_ruby_implementation} with missing links to ${libruby_soname}"
  474. ewarn $(< "${T}"/ruby-ng-${_ruby_implementation}-mislink.log )
  475. die "Missing links to ${libruby_soname}"
  476. fi
  477. }
  478. # @FUNCTION: ruby-ng_src_install
  479. # @DESCRIPTION:
  480. # Install the package for each ruby target implementation.
  481. ruby-ng_src_install() {
  482. if type each_ruby_install &>/dev/null; then
  483. _ruby_each_implementation each_ruby_install
  484. fi
  485. type all_ruby_install &>/dev/null && \
  486. _ruby_invoke_environment all all_ruby_install
  487. _PHASE="check install" \
  488. _ruby_each_implementation _each_ruby_check_install
  489. }
  490. # @FUNCTION: ruby_rbconfig_value
  491. # @USAGE: rbconfig item
  492. # @RETURN: Returns the value of the given rbconfig item of the Ruby interpreter in ${RUBY}.
  493. ruby_rbconfig_value() {
  494. echo $(${RUBY} -rrbconfig -e "puts RbConfig::CONFIG['$1']")
  495. }
  496. # @FUNCTION: doruby
  497. # @USAGE: file [file...]
  498. # @DESCRIPTION:
  499. # Installs the specified file(s) into the sitelibdir of the Ruby interpreter in ${RUBY}.
  500. doruby() {
  501. [[ -z ${RUBY} ]] && die "\$RUBY is not set"
  502. has "${EAPI}" 2 && ! use prefix && EPREFIX=
  503. ( # don't want to pollute calling env
  504. sitelibdir=$(ruby_rbconfig_value 'sitelibdir')
  505. insinto ${sitelibdir#${EPREFIX}}
  506. insopts -m 0644
  507. doins "$@"
  508. ) || die "failed to install $@"
  509. }
  510. # @FUNCTION: ruby_get_libruby
  511. # @RETURN: The location of libruby*.so belonging to the Ruby interpreter in ${RUBY}.
  512. ruby_get_libruby() {
  513. ${RUBY} -rrbconfig -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY"])'
  514. }
  515. # @FUNCTION: ruby_get_hdrdir
  516. # @RETURN: The location of the header files belonging to the Ruby interpreter in ${RUBY}.
  517. ruby_get_hdrdir() {
  518. local rubyhdrdir=$(ruby_rbconfig_value 'rubyhdrdir')
  519. if [[ "${rubyhdrdir}" = "nil" ]] ; then
  520. rubyhdrdir=$(ruby_rbconfig_value 'archdir')
  521. fi
  522. echo "${rubyhdrdir}"
  523. }
  524. # @FUNCTION: ruby_get_version
  525. # @RETURN: The version of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
  526. ruby_get_version() {
  527. local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
  528. echo $(${ruby} -e 'puts RUBY_VERSION')
  529. }
  530. # @FUNCTION: ruby_get_implementation
  531. # @RETURN: The implementation of the Ruby interpreter in ${RUBY}, or what 'ruby' points to.
  532. ruby_get_implementation() {
  533. local ruby=${RUBY:-$(type -p ruby 2>/dev/null)}
  534. case $(${ruby} --version) in
  535. *jruby*)
  536. echo "jruby"
  537. ;;
  538. *rubinius*)
  539. echo "rbx"
  540. ;;
  541. *)
  542. echo "mri"
  543. ;;
  544. esac
  545. }
  546. # @FUNCTION: ruby-ng_rspec <arguments>
  547. # @DESCRIPTION:
  548. # This is simply a wrapper around the rspec command (executed by $RUBY})
  549. # which also respects TEST_VERBOSE and NOCOLOR environment variables.
  550. # Optionally takes arguments to pass on to the rspec invocation. The
  551. # environment variable RSPEC_VERSION can be used to control the specific
  552. # rspec version that must be executed. It defaults to 2 for historical
  553. # compatibility.
  554. ruby-ng_rspec() {
  555. local version=${RSPEC_VERSION-2}
  556. local files="$@"
  557. # Explicitly pass the expected spec directory since the versioned
  558. # rspec wrappers don't handle this automatically.
  559. if [ ${#@} -eq 0 ]; then
  560. files="spec"
  561. fi
  562. if [[ ${DEPEND} != *"dev-ruby/rspec"* ]]; then
  563. ewarn "Missing dev-ruby/rspec in \${DEPEND}"
  564. fi
  565. local rspec_params=
  566. case ${NOCOLOR} in
  567. 1|yes|true)
  568. rspec_params+=" --no-color"
  569. ;;
  570. *)
  571. rspec_params+=" --color"
  572. ;;
  573. esac
  574. case ${TEST_VERBOSE} in
  575. 1|yes|true)
  576. rspec_params+=" --format documentation"
  577. ;;
  578. *)
  579. rspec_params+=" --format progress"
  580. ;;
  581. esac
  582. ${RUBY} -S rspec-${version} ${rspec_params} ${files} || die "rspec failed"
  583. }
  584. # @FUNCTION: ruby-ng_cucumber
  585. # @DESCRIPTION:
  586. # This is simply a wrapper around the cucumber command (executed by $RUBY})
  587. # which also respects TEST_VERBOSE and NOCOLOR environment variables.
  588. ruby-ng_cucumber() {
  589. if [[ ${DEPEND} != *"dev-util/cucumber"* ]]; then
  590. ewarn "Missing dev-util/cucumber in \${DEPEND}"
  591. fi
  592. local cucumber_params=
  593. case ${NOCOLOR} in
  594. 1|yes|true)
  595. cucumber_params+=" --no-color"
  596. ;;
  597. *)
  598. cucumber_params+=" --color"
  599. ;;
  600. esac
  601. case ${TEST_VERBOSE} in
  602. 1|yes|true)
  603. cucumber_params+=" --format pretty"
  604. ;;
  605. *)
  606. cucumber_params+=" --format progress"
  607. ;;
  608. esac
  609. if [[ ${RUBY} == *jruby ]]; then
  610. ewarn "Skipping cucumber tests on JRuby (unsupported)."
  611. return 0
  612. fi
  613. ${RUBY} -S cucumber ${cucumber_params} "$@" || die "cucumber failed"
  614. }
  615. # @FUNCTION: ruby-ng_testrb-2
  616. # @DESCRIPTION:
  617. # This is simply a replacement for the testrb command that load the test
  618. # files and execute them, with test-unit 2.x. This actually requires
  619. # either an old test-unit-2 version or 2.5.1-r1 or later, as they remove
  620. # their script and we installed a broken wrapper for a while.
  621. # This also respects TEST_VERBOSE and NOCOLOR environment variables.
  622. ruby-ng_testrb-2() {
  623. if [[ ${DEPEND} != *"dev-ruby/test-unit"* ]]; then
  624. ewarn "Missing dev-ruby/test-unit in \${DEPEND}"
  625. fi
  626. local testrb_params=
  627. case ${NOCOLOR} in
  628. 1|yes|true)
  629. testrb_params+=" --no-use-color"
  630. ;;
  631. *)
  632. testrb_params+=" --use-color=auto"
  633. ;;
  634. esac
  635. case ${TEST_VERBOSE} in
  636. 1|yes|true)
  637. testrb_params+=" --verbose=verbose"
  638. ;;
  639. *)
  640. testrb_params+=" --verbose=normal"
  641. ;;
  642. esac
  643. ${RUBY} -S testrb-2 ${testrb_params} "$@" || die "testrb-2 failed"
  644. }