1 get_dependencies <- function(pkg,extra_deps) {
2 # determine dependencies
3 dependencies <- r_dependencies_of(description=pkg$description)
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
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 the system requirements
18 if ('SystemRequirements' %in% colnames(pkg$description)) {
19 sysreq <- sysreqs_as_debian(pkg$description[1,'SystemRequirements'])
20 depends$bin = c(sysreq$bin,depends$bin)
21 depends$build = c(sysreq$build,depends$build)
24 forced <- forced_deps_as_debian(pkg$name)
26 notice('forced build dependencies:',paste(forced$build, collapse=', '))
27 notice('forced binary dependencies:',paste(forced$bin, collapse=', '))
28 depends$bin = c(forced$bin,depends$bin)
29 depends$build = c(forced$build,depends$build)
32 # make sure we depend upon R in some way...
33 if (!length(grep('^r-base',depends$build))) {
34 depends$build = c(depends$build,pkgname_as_debian('R',version='>= 2.7.0',build=T))
35 depends$bin = c(depends$bin, pkgname_as_debian('R',version='>= 2.7.0',build=F))
37 # also include stuff to allow tcltk to build (suggested by Dirk)
38 depends$build = c(depends$build,'xvfb','xauth','xfonts-base')
40 # make all bin dependencies build dependencies.
41 depends$build = c(depends$build, depends$bin)
44 depends <- lapply(depends,unique)
46 # append the Debian dependencies
47 depends$build=c(depends$build,'debhelper (>> 4.1.0)','cdbs')
48 if (file.exists(file.path(patch_dir, pkg$name))) {
49 depends$build <- c(depends$build,'dpatch')
52 depends$bin=c(depends$bin,'${shlibs:Depends}')
55 # the names of dependent source packages (to find the .changes file to
56 # upload via dput). these can be found recursively.
57 depends$r = r_dependency_closure(dependencies)
58 # append command line dependencies
59 depends$r = c(extra_deps$r, depends$r)
63 sysreqs_as_debian <- function(sysreq_text) {
64 # form of this field is unspecified (ugh) but most people seem to stick
67 sysreq_text <- gsub('[[:space:]]and[[:space:]]',' , ',tolower(sysreq_text))
68 for (sysreq in strsplit(sysreq_text,'[[:space:]]*,[[:space:]]*')[[1]]) {
71 sysreq = tolower(sysreq)
72 # drop version information/comments for now
73 sysreq = gsub('[[][^])]*[]]','',sysreq)
74 sysreq = gsub('\\([^)]*\\)','',sysreq)
75 sysreq = gsub('[[][^])]*[]]','',sysreq)
76 sysreq = gsub('version','',sysreq)
77 sysreq = gsub('from','',sysreq)
78 sysreq = gsub('[<>=]*[[:space:]]*[[:digit:]]+[[:digit:].+:~-]*','',sysreq)
80 sysreq = gsub('(ht|f)tps?://[[:alnum:]!?*"\'(),%$_@.&+/=-]*','',sysreq)
82 sysreq = chomp(gsub('[[:space:]]+',' ',sysreq))
83 if (nchar(sysreq) == 0) {
84 notice('part of the SystemRequirement became nothing')
87 alias <- db_sysreq_override(sysreq)
89 error('do not know what to do with SystemRequirement:',sysreq)
90 error('original SystemRequirement:',startreq)
91 fail('unmet system requirement')
93 notice('mapped SystemRequirement',startreq,'onto',alias,'via',sysreq)
94 aliases = c(aliases,alias)
96 return(map_aliases_to_debian(aliases))
99 forced_deps_as_debian <- function(r_name) {
100 aliases <- db_get_forced_depends(r_name)
101 return(map_aliases_to_debian(aliases))
104 map_aliases_to_debian <- function(aliases) {
105 if (!length(aliases)) {
109 debs$bin = unlist(sapply(aliases, db_get_depends))
110 debs$build = unlist(sapply(aliases, db_get_depends, build=T))
111 debs$bin = debs$bin[debs$bin != 'build-essential']
112 debs$build = debs$build[debs$build != 'build-essential']
116 generate_control <- function(pkg) {
117 # construct control file
119 control <- data.frame()
120 control[1,'Source'] <- pkg$srcname
121 control[1,'Section'] <- 'gnu-r'
122 control[1,'Priority'] <- 'optional'
123 control[1,'Maintainer'] <- maintainer
124 control[1,'Build-Depends'] <- paste(pkg$depends$build, collapse=', ')
125 control[1,'Standards-Version'] <- '3.8.4'
127 control[2,'Package'] <- pkg$debname
128 control[2,'Architecture'] <- 'all'
130 control[2,'Architecture'] <- 'any'
132 control[2,'Depends'] <- paste(pkg$depends$bin,collapse=', ')
134 # generate the description
135 descr <- 'GNU R package "'
136 if ('Title' %in% colnames(pkg$description)) {
137 descr <- paste(descr,pkg$description[1,'Title'],sep='')
139 descr <- paste(descr,pkg$name,sep='')
141 long_descr <- pkg$description[1,'Description']
143 if (length(long_descr) < 1 || long_descr == "") {
144 # bypass lintian extended-description-is-empty for which we care not.
145 long_descr <- paste('The author/maintainer of this package'
146 ,'did not care to enter a longer description.')
149 # using \n\n.\n\n is not very nice, but is necessary to make sure
150 # the longer description does not begin on the synopsis line --- R's
151 # write.dcf does not appear to have a nicer way of doing this.
152 descr <- paste(descr,'"\n\n', long_descr, sep='')
153 # add some extra nice info about the original R package
154 for (r_info in c('Author','Maintainer','URL')) {
155 if (r_info %in% colnames(pkg$description)) {
156 descr <- paste(descr,'\n\n',r_info,': ',pkg$description[1,r_info],sep='')
159 if (Encoding(descr) == "unknown")
160 Encoding(descr) <- "latin1" # or should it be UTF-8
162 control[2,'Description'] <- descr
164 # Debian policy says 72 char width; indent minimally
165 write.dcf(control,file=pkg$debfile('control.in'),indent=1,width=72)
166 write.dcf(control,indent=1,width=72)