commit:     4ec6a5d7055d7197a3eb9f8b9ab95a0c9a9e1b83
Author:     Alessandro Barbieri <lssndrbarbieri <AT> gmail <DOT> com>
AuthorDate: Fri Apr 15 17:46:55 2022 +0000
Commit:     Alessandro Barbieri <lssndrbarbieri <AT> gmail <DOT> com>
CommitDate: Fri Apr 15 20:34:21 2022 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=4ec6a5d7

R-packages.eclass: add documentation comments

Signed-off-by: Alessandro Barbieri <lssndrbarbieri <AT> gmail.com>

 eclass/R-packages.eclass | 120 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 97 insertions(+), 23 deletions(-)

diff --git a/eclass/R-packages.eclass b/eclass/R-packages.eclass
index 6cbf9d7d3..51765af2b 100644
--- a/eclass/R-packages.eclass
+++ b/eclass/R-packages.eclass
@@ -1,9 +1,25 @@
-# Copyright 1999-2021 Gentoo Authors
+# Copyright 1999-2022 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+# @ECLASS: R-packages.eclass
+# @AUTHOR:
+# AndrĂ© Erdmann <[email protected]>
+# Denis Dupeyron <[email protected]>
+# Benda Xu <[email protected]>
+# Alessandro Barbieri <[email protected]>
+# @BLURB: eclass to build R packages
+# @MAINTAINER:
+# Alessandro Barbieri <[email protected]>
+# @SUPPORTED_EAPIS: 7
+
 inherit eutils optfeature toolchain-funcs
 
-EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install pkg_postinst
+case ${EAPI} in
+       7) ;;
+       *) die "${ECLASS}: EAPI ${EAPI} unsupported."
+esac
+
+EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install 
pkg_postinst
 
 SRC_URI="mirror://cran/src/contrib/${PN}_${PV}.tar.gz"
 HOMEPAGE="https://cran.r-project.org/package=${PN}";
@@ -12,14 +28,24 @@ SLOT="0"
 
 DEPEND="dev-lang/R"
 RDEPEND="${DEPEND}"
+BDEPEND="sys-apps/pkgcore"
 
-dodocrm() {
+# @FUNCTION: _movelink
+# @INTERNAL
+# @USAGE: [<source> <dest>]
+# @DESCRIPTION:
+# <dest> will contain symlinks to everything in <source>
+_movelink() {
        if [ -e "${1}" ]; then
-               dodoc -r "${1}"
-               rm -rf "${1}" || die
+               local rp1="$(realpath ${1})" || die
+               mv "${rp1}" "${2}" || die
+               cp -rsf "${2}" "${rp1}" || die
        fi
 }
 
+# @FUNCTION: R-packages_src_unpack
+# @DESCRIPTION:
+# function to unpack R packages into the right folder
 R-packages_src_unpack() {
        unpack ${A}
        if [[ -d "${PN//_/.}" ]] && [[ ! -d "${P}" ]]; then
@@ -27,43 +53,91 @@ R-packages_src_unpack() {
        fi
 }
 
+# @FUNCTION: R-packages_src_prepare
+# @DESCRIPTION:
+# function to remove unwanted files from the sources
 R-packages_src_prepare() {
        rm -f LICENSE || die
        default
 }
 
+# @FUNCTION: R-packages_src_configure
+# @DESCRIPTION:
+# dummy function to disable configure
+R-packages_src_configure() { :; }
+
+# @FUNCTION: R-packages_src_compile
+# @DESCRIPTION:
+# function that will pass some environment variables to R and then 
build/install the package
 R-packages_src_compile() {
-       MAKEFLAGS="AR=$(tc-getAR) CFLAGS=${CFLAGS// /\\ } CXXFLAGS=${CXXFLAGS// 
/\\ } FFLAGS=${FFLAGS// /\\ } FCFLAGS=${FCFLAGS// /\\ } LDFLAGS=${LDFLAGS// /\\ 
}" R CMD INSTALL . -l "${WORKDIR}" "--byte-compile" || die
+       MAKEFLAGS=" \
+               ${MAKEFLAGS// /\\ } \
+               AR=$(tc-getAR) \
+               CC=$(tc-getCC) \
+               CPP=$(tc-getCPP) \
+               CXX=$(tc-getCXX) \
+               FC=$(tc-getFC) \
+               LD=$(tc-getLD) \
+               NM=$(tc-getNM) \
+               RANLIB=$(tc-getRANLIB) \
+               CFLAGS=${CFLAGS// /\\ } \
+               CPPFLAGS=${CPPFLAGS// /\\ } \
+               CXXFLAGS=${CXXFLAGS// /\\ } \
+               FFLAGS=${FFLAGS// /\\ } \
+               FCFLAGS=${FCFLAGS// /\\ } \
+               LDFLAGS=${LDFLAGS// /\\ } \
+               MAKEOPTS=${MAKEOPTS// /\\ } \
+       " \
+       R CMD INSTALL . -l "${WORKDIR}" "--byte-compile" || die
 }
 
+
+# @FUNCTION: R-packages_src_install
+# @DESCRIPTION:
+# function to move the files in the right folders
+# documentation and examples to docsdir, symlinked back to R site-library (to 
allow access from within R)
+# everything else to R site-library
 R-packages_src_install() {
-       cd "${WORKDIR}/${PN//_/.}" || die
+       pushd "${WORKDIR}/${PN//_/.}" || die
 
-       dodocrm examples || die
-       #dodocrm DESCRIPTION || die #keep this
-       dodocrm NEWS.md || die
-       dodocrm README.md || die
-       dodocrm html || die
+       local DOCS_DIR="${ED}/usr/share/doc/${PF}"
 
+       mkdir -p "${DOCS_DIR}" || die
+
+       for i in NEWS.md README.md DESCRIPTION examples ; do
+               _movelink "${i}" "${DOCS_DIR}/${i}" || die
+       done
+
+       if [ -e html ]; then
+               _movelink html "${DOCS_DIR}/html" || die
+               docompress -x "${DOCS_DIR}/html"
+       fi
        if [ -e doc ]; then
-               if [ -e doc/html ]; then
-                       docinto "${DOCSDIR}/html"
-                       dodoc -r doc/*.html
-                       rm -r doc/*.html || die
-                       docompress -x "${DOCSDIR}/html"
-               fi
-
-               docinto "${DOCSDIR}"
-               dodoc -r doc/.
-               rm -r doc || die
+               pushd doc || die
+               for i in * ; do
+                       _movelink "${i}" "${DOCS_DIR}/${i}" || die
+               done
+               popd || die
+       fi
+       if [ -e doc/html ]; then
+               docompress -x "${DOCS_DIR}/html"
        fi
+       docompress -x "${DOCS_DIR}"
 
        insinto "/usr/$(get_libdir)/R/site-library"
        doins -r "${WORKDIR}/${PN//_/.}"
 }
 
+# @FUNCTION: R-packages_pkg_postinst
+# @DESCRIPTION:
+# function that will prompt to install the suggested packages if they exist
 R-packages_pkg_postinst() {
        if [ -v SUGGESTED_PACKAGES ]; then
-               optfeature "having the upstream suggested packages" 
"${SUGGESTED_PACKAGES}"
+               for p in ${SUGGESTED_PACKAGES} ; do
+                       pexist=$(pquery -n1 "${p}" 2>/dev/null) || die
+                       if [ -n "${pexist}" ]; then
+                               optfeature "having the upstream suggested 
package" "${p}"
+                       fi
+               done
        fi
 }

Reply via email to