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