]> git.donarmstrong.com Git - cran2deb.git/blobdiff - pkg/trunk/cran2deb
cran2deb: name the tarball according to pkg$srcname not pkg$name
[cran2deb.git] / pkg / trunk / cran2deb
index 0fd1d09fa848f80bd86b5ba35ef503f1ff3cd082..7f9e14a6e8bf5189364a9662f65eb19cd564a348 100755 (executable)
@@ -112,19 +112,39 @@ prepare.pkg <- function(dir, pkgname,repo='cran',repoURL='http://cran.uk.r-proje
     pkg$repo = repo
     pkg$repoURL = repoURL
     pkg$version = pkg$description[1,'Version']
+    # TODO: re-pack into a Debian-named archive with a Debian-named directory.
     return(pkg)
 }
 
-debian_ok_licenses=c('GPL','LGPL','AGPL','Artistic','Unlimited')
-# these are commonly found 'in the wild'. the R packages should be fixed...
-debian_wild_licenses=c('gpl version 2 or newer'
-                      ,'gpl version 2 or later'
-                      ,'gnu gpl'
-                      ,'gpl v2'
-                      ,'gpl (version 2 or later)'
-                      ,'gpl version 2'
-                      ,'gpl 2 or later'
-                      ,'gpl2')
+debian_ok_licenses=c('GPL','LGPL','AGPL','ARTISTIC','UNLIMITED','BSD')
+
+is_acceptable_license <- function(license) {
+    # compress spaces into a single space
+    license = gsub('[[:space:]]+',' ',license)
+    # make all characters upper case
+    license = toupper(license)
+    # don't care about versions of licenses
+    license = chomp(sub('\\([<=>!]+[[:space:]]*[0-9.]+\\)',''
+                    ,sub('-[0-9.]+','',license)))
+    if (license %in% debian_ok_licenses) {
+        return(T)
+    }
+    # remove all punctuation
+    license = gsub('[[:punct:]]+','',license)
+    # remove everything that looks like a version specification
+    license = gsub('(VERSION|V)? *[0-9.]+ *(OR *(LATER|NEWER))?',''
+                   ,license)
+    # remove any extra space
+    license = chomp(gsub('[[:space:]]+',' ',license))
+    if (license %in% debian_ok_licenses) {
+        message(paste('W: Accepted wild license as',license,'. FIX THE PACKAGE!'))
+        return(T)
+    }
+    # TODO: put debian_ok_licenses in DB
+    # TODO: file {LICENSE,LICENCE} (+ maybe COPYING?)
+    message(paste('E: Wild license',license,'did not match'))
+    return(F)
+}
 
 chomp <- function(x) {
     return(sub('^[[:space:]]+','',sub('[[:space:]]+$','',x)))
@@ -137,73 +157,68 @@ host.arch <- function() {
 prepare.new.debian <- function(pkg) {
     maintainer = 'cran2deb buildbot <cran2deb@example.org>'
 
+    # generate Debian version and name
+    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 = paste('r',tolower(pkg$repo),pkg$srcname,sep='-')
+
+    # rename package into something Debian-friendly
     if (!length(grep('\\.tar\\.gz',pkg$archive))) {
         stop('archive is not tarball')
     }
     debarchive= paste(dirname(pkg$archive),'/'
-                             ,pkg$name,'_'
+                             ,pkg$srcname,'_'
                              ,pkg$version,'.orig.tar.gz'
                              ,sep='')
     file.rename(pkg$archive, debarchive)
     pkg$archive = debarchive
-    # not sure can rename directory from R(!)
-    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$debname = paste('r',tolower(pkg$repo),tolower(pkg$name),sep='-')
-    pkg$srcname = tolower(pkg$name)
+
+    # make the debian/ directory
     debdir <- paste(pkg$path,'debian',sep='/')
     debfile <- function(x) { paste(debdir,x,sep='/') }
     unlink(debdir,recursive=T)
     dir.create(debdir)
 
-    # 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'))
-    cat(paste('#!/usr/bin/make -f'
-             ,'include /usr/share/R/debian/r-cran.mk'
-             ,'',sep='\n')
-       ,file=debfile('rules'))
-    Sys.chmod(debfile('rules'),'0700')
-
-    # if License: is missing, we must stop!
+    # check the license
     if (!('License' %in% names(pkg$description[1,]))) {
         stop('package has no License: field in description!')
     }
     accept=NULL
     for (license in strsplit(chomp(pkg$description[1,'License'])
                             ,'[[:space:]]*\\|[[:space:]]*')[[1]]) {
-
-        # don't care about versions of licenses
-        license0 = chomp(sub('\\([<=>!]+[[:space:]]*[0-9.]+\\)',''
-                        ,sub('-[0-9.]+','',license)))
-        if (license0 %in% debian_ok_licenses) {
+        if (is_acceptable_license(license)) {
             accept=license
             break
         }
-        license0 = sub('\\.$','',tolower(license0))
-        if (license0 %in% debian_wild_licenses) {
-            message('Accepted wild license. FIX THE PACKAGE!')
-            accept=license
-            break
-        }
-        # TODO: put debian_ok_licenses in DB
-        # TODO: file {LICENSE,LICENCE} (+ maybe COPYING?)
     }
     if (is.null(accept)) {
         stop(paste('No acceptable license:',pkg$description[1,'License']))
     } else {
-        message(paste('Auto-accepted license',accept))
+        message(paste('N: Auto-accepted license',accept))
     }
     if (accept == 'Unlimited') {
         # definition of Unlimited from ``Writing R extensions''
         accept=paste('Unlimited (no restrictions on distribution or'
                     ,'use other than those imposed by relevant laws)')
     }
+
+    # 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'))
+    cat(paste('#!/usr/bin/make -f'
+             ,'include /usr/share/R/debian/r-cran.mk'
+             ,'',sep='\n')
+       ,file=debfile('rules'))
+    Sys.chmod(debfile('rules'),'0700')
+
+    # generate copyright file; we trust DESCRIPTION
     writeLines(strwrap(
         paste('This Debian package of the GNU R package',pkg$name
              ,'was generated automatically using cran2deb by'
@@ -233,8 +248,9 @@ prepare.new.debian <- function(pkg) {
                    ,pkg$debname
                    ,'DESCRIPTION'
                    ,sep='/')
-             ,sep='\n'), width=72), con=debfile('copyright'))
+             ,sep='\n'), width=72), con=debfile('copyright.in'))
 
+    # see if this is an architecture-dependent package.
     # heuristic: if /src/ exists in pkg$path, then this is an
     #            architecture-dependent package.
     # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
@@ -246,6 +262,8 @@ prepare.new.debian <- function(pkg) {
     if (pkg$archdep) {
         pkg$arch <- host.arch()
     }
+
+    # construct control file
     shlibdep = ''
     if (pkg$archdep) {
         shlibdep = '${shlibs:Depends}'
@@ -277,24 +295,32 @@ prepare.new.debian <- function(pkg) {
                                     ,pkg$description[1,'Description']
                                     ,sep='')
     # Debian policy says 72 char width; indent minimally
-    write.dcf(control,file=debfile('control'),indent=1,width=72)
+    write.dcf(control,file=debfile('control.in'),indent=1,width=72)
     # TODO: debian/watch
 
+    # convert text to utf8 (who knows what the original character set is --
+    # let's hope iconv DTRT).
+    for (file in c('control','changelog','copyright')) {
+        system(paste('iconv -o ',shQuote(debfile(file))
+                    ,' -t utf8 '
+                    ,shQuote(debfile(paste(file,'in',sep='.')))))
+    }
     return(pkg)
 }
 
 build.debian <- function(pkg) {
     wd <- getwd()
     setwd(pkg$path)
-    message(paste('building Debian package'
+    message(paste('N: building Debian package'
                  ,pkg$debname
                  ,paste('(',pkg$debversion,')',sep='')
                  ,'...'))
     if (use_pbuilder) {
         # resulting files are in
-        # /var/cache/pbuilder/
+        # /var/cache/pbuilder/result/
         ret = system('pdebuild')
     } else {
+        # results not kept
         ret = system('debuild -us -uc -b')
     }
     setwd(wd)