]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/R/debcontrol.R
76c7e5a2387bae0e3b9931c1e1d906a8bb5e10ec
[cran2deb.git] / trunk / R / debcontrol.R
1 get_dependencies <- function(pkg,extra_deps,verbose=TRUE) {
2     # determine dependencies
3     dependencies <- r_dependencies_of(description=pkg$description)
4     depends <- list()
5     # these are used for generating the Depends fields
6     as_deb <- function(r,build) {
7         return(pkgname_as_debian(paste(dependencies[r,]$name)
8                                 ,version=dependencies[r,]$version
9                                 ,repopref=pkg$repo
10                                 ,build=build))
11     }
12     depends$bin <- lapply(rownames(dependencies), as_deb, build=F)
13     depends$build <- lapply(rownames(dependencies), as_deb, build=T)
14     # add the command line dependencies
15     depends$bin = c(extra_deps$deb,depends$bin)
16     depends$build = c(extra_deps$deb,depends$build)
17     ## add R:Depends
18     depends$bin = c(depends$bin,'${R:Depends}');
19     # add the system requirements
20     if ('SystemRequirements' %in% colnames(pkg$description)) {
21         sysreq <- sysreqs_as_debian(pkg$description[1,'SystemRequirements'],verbose=verbose)
22         if (!is.null(sysreq) && is.list(sysreq)) {
23             depends$bin = c(sysreq$bin,depends$bin)
24             depends$build = c(sysreq$build,depends$build)
25         } else {
26             if (verbose) {cat("sysreq:"); print(sysreq)}
27             fail('Cannot interpret system dependency, fix package.\n')
28         }
29     }
30
31     forced <- forced_deps_as_debian(pkg$name)
32     if (length(forced)) {
33         notice('forced build dependencies:',paste(forced$build, collapse=', '))
34         notice('forced binary dependencies:',paste(forced$bin, collapse=', '))
35         depends$bin = c(forced$bin,depends$bin)
36         depends$build = c(forced$build,depends$build)
37     }
38
39     # make sure we depend upon R in some way...
40     if (!length(grep('^r-base',depends$build))) {
41         depends$build = c(depends$build,pkgname_as_debian('R',version='>= 2.7.0',build=T))
42         depends$bin   = c(depends$bin,  pkgname_as_debian('R',version='>= 2.7.0',build=F))
43     }
44     # also include stuff to allow tcltk to build (suggested by Dirk)
45     depends$build = c(depends$build,'xvfb','xauth','xfonts-base')
46
47     # make all bin dependencies build dependencies.
48     depends$build = c(depends$build, depends$bin)
49
50     # remove duplicates
51     depends <- lapply(depends,unique)
52
53     # append the Debian dependencies
54     depends$build=c(depends$build,'debhelper (>> 4.1.0)','cdbs')
55     if (file.exists(file.path(patch_dir, pkg$name))) {
56         depends$build <- c(depends$build,'dpatch')
57     }
58     if (pkg$archdep) {
59         depends$bin=c(depends$bin,'${shlibs:Depends}')
60     }
61
62     # the names of dependent source packages (to find the .changes file to
63     # upload via dput). these can be found recursively.
64     depends$r = r_dependency_closure(dependencies)
65     # append command line dependencies
66     depends$r = c(extra_deps$r, depends$r)
67     return(depends)
68 }
69
70 sysreqs_as_debian <- function(sysreq_text,verbose=FALSE) {
71     # form of this field is unspecified (ugh) but most people seem to stick
72     # with this
73     aliases <- c()
74     # drop notes
75     sysreq_text = gsub('[Nn][Oo][Tt][Ee]:\\s.*','',sysreq_text)
76     # conversion from and to commata and lower case
77     sysreq_text <- gsub('[[:space:]]and[[:space:]]',' , ',tolower(sysreq_text))
78     for (sysreq in strsplit(sysreq_text,'[[:space:]]*,[[:space:]]*')[[1]]) {
79         if (verbose) cat("sysreq to investigate: '",sysreq,"'.\n",sep="")
80         startreq = sysreq
81         # constant case (redundant)
82         sysreq = tolower(sysreq)
83         # drop version information/comments for now
84         sysreq = gsub('[[][^])]*[]]','',sysreq)
85         sysreq = gsub('\\([^)]*\\)','',sysreq)
86         sysreq = gsub('[[][^])]*[]]','',sysreq)
87         sysreq = gsub('version','',sysreq)
88         sysreq = gsub('from','',sysreq)
89         sysreq = gsub('[<>=]*[[:space:]]*[[:digit:]]+[[:digit:].+:~-]*','',sysreq)
90         # byebye URLs
91         sysreq = gsub('(ht|f)tps?://[[:alnum:]!?*"\'(),%$_@.&+/=-]*','',sysreq)
92         # squish out space -- this does not work for me (did not want to touch, though), Steffen
93         sysreq = chomp(gsub('[[:space:]]+',' ',sysreq))
94         # no final dot and neither final blanks
95         sysreq = gsub('\\.?\\s*$','',sysreq)
96         if (nchar(sysreq) == 0) {
97             notice('part of the SystemRequirement became nothing')
98             next
99         }
100         alias <- db_sysreq_override(sysreq)
101         if (is.null(alias)) {
102             error('do not know what to do with SystemRequirement:',sysreq)
103             error('original SystemRequirement:',startreq)
104             fail('unmet system requirement')
105         }
106         notice(paste("mapped SystemRequirement '",startreq,"' onto '",alias,"' via '",sysreq,"'.",sep=""))
107         aliases = c(aliases,alias)
108     }
109     return(map_aliases_to_debian(aliases))
110 }
111
112 forced_deps_as_debian <- function(r_name) {
113     aliases <- db_get_forced_depends(r_name)
114     return(map_aliases_to_debian(aliases))
115 }
116
117 map_aliases_to_debian <- function(aliases) {
118     if (!length(aliases)) {
119         return(aliases)
120     }
121     debs <- list()
122     debs$bin = unlist(sapply(aliases, db_get_depends))
123     debs$build = unlist(sapply(aliases, db_get_depends, build=T))
124     debs$bin = debs$bin[debs$bin != 'build-essential']
125     debs$build = debs$build[debs$build != 'build-essential']
126     return(debs)
127 }
128
129 generate_control <- function(pkg) {
130     # construct control file
131
132     control <- data.frame()
133     control[1,'Source'] <- pkg$srcname
134     control[1,'Section'] <- 'gnu-r'
135     control[1,'Priority'] <- 'optional'
136     control[1,'Maintainer'] <- maintainer
137     control[1,'Build-Depends'] <- paste(pkg$depends$build, collapse=', ')
138     control[1,'Standards-Version'] <- '3.9.1'
139     if ('URL' %in% colnames(pkg$description)) {
140         control[1,'Homepage'] <- pkg$description[1,'URL']
141     }
142
143     control[2,'Package'] <- pkg$debname
144     control[2,'Architecture'] <- 'all'
145     if (pkg$archdep) {
146         control[2,'Architecture'] <- 'any'
147     }
148     control[2,'Depends'] <- paste(pkg$depends$bin,collapse=', ',sep='')
149
150     # generate the description
151     descr <- 'GNU R package "'
152     if ('Title' %in% colnames(pkg$description)) {
153         descr <- paste(descr,pkg$description[1,'Title'],sep='')
154     } else {
155         descr <- paste(descr,pkg$name,sep='')
156     }
157     long_descr <- pkg$description[1,'Description']
158
159     if (length(long_descr) < 1 || long_descr == "") {
160         # bypass lintian extended-description-is-empty for which we care not.
161         long_descr <- paste('The author/maintainer of this package'
162                            ,'did not care to enter a longer description.')
163     }
164
165     # using \n\n.\n\n is not very nice, but is necessary to make sure
166     # the longer description does not begin on the synopsis line --- R's
167     # write.dcf does not appear to have a nicer way of doing this.
168     descr <- paste(descr,'"\n\n', long_descr, sep='')
169     # add some extra nice info about the original R package
170     for (r_info in c('Author','Maintainer')) {
171         if (r_info %in% colnames(pkg$description)) {
172             descr <- paste(descr,'\n\n',r_info,': ',pkg$description[1,r_info],sep='')
173         }
174     }
175     if (Encoding(descr) == "unknown")
176         Encoding(descr) <- "latin1"     # or should it be UTF-8
177
178     control[2,'Description'] <- descr
179
180     # Debian policy says 72 char width; indent minimally
181     write.dcf(control,file=pkg$debfile('control.in'),indent=1,width=72)
182     write.dcf(control,indent=1,width=72)
183 }
184