--- /usr/portage/eclass/gems.eclass 2008-02-17 09:05:59.000000000 +0000 +++ gems.eclass 2008-07-04 23:03:09.000000000 +0100 @@ -10,10 +10,13 @@ # the Gentoo Linux system. # # - Features: -# gems_location() - Set ${GEMSDIR} with gem install dir and ${GEM_SRC} with path to gem to install +# gems_location() - Set ${GEMSDIR} with gem install dir and ${GEM_SRC} with +# path to gem to install. Optionally takes a ruby version string, like +# "ruby18" as a parameter. # gems_src_unpack() - Does nothing. # gems_src_compile() - Does nothing. -# gems_src_install() - installs a gem into ${D} +# gems_src_install() - installs a gem into ${D} using each ruby version that is both +# installed and specified in USE_RUBY. # # NOTE: # See http://dev.gentoo.org/~pythonhead/ruby/gems.html for notes on using gems with portage @@ -33,9 +36,14 @@ gems_location() { local sitelibdir - sitelibdir=$(ruby -r rbconfig -e 'print Config::CONFIG["sitelibdir"]') + local ruby_version + if [[ -z "$1" ]]; then + ruby_version="ruby" + else + ruby_version=$1 + fi + sitelibdir=$(/usr/bin/${ruby_version} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]') export GEMSDIR=${sitelibdir/site_ruby/gems} - } gems_src_unpack() { @@ -47,16 +55,6 @@ } gems_src_install() { - gems_location - - if [[ -z "${MY_P}" ]]; then - [[ -z "${GEM_SRC}" ]] && GEM_SRC="${DISTDIR}/${P}" - spec_path="${D}/${GEMSDIR}/specifications/${P}.gemspec" - else - [[ -z "${GEM_SRC}" ]] && GEM_SRC="${DISTDIR}/${MY_P}" - spec_path="${D}/${GEMSDIR}/specifications/${MY_P}.gemspec" - fi - local myconf if use doc; then myconf="--rdoc --ri" @@ -64,16 +62,46 @@ myconf="--no-rdoc --no-ri" fi - dodir ${GEMSDIR} - gem install ${GEM_SRC} --version ${PV} ${myconf} \ - --local --install-dir "${D}/${GEMSDIR}" || die "gem install failed" - - if [[ -d "${D}/${GEMSDIR}/bin" ]] ; then - exeinto /usr/bin - for exe in ${D}/${GEMSDIR}/bin/* ; do - doexe ${exe} - done + # I'm not sure how many ebuilds have correctly set USE_RUBY - let's assume + # ruby18 if they haven't, since even pure Ruby gems that have been written + # against 1.8 can explode under 1.9. + if [[ -z "${USE_RUBY}" ]]; then + USE_RUBY="ruby18" + elif [[ "${USE_RUBY}" == "any" ]]; then + # Get the installed versions. + USE_RUBY=`ls /usr/bin/ruby* | grep -E 'ruby1(8|9)' | sed -e 's@/usr/bin/@@g'` fi + + local num_ruby_slots=$(echo "${USE_RUBY}" | wc -w) + + for ruby_version in ${USE_RUBY} ; do + einfo "Installing for ${ruby_version}..." + gems_location ${ruby_version} + dodir ${GEMSDIR} + + if [[ -z "${MY_P}" ]]; then + [[ -z "${GEM_SRC}" ]] && GEM_SRC="${DISTDIR}/${P}" + spec_path="${D}/${GEMSDIR}/specifications/${P}.gemspec" + else + [[ -z "${GEM_SRC}" ]] && GEM_SRC="${DISTDIR}/${MY_P}" + spec_path="${D}/${GEMSDIR}/specifications/${MY_P}.gemspec" + fi + + /usr/bin/${ruby_version} /usr/bin/gem install ${GEM_SRC} --version ${PV} ${myconf} \ + --local --install-dir "${D}/${GEMSDIR}" || die "gem install failed" + + if [[ -d "${D}/${GEMSDIR}/bin" ]] ; then + exeinto /usr/bin + for exe in ${D}/${GEMSDIR}/bin/* ; do + if [ "$num_ruby_slots" -ge 2 ] ; then + # Ensures that the exe file gets run using the currently + # selected version of ruby. + sed -i -e 's@^#!/usr/bin/ruby.*$@#!/usr/bin/ruby@' "${exe}" + fi + doexe ${exe} + done + fi + done } EXPORT_FUNCTIONS src_unpack src_compile src_install