diff options
author | brook <brook@pkgsrc.org> | 2015-04-25 22:06:34 +0000 |
---|---|---|
committer | brook <brook@pkgsrc.org> | 2015-04-25 22:06:34 +0000 |
commit | f69b030007a30e1d8b7eef3ec436960ef53add24 (patch) | |
tree | eb554a11ba0d14f6a8937c64b015636f960df1a3 /pkgtools/R2pkg | |
parent | fa95285740734104f314727958f1942cde71e704 (diff) | |
download | pkgsrc-f69b030007a30e1d8b7eef3ec436960ef53add24.tar.gz |
Initial import of the R2pkg package:
The R2pkg program, which is modeled after url2pkg, creates a new
pkgsrc package for the corresponding R package. It is intended to
help pkgsrc developers create new R packages quickly and easily.
This package was discussed in a thread beginning with the following:
http://mail-index.netbsd.org/tech-pkg/2015/02/04/msg014227.html
Diffstat (limited to 'pkgtools/R2pkg')
-rw-r--r-- | pkgtools/R2pkg/DESCR | 3 | ||||
-rw-r--r-- | pkgtools/R2pkg/Makefile | 41 | ||||
-rw-r--r-- | pkgtools/R2pkg/PLIST | 3 | ||||
-rw-r--r-- | pkgtools/R2pkg/files/R2pkg.8 | 149 | ||||
-rwxr-xr-x | pkgtools/R2pkg/files/R2pkg.sh | 301 |
5 files changed, 497 insertions, 0 deletions
diff --git a/pkgtools/R2pkg/DESCR b/pkgtools/R2pkg/DESCR new file mode 100644 index 00000000000..c642fade6f1 --- /dev/null +++ b/pkgtools/R2pkg/DESCR @@ -0,0 +1,3 @@ +The R2pkg program, which is modeled after url2pkg, creates a new +pkgsrc package for the corresponding R package. It is intended to +help pkgsrc developers create new R packages quickly and easily. diff --git a/pkgtools/R2pkg/Makefile b/pkgtools/R2pkg/Makefile new file mode 100644 index 00000000000..b4f9deeb2be --- /dev/null +++ b/pkgtools/R2pkg/Makefile @@ -0,0 +1,41 @@ +# $NetBSD: Makefile,v 1.1 2015/04/25 22:06:34 brook Exp $ +# + +VERS= 0.2 +PKGNAME= R2pkg-${VERS} +CATEGORIES= pkgtools + +MAINTAINER= brook@NetBSD.org +HOMEPAGE= # none +COMMENT= Tool to automate initial steps in building an R package +LICENSE= modified-bsd + +WRKSRC= ${WRKDIR} +NO_BUILD= yes +USE_LANGUAGES= # none +AUTO_MKDIRS= yes + +SUBST_CLASSES+= version +SUBST_STAGE.version= pre-configure +SUBST_MESSAGE.version= Substituting version in R2pkg.sh. +SUBST_FILES.version= R2pkg.sh +SUBST_VARS.version= VERS + +SUBST_CLASSES+= tools +SUBST_STAGE.tools= pre-configure +SUBST_MESSAGE.tools= Substituting tool locations. +SUBST_FILES.tools= R2pkg.sh +SUBST_VARS.tools= MAKE + +INSTALLATION_DIRS+= sbin ${PKGMANDIR}/man8 + +do-extract: + ${CP} ${FILESDIR}/R2pkg.sh ${WRKSRC} + ${CP} ${FILESDIR}/R2pkg.8 ${WRKSRC} + +do-install: + ${INSTALL_SCRIPT} ${WRKSRC}/R2pkg.sh ${DESTDIR}${PREFIX}/sbin/R2pkg + ${INSTALL_MAN} ${WRKSRC}/R2pkg.8 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/R2pkg.8 + +.include "../../math/R/buildlink3.mk" +.include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/R2pkg/PLIST b/pkgtools/R2pkg/PLIST new file mode 100644 index 00000000000..eb6ed17ee3b --- /dev/null +++ b/pkgtools/R2pkg/PLIST @@ -0,0 +1,3 @@ +@comment $NetBSD: PLIST,v 1.1 2015/04/25 22:06:34 brook Exp $ +man/man8/R2pkg.8 +sbin/R2pkg diff --git a/pkgtools/R2pkg/files/R2pkg.8 b/pkgtools/R2pkg/files/R2pkg.8 new file mode 100644 index 00000000000..10e84b16ba8 --- /dev/null +++ b/pkgtools/R2pkg/files/R2pkg.8 @@ -0,0 +1,149 @@ +.\" $NetBSD: R2pkg.8,v 1.1 2015/04/25 22:06:34 brook Exp $ +.\" +.\" Copyright (c) 2014,2015 +.\" Brook Milligan. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the author nor the names of any contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" +.Dd April 25, 2015 +.Dt R2pkg 8 +.Os +.Sh NAME +.Nm R2pkg +.Nd create a pkgsrc package for an R package +.Sh SYNOPSIS +.Nm +.Op Fl DVehqv +.Op Fl E Ar editor +.Op Ar package +.Sh DESCRIPTION +.Nm +takes the name of an R +.Ar package +that should be turned into a +.Xr pkgsrc 7 +package in the current directory. The generated package includes a +.Pa Makefile +and a mostly complete set of files to get the package going. However, the files should be reviewed and perhaps adjusted manually after +.Nm +has finished its job. To help with this, the original versions of files created by +.Nm +are preserved for reference. +.Pp +.Nm +is intended to help the process of creating a package but is not +intended to fly on autopilot. +.Pp +The +.Pa Makefile +contains all of the variables required for an R package, with information being taken from the package's +.Pa DESCRIPTION +file on CRAN, which is automatically fetched by +.Nm . +Likewise, the +.Pa DESCR +file is populated with information from the same file. After +.Pa Makefile +and +.Pa DESCR +are completed, +.Nm +fetches the package and computes its checksum via the +.Ic makesum +target. Then the package is extracted via the +.Ic extract +target. +.Pp +If the user does not supply the +.Ar package +on the command line, then +.Nm +will prompt for it. +.Pp +The following options are available: +.Bl -tag -width indent +.It Fl D +Write the package's description into +.Pa DESCRIPTION . +This may be useful for verifying the information obtained from CRAN. However, this file must be removed as it is not part of a +.Xr pkgsrc 7 +package. +.It Fl E Ar editor +Use +.Ar editor +instead of the user's default editor. +.It Fl V +Print the version. +.It Fl e +Do not edit Makefile and DESCR. +.It Fl h +Produce a short help message. +.It Fl q +Do not produce status messages along the way. +.It Fl v +Generate verbose output. This may be repeated to increase the verbosity. +.El +.Sh ENVIRONMENT +The following environment variables affect the execution of +.Nm : +.Bl -tag -width BLOCKSIZE +.It Ev PKGEDITOR, EDITOR +Editor used for editing +.Pa Makefile +and +.Pa DESCR . +.It Ev CRAN_URL +The URL to the CRAN mirror for downloading the package's DESCRIPTION +file. By default, +.Pa ftp://cran.r-project.org . +.El +.Sh EXAMPLES +Use the following commands to create a +.Xr pkgsrc 7 +package for the R package +.Ar foo : +.Dl cd pkgsrc/math +.Dl mkdir R-foo +.Dl cd R-foo +.Dl R2pkg foo +Remember to test the resulting package and remove any extra files created by +.Nm . +.Sh BUGS +.Nm +does not create a finished package; instead, it facilitates the task. +However, the resulting files must be reviewed and possibly edited by +hand. Although dependencies are included in the generated +.Pa Makefile , +they are only comments; no attempt is made to find corresponding +packages within +.Xr pkgsrc 7 . +As a consequence, the category of dependencies is also not determined. +.Sh SEE ALSO +.Xr pkgsrc 7 +.Sh AUTHORS +.Nm +was written by +.An Brook Milligan Aq Mt brook@NetBSD.org . diff --git a/pkgtools/R2pkg/files/R2pkg.sh b/pkgtools/R2pkg/files/R2pkg.sh new file mode 100755 index 00000000000..67e82965cd3 --- /dev/null +++ b/pkgtools/R2pkg/files/R2pkg.sh @@ -0,0 +1,301 @@ +#!/bin/sh +# R2pkg +# +# Copyright (c) 2014,2015 +# Brook Milligan. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the author nor the names of any contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# Create an R package in the current directory +# +NAME="R2pkg" +VERS="@VERS@" + +USAGE="${NAME} [-DVehqv] [-E editor] [package] -- create an R package for pkgsrc" + +: ${CRAN_URL:=ftp://cran.r-project.org} +: ${PKGEDITOR:=${EDITOR:=vi}} + +# Substituted by pkgsrc at pre-configure time. +MAKE=@MAKE@ +ECHO=echo +EDIT=1 +QUIET=0 +VERBOSE=0 + +while getopts DE:Vehqv f +do + case $f in + D) DESCRIPTION=yes;; + E) PKGEDITOR=${OPTARG};; + V) echo "${NAME} v${VERS}"; exit 0;; + e) EDIT=0;; + h) echo ${USAGE}; exit 0;; + q) ECHO=":"; QUIET=1;; + v) VERBOSE=$((${VERBOSE}+1));; + \?) echo ${USAGE}; exit 1;; + esac +done +shift `expr ${OPTIND} - 1` + +if [ ${#} -eq 0 ]; then + read -p "package: " RPKG TAIL + if [ "X${TAIL}" != "X" ]; then + echo "Error: multiple package names given." + echo ${USAGE} + exit 1 + fi +elif [ ${#} -eq 1 ]; then + RPKG=${1} +else + echo ${USAGE} + exit 1 +fi + +if [ ${VERBOSE} -eq 0 ]; then + STDOUT=">/dev/null 2>&1" + STDOUT2=">/dev/null 2>&1" +elif [ ${VERBOSE} -eq 1 ]; then + STDOUT="" + STDOUT2=">/dev/null 2>&1" +else + STDOUT="" + STDOUT2="" +fi + +CRAN_PACKAGES=pub/R/web/packages +RPKG_DESCRIPTION_URL=${CRAN_URL}/${CRAN_PACKAGES}/${RPKG}/DESCRIPTION + +check_for_R () +{ + R_CMD="R --no-save ${STDOUT2}" + echo "q()" | eval ${R_CMD} + if [ ${?} -ne 0 ]; then + echo "ERROR: math/R package is not installed." + exit 1 + fi +} + +preserve_original_files () +{ + [ -f DESCR ] && mv DESCR DESCR.orig + [ -f Makefile ] && mv Makefile Makefile.orig + [ -f distinfo ] && mv distinfo distinfo.orig +} + +make_package () +{ + R_CMD="R --no-save ${STDOUT2}" + [ "X${DESCRIPTION}" != "X" ] && DESCRIPTION_CMD="copy.description(connection)" + cat << EOF | eval ${R_CMD} +one.line <- function(s) gsub(' *\n *',' ',s) +pkg.vers <- function(s) gsub('_','.',s) +field <- function(key,value) paste(key,'=\t',value,sep='') + +licenses <- list() +licenses[['ACM']] <- 'acm-license' +licenses[['APACHE']] <- 'apache-2.0' +licenses[['ARTISTIC']] <- 'artistic-2.0' +licenses[['BSD-2']] <- '2-clause-bsd' +licenses[['GPL-2']] <- 'gnu-gpl-v2' +licenses[['GPL-3']] <- 'gnu-gpl-v3' +licenses[['GPL (>= 2)']] <- 'gnu-gpl-v2' +licenses[['GPL-2 | GPL-3']] <- 'gnu-gpl-v2 OR gnu-gpl-v3' +licenses[['LGPL-2']] <- 'gnu-lgpl-v2' +licenses[['LGPL-2.1']] <- 'gnu-lgpl-v2.1' +licenses[['LGPL (>= 2)']] <- 'gnu-lgpl-v2' +licenses[['LUCENT']] <- 'lucent' +licenses[['MIT']] <- 'mit' +licenses[['POSTGRESQL']] <- 'postgresql-license' + +paste2 <- function(s1,s2) +{ + if (is.na(s1) && is.na(s2)) return ('') + if (is.na(s1) && !is.na(s2)) return (s2) + if (!is.na(s1) && is.na(s2)) return (s1) + if (!is.na(s1) && !is.na(s2)) return (paste(s1,s2)) +} + +todo.license <- function(s) +{ + if (is.null(licenses[[s]])) + todo <- '# TODO: LICENSE' + else + todo <- 'LICENSE' + todo +} + +pkgsrc.license <- function(s) +{ + license <- licenses[[s]] + if (is.null(license)) + license <- s + license +} + +package <- function(s) field('R_PKGNAME',one.line(s)) +version <- function(s) field('R_PKGVER',one.line(s)) +comment <- function(s) field('COMMENT',one.line(s)) +license <- function(s) field(todo.license(s),pkgsrc.license(s)) + +categories <- function() paste('CATEGORIES=',paste(basename(dirname(getwd())),'R'),sep=' ') +description <- function(s) strwrap(s,width=71) + +depends <- function(s1,s2) +{ + s <- paste2(s1,s2) + imports <- na.omit(strsplit(one.line(s),', *')[[1]]) + DEPENDS <- '' + if (length(imports) > 0) + { + for (i in 1:length(imports)) + { + dependency <- strsplit(imports[i],' *\\\\( *')[[1]] + depends <- dependency[1] + depends.vers <- ifelse(length(dependency) == 2, dependency[2], '>=???') + depends.vers <- gsub(' ','',depends.vers) + depends.vers <- pkg.vers(gsub('\\\\)','',depends.vers)) + depends.line <- paste('# DEPENDS+=\tR-',depends,depends.vers,':../../CATEGORY/R-',depends,sep='') + DEPENDS <- paste(DEPENDS,depends.line,sep='\n') + } + DEPENDS <- paste(DEPENDS,'',sep='\n') + } + DEPENDS +} + +copy.description <- function(connection) +{ + description <- readLines(connection) + writeLines(description,con='DESCRIPTION') +} + +connection <- url('${RPKG_DESCRIPTION_URL}') +${DESCRIPTION_CMD} +metadata <- read.dcf(connection, fields=c('Package','Version','Title','Description','License','Imports','Depends')) + +CVS <- '# \$NetBSD\$' +CATEGORIES <- categories() +MASTER.SITES <- 'MASTER_SITES= \${MASTER_SITE_R_CRAN:=contrib/}' +MAINTAINER <- 'MAINTAINER= pkgsrc-users@NetBSD.org' +HOMEPAGE <- 'HOMEPAGE= \${R_HOMEPAGE_BASE}/${RPKG}/' +COMMENT <- comment(metadata[3]) +LICENSE <- license(metadata[5]) +R_PKGNAME <- package(metadata[1]) +R_PKGVER <- version(metadata[2]) +DEPENDS <- depends(metadata[6],metadata[7]) +INCLUDE.R <- '.include "../../math/R/Makefile.extension"' +INCLUDE.PKG <- '.include "../../mk/bsd.pkg.mk"' + +DESCR <- description(metadata[4]) + +Makefile <- paste(CVS, + '', + CATEGORIES, + MASTER.SITES, + '', + MAINTAINER, + HOMEPAGE, + COMMENT, + LICENSE, + '', + R_PKGNAME, + R_PKGVER, + DEPENDS, + INCLUDE.R, + INCLUDE.PKG, + sep='\n') + +write(Makefile,'Makefile') +write(DESCR,'DESCR') +EOF + if [ ${?} -ne 0 ]; then + echo "ERROR: parsing metadata failed." + exit 1 + fi +} + +edit_Makefile () +{ + [ ${EDIT} -eq 0 ] || ${PKGEDITOR} Makefile +} + +edit_DESCR () +{ + [ ${EDIT} -eq 0 ] || ${PKGEDITOR} DESCR +} + +create_distinfo () +{ + ${ECHO} "Fetching package ... " + MAKE_CMD="${MAKE} makesum ${STDOUT}" + eval ${MAKE_CMD} +} + +extract () +{ + ${ECHO} "Extracting package ... " + MAKE_CMD="${MAKE} extract ${STDOUT}" + eval ${MAKE_CMD} +} + +cleanup () +{ + if [ -f DESCR.orig ] && cmp -s DESCR.orig DESCR; then + mv DESCR.orig DESCR + fi + if [ -f Makefile.orig ] && cmp -s Makefile.orig Makefile; then + mv Makefile.orig Makefile + fi + if [ -f distinfo.orig ] && cmp -s distinfo.orig distinfo; then + mv distinfo.orig distinfo + fi +} + +messages () +{ + if [ ${QUIET} -eq 0 ]; then + cat << EOF +Please do not forget the following: +- check DESCR and edit as necessary. +- check Makefile: + o verify the COMMENT. + o verify the LICENSE. + o verify the DEPENDS, especially the categories. +EOF + [ "X${DESCRIPTION}" != "X" ] && echo "- remove DESCRIPTION." + fi +} + +${ECHO} "Creating R package: ${RPKG} ... " +check_for_R +preserve_original_files +make_package +edit_Makefile +edit_DESCR +create_distinfo +extract +cleanup +messages |