]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/R/debcontrol.R
a4f9271f5df1f8c484655bc7b10f700ca0ce958f
[cran2deb.git] / trunk / R / debcontrol.R
1 get_dependencies <- function(pkg,extra_deps) {
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 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)
22     }
23
24     forced <- forced_deps_as_debian(pkg$name)
25     if (length(forced)) {
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)
30     }
31
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))
36     }
37     # also include stuff to allow tcltk to build (suggested by Dirk)
38     depends$build = c(depends$build,'xvfb','xauth','xfonts-base')
39
40     # make all bin dependencies build dependencies.
41     depends$build = c(depends$build, depends$bin)
42
43     # remove duplicates
44     depends <- lapply(depends,unique)
45
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')
50     }
51     if (pkg$archdep) {
52         depends$bin=c(depends$bin,'${shlibs:Depends}')
53     }
54
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)
60     return(depends)
61 }
62
63 sysreqs_as_debian <- function(sysreq_text) {
64     # form of this field is unspecified (ugh) but most people seem to stick
65     # with this
66     aliases <- c()
67     sysreq_text <- gsub('[[:space:]]and[[:space:]]',' , ',tolower(sysreq_text))
68     for (sysreq in strsplit(sysreq_text,'[[:space:]]*,[[:space:]]*')[[1]]) {
69         startreq = sysreq
70         # constant case
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)
79         # byebye URLs
80         sysreq = gsub('(ht|f)tps?://[[:alnum:]!?*"\'(),%$_@.&+/=-]*','',sysreq)
81         # squish out space
82         sysreq = chomp(gsub('[[:space:]]+',' ',sysreq))
83         if (nchar(sysreq) == 0) {
84             notice('part of the SystemRequirement became nothing')
85             next
86         }
87         alias <- db_sysreq_override(sysreq)
88         if (is.null(alias)) {
89             error('do not know what to do with SystemRequirement:',sysreq)
90             error('original SystemRequirement:',startreq)
91             fail('unmet system requirement')
92         }
93         notice('mapped SystemRequirement',startreq,'onto',alias,'via',sysreq)
94         aliases = c(aliases,alias)
95     }
96     return(map_aliases_to_debian(aliases))
97 }
98
99 forced_deps_as_debian <- function(r_name) {
100     aliases <- db_get_forced_depends(r_name)
101     return(map_aliases_to_debian(aliases))
102 }
103
104 map_aliases_to_debian <- function(aliases) {
105     if (!length(aliases)) {
106         return(aliases)
107     }
108     debs <- list()
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']
113     return(debs)
114 }
115
116 generate_control <- function(pkg) {
117     # construct control file
118
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.9.1'
126     if ('URL' %in% colnames(pkg$description)) {
127         control[1,'Homepage'] <- pkg$description[1,'URL']
128     }
129
130     control[2,'Package'] <- pkg$debname
131     control[2,'Architecture'] <- 'all'
132     if (pkg$archdep) {
133         control[2,'Architecture'] <- 'any'
134     }
135     control[2,'Depends'] <- paste(pkg$depends$bin,collapse=', ',sep='')
136
137     # generate the description
138     descr <- 'GNU R package "'
139     if ('Title' %in% colnames(pkg$description)) {
140         descr <- paste(descr,pkg$description[1,'Title'],sep='')
141     } else {
142         descr <- paste(descr,pkg$name,sep='')
143     }
144     long_descr <- pkg$description[1,'Description']
145
146     if (length(long_descr) < 1 || long_descr == "") {
147         # bypass lintian extended-description-is-empty for which we care not.
148         long_descr <- paste('The author/maintainer of this package'
149                            ,'did not care to enter a longer description.')
150     }
151
152     # using \n\n.\n\n is not very nice, but is necessary to make sure
153     # the longer description does not begin on the synopsis line --- R's
154     # write.dcf does not appear to have a nicer way of doing this.
155     descr <- paste(descr,'"\n\n', long_descr, sep='')
156     # add some extra nice info about the original R package
157     for (r_info in c('Author','Maintainer')) {
158         if (r_info %in% colnames(pkg$description)) {
159             descr <- paste(descr,'\n\n',r_info,': ',pkg$description[1,r_info],sep='')
160         }
161     }
162     if (Encoding(descr) == "unknown")
163         Encoding(descr) <- "latin1"     # or should it be UTF-8
164
165     control[2,'Description'] <- descr
166
167     # Debian policy says 72 char width; indent minimally
168     write.dcf(control,file=pkg$debfile('control.in'),indent=1,width=72)
169     write.dcf(control,indent=1,width=72)
170 }
171