]> git.donarmstrong.com Git - cran2deb.git/commitdiff
cran2deb: refactor prepare.new.debian into smaller parts.
authorblundellc <blundellc@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Sat, 13 Sep 2008 13:14:57 +0000 (13:14 +0000)
committerblundellc <blundellc@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Sat, 13 Sep 2008 13:14:57 +0000 (13:14 +0000)
git-svn-id: svn://svn.r-forge.r-project.org/svnroot/cran2deb@34 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/trunk/cran2deb

index 956b726b176fb1108bdb9e08e5650f13f712d36c..257a335a672a096f4d29f5b10b1d33baa1b33e05 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env r
 
+maintainer <- 'cran2deb buildbot <cran2deb@example.org>'
 root <- '/home/cb/work/gsoc/cran2deb'
 pbuilder_results <- paste(root,'/var/results',sep='')
 pbuilder_config  <- paste(root,'/etc/pbuilderrc',sep='')
@@ -113,7 +114,7 @@ pkgname.as.debian <- function(name,repopref=NULL,version=NULL,binary=T) {
         # XXX: data.frame rownames are unique, so always override repopref for
         #      now.
         if (!(name %in% rownames(available))) {
-            bundle <- r.bundle.of(pkgname)
+            bundle <- r.bundle.of(name)
             if (is.na(bundle)) {
                 stop(paste('package',name,'is not available'))
             }
@@ -144,11 +145,9 @@ r.bundle.of <- function(pkgname) {
     # use the first bundle
     for (bundle in names(bundles)) {
         content <- strsplit(bundles[[bundle]],'[[:space:]]+')[[1]]
-        message(paste(pkgname,'in',paste(content,collapse=', ')))
         if (pkgname %in% content) {
             return(bundle)
         }
-        message('no')
     }
     return(NA)
 }
@@ -332,7 +331,6 @@ r.dependency.closure <- function(fringe) {
         if (!length(grep('^r-',src)) || length(grep('^r-base',src))) {
             next
         }
-        # TODO: cross-repo dependencies
         newdeps <- levels(r.dependencies.of(name=top)$name)
         closure=c(closure,top)
         fringe=c(fringe,newdeps)
@@ -341,55 +339,7 @@ r.dependency.closure <- function(fringe) {
     return(rev(unique(closure,fromLast=T)))
 }
 
-prepare.new.debian <- function(pkg) {
-    maintainer = 'cran2deb buildbot <cran2deb@example.org>'
-
-    # XXX: TODO: bundles do not work.
-    if ('Bundle' %in% names(pkg$description[1,])) {
-        stop('E: TODO: bundles')
-    }
-
-    # generate Debian version and name
-    pkg$repo = repourl.as.debian(pkg$repoURL)
-    pkg$debversion = version.new(pkg$version)
-    if (!length(grep('^[A-Za-z0-9][A-Za-z0-9+.-]+$',pkg$name))) {
-        stop(paste('Cannot convert package name into a Debian name',pkg$name))
-    }
-    pkg$srcname = tolower(pkg$name)
-    pkg$debname = pkgname.as.debian(pkg$name,repo=pkg$repo)
-
-    if (!length(grep('\\.tar\\.gz',pkg$archive))) {
-        stop('archive is not tarball')
-    }
-
-    # re-pack into a Debian-named archive with a Debian-named directory.
-    debpath = paste(dirname(pkg$archive),'/'
-                   ,pkg$srcname,'-'
-                   ,pkg$version
-                   ,sep='')
-    file.rename(pkg$path, debpath)
-    pkg$path = debpath
-    debarchive = paste(dirname(pkg$archive),'/'
-                              ,pkg$srcname,'_'
-                              ,pkg$version,'.orig.tar.gz'
-                              ,sep='')
-    wd <- getwd()
-    setwd(dirname(pkg$path))
-    # remove them pesky +x files
-    system(paste('find',shQuote(basename(pkg$path))
-                ,'-type f -exec chmod -x {} \\;'))
-    # tar it all back up
-    system(paste('tar -czf',shQuote(debarchive),shQuote(basename(pkg$path))))
-    setwd(wd)
-    file.remove(pkg$archive)
-    pkg$archive = debarchive
-
-    # make the debian/ directory
-    debdir <- paste(pkg$path,'debian',sep='/')
-    debfile <- function(x) { paste(debdir,x,sep='/') }
-    unlink(debdir,recursive=T)
-    dir.create(debdir)
-
+accept.license <- function(pkg) {
     # check the license
     if (!('License' %in% names(pkg$description[1,]))) {
         stop('package has no License: field in description!')
@@ -412,20 +362,28 @@ prepare.new.debian <- function(pkg) {
         accept=paste('Unlimited (no restrictions on distribution or'
                     ,'use other than those imposed by relevant laws)')
     }
+    return(accept)
+}
 
+generate.changelog <- function(pkg) {
     # construct a dummy changelog
     # TODO: ``Writing R extensions'' mentions that a package may also have
     # {NEWS,ChangeLog} files.
     cat(paste(paste(pkg$srcname,' (',pkg$debversion,') unstable; urgency=low',sep='')
              ,'' ,'  * Initial release.',''
              ,paste(' --',maintainer,'',format(Sys.time(),'%a, %d %b %Y %H:%M:%S %z'))
-             ,'',sep='\n'),file=debfile('changelog.in'))
+             ,'',sep='\n'),file=pkg$debfile('changelog.in'))
+}
+
+generate.rules <- function(pkg) {
     cat(paste('#!/usr/bin/make -f'
              ,'include /usr/share/R/debian/r-cran.mk'
              ,'',sep='\n')
-       ,file=debfile('rules'))
-    Sys.chmod(debfile('rules'),'0700')
+       ,file=pkg$debfile('rules'))
+    Sys.chmod(pkg$debfile('rules'),'0700')
+}
 
+generate.copyright <- function(pkg) {
     # generate copyright file; we trust DESCRIPTION
     writeLines(strwrap(
         paste('This Debian package of the GNU R package',pkg$name
@@ -456,8 +414,10 @@ prepare.new.debian <- function(pkg) {
                    ,pkg$debname
                    ,'DESCRIPTION'
                    ,sep='/')
-             ,sep='\n'), width=72), con=debfile('copyright.in'))
+             ,sep='\n'), width=72), con=pkg$debfile('copyright.in'))
+}
 
