Files
guru/eclass/R-packages.eclass
Robert Greener 4d1f8fd683 eclass/R-packages: Add CRAN_SNAPSHOT_DATE and use MRAN.
The current SRC_URI searches all the CRAN mirrors for
/src/contrib/${PN}_${PV}.tar.gz. This is problematic. Once a package is updated
on CRAN, the package is removed from this path and moved to
/src/contrib/Archive/${PN}/${PN}_${PV}.tar.gz. The effect of this is
that once a package goes out-of-date on CRAN, the ebuild will no longer
build. This significantly increases the maintenance burden of dev-R/*
packages, as it requires that they be up-to-date at all times.

The proposal here, is to use the snapshots of CRAN provided by
Microsoft. This requires an additional variable set in the ebuilds, the
update date. This can just be set to the date that the ebuild is
updated. By setting this, out of date packages will continue to build.

Signed-off-by: Robert Greener <me@r0bert.dev>
2022-07-12 13:05:31 +01:00

162 lines
4.0 KiB
Bash

# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: R-packages.eclass
# @AUTHOR:
# André Erdmann <dywi@mailerd.de>
# Denis Dupeyron <calchan@gentoo.org>
# Benda Xu <heroxbd@gentoo.org>
# Alessandro Barbieri <lssndrbarbieri@gmail.com>
# @BLURB: eclass to build R packages
# @MAINTAINER:
# Alessandro Barbieri <lssndrbarbieri@gmail.com>
# @SUPPORTED_EAPIS: 7
inherit edo eutils optfeature toolchain-funcs
case ${EAPI} in
7) ;;
*) die "${ECLASS}: EAPI ${EAPI} unsupported."
esac
EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install pkg_postinst
CRAN_PV=${CRAN_PV:-$PV}
CRAN_PN=${CRAN_PN:-${PN//_/.}}
# Set CRAN_SNAPSHOT_DATE to the date the ebuild was updated in the ebuild
if [[ ${CRAN_SNAPSHOT_DATE} ]]; then
SRC_URI="https://cran.microsoft.com/snapshot/${CRAN_SNAPSHOT_DATE}"
else
SRC_URI="mirror://cran"
fi
SRC_URI+="/src/contrib/${CRAN_PN}_${CRAN_PV}.tar.gz"
HOMEPAGE="https://cran.r-project.org/package=${CRAN_PN}"
SLOT="0"
DEPEND="dev-lang/R"
RDEPEND="${DEPEND}"
BDEPEND="sys-apps/pkgcore"
# @FUNCTION: _movelink
# @INTERNAL
# @USAGE: [<source> <dest>]
# @DESCRIPTION:
# <dest> will contain symlinks to everything in <source>
_movelink() {
if [[ -e "${1}" ]]; then
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 "${CRAN_PN}" ]] && [[ ! -d "${P}" ]]; then
mv "${CRAN_PN}" "${P}" || die
fi
}
# @FUNCTION: R-packages_src_prepare
# @DESCRIPTION:
# function to remove unwanted files from the sources
R-packages_src_prepare() {
rm -f LICENSE || die
default
mkdir -p "${T}/R" || die
}
# @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=" \
${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// /\\ } \
" \
edo R CMD INSTALL . -d -l "${T}/R" "--byte-compile"
}
# @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() {
pushd "${T}/R/${CRAN_PN}" || die
local DOCS_DIR="/usr/share/doc/${PF}"
mkdir -p "${ED}/${DOCS_DIR}" || die
for i in NEWS.md README.md DESCRIPTION examples CITATION INDEX NEWS WORDLIST News.Rd ; do
_movelink "${i}" "${ED}${DOCS_DIR}/${i}" || die
docompress -x "${DOCS_DIR}/${i}"
done
if [[ -e html ]]; then
_movelink html "${ED}${DOCS_DIR}/html" || die
docompress -x "${DOCS_DIR}/html"
fi
if [[ -e doc ]]; then
pushd doc || die
for i in * ; do
_movelink "${i}" "${ED}${DOCS_DIR}/${i}" || die
docompress -x "${DOCS_DIR}/${i}"
done
popd || die
fi
if [[ -e doc/html ]]; then
docompress -x "${DOCS_DIR}/html"
fi
docompress -x "${DOCS_DIR}"
rm -rf tests test || die
insinto "/usr/$(get_libdir)/R/site-library"
doins -r "${T}/R/${CRAN_PN}"
}
# @FUNCTION: R-packages_pkg_postinst
# @DESCRIPTION:
# function that will prompt to install the suggested packages if they exist
R-packages_pkg_postinst() {
if [[ ${MERGE_TYPE} != binary ]]; then
if [[ -v SUGGESTED_PACKAGES ]]; then
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
fi
}