]> git.donarmstrong.com Git - cran2deb.git/blobdiff - trunk/R/debcontrol.R
Improving the mapping/handling of sysreqs.
[cran2deb.git] / trunk / R / debcontrol.R
index f9aeecd4c9ac791b60d9164f59fcb724c09ee30c..e8f8d325992c8a2bc83a3a3603002835047ed4db 100644 (file)
@@ -1,4 +1,4 @@
-get_dependencies <- function(pkg,extra_deps) {
+get_dependencies <- function(pkg,extra_deps,verbose=TRUE) {
     # determine dependencies
     dependencies <- r_dependencies_of(description=pkg$description)
     depends <- list()
@@ -16,9 +16,14 @@ get_dependencies <- function(pkg,extra_deps) {
     depends$build = c(extra_deps$deb,depends$build)
     # add the system requirements
     if ('SystemRequirements' %in% colnames(pkg$description)) {
-        sysreq <- sysreqs_as_debian(pkg$description[1,'SystemRequirements'])
-        depends$bin = c(sysreq$bin,depends$bin)
-        depends$build = c(sysreq$build,depends$build)
+        sysreq <- sysreqs_as_debian(pkg$description[1,'SystemRequirements'],verbose=verbose)
+       if (!is.null(sysreq) && is.list(sysreq)) {
+            depends$bin = c(sysreq$bin,depends$bin)
+            depends$build = c(sysreq$build,depends$build)
+        } else {
+           if (verbose) {cat("sysreq:"); print(sysreq)}
+            fail('Cannot interpret system dependency, fix package.\n')
+        }
     }
 
     forced <- forced_deps_as_debian(pkg$name)
@@ -60,14 +65,18 @@ get_dependencies <- function(pkg,extra_deps) {
     return(depends)
 }
 
-sysreqs_as_debian <- function(sysreq_text) {
+sysreqs_as_debian <- function(sysreq_text,verbose=FALSE) {
     # form of this field is unspecified (ugh) but most people seem to stick
     # with this
     aliases <- c()
+    # drop notes
+    sysreq_text = gsub('[Nn][Oo][Tt][Ee]:\\s.*','',sysreq_text)
+    # conversion from and to commata and lower case
     sysreq_text <- gsub('[[:space:]]and[[:space:]]',' , ',tolower(sysreq_text))
     for (sysreq in strsplit(sysreq_text,'[[:space:]]*,[[:space:]]*')[[1]]) {
+       if (verbose) cat("sysreq to investigate: '",sysreq,"'.\n",sep="")
         startreq = sysreq
-        # constant case
+        # constant case (redundant)
         sysreq = tolower(sysreq)
         # drop version information/comments for now
         sysreq = gsub('[[][^])]*[]]','',sysreq)
@@ -78,8 +87,10 @@ sysreqs_as_debian <- function(sysreq_text) {
         sysreq = gsub('[<>=]*[[:space:]]*[[:digit:]]+[[:digit:].+:~-]*','',sysreq)
         # byebye URLs
         sysreq = gsub('(ht|f)tps?://[[:alnum:]!?*"\'(),%$_@.&+/=-]*','',sysreq)
-        # squish out space
+        # squish out space -- this does not work for me (did not want to touch, though), Steffen
         sysreq = chomp(gsub('[[:space:]]+',' ',sysreq))
+        # no final dot and neither final blanks
+        sysreq = gsub('\\.?\\s*$','',sysreq)
         if (nchar(sysreq) == 0) {
             notice('part of the SystemRequirement became nothing')
             next
@@ -90,7 +101,7 @@ sysreqs_as_debian <- function(sysreq_text) {
             error('original SystemRequirement:',startreq)
             fail('unmet system requirement')
         }
-        notice('mapped SystemRequirement',startreq,'onto',alias,'via',sysreq)
+        notice(paste("mapped SystemRequirement '",startreq,"' onto '",alias,"' via '",sysreq,"'.",sep=""))
         aliases = c(aliases,alias)
     }
     return(map_aliases_to_debian(aliases))
@@ -115,43 +126,33 @@ map_aliases_to_debian <- function(aliases) {
 
 generate_control <- function(pkg) {
     # construct control file
-    control = data.frame()
-    control[1,'Source'] = pkg$srcname
-    control[1,'Section'] = 'gnu-r'
-    control[1,'Priority'] = 'optional'
-    control[1,'Maintainer'] = maintainer
-    control[1,'Build-Depends'] = paste(pkg$depends$build,collapse=', ')
-    control[1,'Standards-Version'] = '3.8.3'
-
-    control[2,'Package'] = pkg$debname
-    control[2,'Architecture'] = 'all'
+
+    control <- data.frame()
+    control[1,'Source'] <- pkg$srcname
+    control[1,'Section'] <- 'gnu-r'
+    control[1,'Priority'] <- 'optional'
+    control[1,'Maintainer'] <- maintainer
+    control[1,'Build-Depends'] <- paste(pkg$depends$build, collapse=', ')
+    control[1,'Standards-Version'] <- '3.9.1'
+    if ('URL' %in% colnames(pkg$description)) {
+        control[1,'Homepage'] <- pkg$description[1,'URL']
+    }
+
+    control[2,'Package'] <- pkg$debname
+    control[2,'Architecture'] <- 'all'
     if (pkg$archdep) {
-        control[2,'Architecture'] = 'any'
+        control[2,'Architecture'] <- 'any'
     }
-    control[2,'Depends'] = paste(pkg$depends$bin,collapse=', ')
-
-#   # bundles provide virtual packages of their contents
-#   # unnecessary for now; cran2deb converts R bundles itself
-#    if (pkg$is_bundle) {
-#        control[2,'Provides'] = paste(
-#                    lapply(r_bundle_contains(pkg$name)
-#                          ,function(name) return(pkgname_as_debian(paste(name)
-#                                                                  ,repopref=pkg$repo)))
-#                          ,collapse=', ')
-#    }
+    control[2,'Depends'] <- paste(pkg$depends$bin,collapse=', ',sep='')
 
     # generate the description
-    descr = 'GNU R package "'
+    descr <- 'GNU R package "'
     if ('Title' %in% colnames(pkg$description)) {
-        descr = paste(descr,pkg$description[1,'Title'],sep='')
+        descr <- paste(descr,pkg$description[1,'Title'],sep='')
     } else {
-        descr = paste(descr,pkg$name,sep='')
-    }
-    if (pkg$is_bundle) {
-        long_descr <- pkg$description[1,'BundleDescription']
-    } else {
-        long_descr <- pkg$description[1,'Description']
+        descr <- paste(descr,pkg$name,sep='')
     }
+    long_descr <- pkg$description[1,'Description']
 
     if (length(long_descr) < 1 || long_descr == "") {
         # bypass lintian extended-description-is-empty for which we care not.
@@ -162,14 +163,17 @@ generate_control <- function(pkg) {
     # using \n\n.\n\n is not very nice, but is necessary to make sure
     # the longer description does not begin on the synopsis line --- R's
     # write.dcf does not appear to have a nicer way of doing this.
-    descr = paste(descr,'"\n\n', long_descr, sep='')
-    % add some extra nice info about the original R package
-    for (r_info in c('Author','Maintainer','URL')) {
+    descr <- paste(descr,'"\n\n', long_descr, sep='')
+    # add some extra nice info about the original R package
+    for (r_info in c('Author','Maintainer')) {
         if (r_info %in% colnames(pkg$description)) {
-            descr = paste(descr,'\n\n',r_info,': ',pkg$description[1,r_info],sep='')
+            descr <- paste(descr,'\n\n',r_info,': ',pkg$description[1,r_info],sep='')
         }
     }
-    control[2,'Description'] = descr
+    if (Encoding(descr) == "unknown")
+        Encoding(descr) <- "latin1"     # or should it be UTF-8
+
+    control[2,'Description'] <- descr
 
     # Debian policy says 72 char width; indent minimally
     write.dcf(control,file=pkg$debfile('control.in'),indent=1,width=72)