+generate.control <- function(pkg) {
     # see if this is an architecture-dependent package.
     # heuristic: if /src/ exists in pkg$path, then this is an
     #            architecture-dependent package.
@@ -536,6 +496,61 @@ prepare.new.debian <- function(pkg) {
     # Debian policy says 72 char width; indent minimally
     write.dcf(control,file=debfile('control.in'),indent=1,width=72)
     write.dcf(control,indent=1,width=72)
+}
+
+prepare.new.debian <- function(pkg) {
+    # XXX: TODO: bundles do not work.
+    if ('Bundle' %in% names(pkg$description[1,])) {
+        stop('E: TODO: bundles')
+    }
+
+    # generate Debian version and name
+    pkg$repo = repourl.as.debian(pkg$repoURL)
+    pkg$debversion = version.new(pkg$version)
+    if (!length(grep('^[A-Za-z0-9][A-Za-z0-9+.-]+$',pkg$name))) {
+        stop(paste('Cannot convert package name into a Debian name',pkg$name))
+    }
+    pkg$srcname = tolower(pkg$name)
+    pkg$debname = pkgname.as.debian(pkg$name,repo=pkg$repo)
+
+    if (!length(grep('\\.tar\\.gz',pkg$archive))) {
+        stop('archive is not tarball')
+    }
+
+    # re-pack into a Debian-named archive with a Debian-named directory.
+    debpath = paste(dirname(pkg$archive),'/'
+                   ,pkg$srcname,'-'
+                   ,pkg$version
+                   ,sep='')
+    file.rename(pkg$path, debpath)
+    pkg$path = debpath
+    debarchive = paste(dirname(pkg$archive),'/'
+                              ,pkg$srcname,'_'
+                              ,pkg$version,'.orig.tar.gz'
+                              ,sep='')
+    wd <- getwd()
+    setwd(dirname(pkg$path))
+    # remove them pesky +x files
+    system(paste('find',shQuote(basename(pkg$path))
+                ,'-type f -exec chmod -x {} \\;'))
+    # tar it all back up
+    system(paste('tar -czf',shQuote(debarchive),shQuote(basename(pkg$path))))
+    setwd(wd)
+    file.remove(pkg$archive)
+    pkg$archive = debarchive
+
+    # make the debian/ directory
+    debdir <- paste(pkg$path,'debian',sep='/')
+    pkg$debfile <- function(x) { paste(debdir,x,sep='/') }
+    unlink(debdir,recursive=T)
+    dir.create(debdir)
+
+    pkg$license <- accept.license(pkg)
+
+    generate.changelog(pkg)
+    generate.rules(pkg)
+    generate.copyright(pkg)
+    generate.control(pkg)
 
     # TODO: debian/watch from pkg$repoURL
 
@@ -570,7 +585,6 @@ changesfile <- function(srcname,version='*') {
                       ,host.arch(),'.changes',sep=''), sep=''))
 }
 
-# TEST: SRPM -> stashR -> digest -> filehash
 go <- function(name) {
     dir <- setup()
     pkg <- try((function() {