1 append_build_from_pkg <- function(pkg, builds) {
2 pkg_build <- data.frame(id = -1 # never used
5 ,r_version = version_upstream(pkg$debversion)
6 ,deb_epoch = version_epoch(pkg$debversion)
7 ,deb_revision = version_revision(pkg$debversion)
8 ,db_version = db_get_version()
9 ,date_stamp = pkg$date_stamp
10 ,scm_revision = scm_revision
11 ,success = 1 # never used
12 ,log = '' # never used
14 return(cbind(data.frame(srcname=pkg$srcname), rbind(builds, pkg_build)))
17 generate_changelog <- function(pkg) {
18 # TODO: ``Writing R extensions'' mentions that a package may also have
19 # {NEWS,ChangeLog} files.
20 builds <- append_build_from_pkg(pkg, db_builds(pkg$name))
21 sapply(rev(rownames(builds)), function(b, changelog) generate_changelog_entry(builds[b,], changelog), pkg$debfile('changelog.in'))
24 generate_changelog_entry <- function(build, changelog) {
25 # TODO: should say 'New upstream release' when necessary
26 debversion <- version_new(build$r_version, build$deb_revision, build$deb_epoch)
27 cat(paste(paste(build$srcname,' (',debversion,') unstable; urgency=low',sep='')
28 ,'' ,paste(' * cran2deb ',build$scm_revision
29 ,' with DB version ',as.integer(build$db_version),'.',sep='')
30 ,'',paste(' --',maintainer,'',format(build$date_stamp,'%a, %d %b %Y %H:%M:%S %z'))
31 ,'','','',sep='\n'),file=changelog, append=TRUE)
34 generate_rules <- function(pkg) {
35 cat(paste('#!/usr/bin/make -f'
36 ,paste('debRreposname :=',pkg$repo)
37 ,'include /usr/share/R/debian/r-cran.mk'
39 ,file=pkg$debfile('rules'))
40 Sys.chmod(pkg$debfile('rules'),'0700')
43 generate_copyright <- function(pkg) {
44 # generate_copyright file; we trust DESCRIPTION
46 # if maintainer is missing then try to use author
47 if (!('Maintainer' %in% colnames(pkg$description))) {
48 if ('Author' %in% colnames(pkg$description)) {
49 maintainer = pkg$description[1,'Author']
51 fail('Maintainer and Author not defined in R DESCRIPTION')
54 maintainer = pkg$description[1,'Maintainer']
56 # likewise if author is missing then try to use maintainer
57 if (!('Author' %in% colnames(pkg$description))) {
60 author = pkg$description[1,'Author']
64 paste('This Debian package of the GNU R package',pkg$name
65 ,'was generated automatically using cran2deb by'
66 ,paste(maintainer,'.',sep='')
68 ,'The original GNU R package is Copyright (C) '
69 # TODO: copyright start date, true copyright date
70 ,format(Sys.time(),'%Y')
72 ,'and possibly others.'
74 ,'The original GNU R package is maintained by'
75 ,maintainer,'and was obtained from:'
80 ,'The GNU R package DESCRIPTION offers a'
81 ,'Copyright licenses under the terms of the license:'
82 ,pkg$license,'. On a Debian GNU/Linux system, common'
83 ,'licenses are included in the directory'
84 ,'/usr/share/common-licenses/.'
86 ,'The DESCRIPTION file for the original GNU R package '
88 ,file.path('/usr/lib/R/site-library'
92 ,sep='\n'), width=72), con=pkg$debfile('copyright.in'))
95 prepare_new_debian <- function(pkg,extra_deps) {
96 # generate Debian version and name
97 pkg$debversion = new_build_version(pkg$name)
99 # make the debian/ directory
100 debdir <- file.path(pkg$path,'debian')
101 pkg$debfile <- function(x) { file.path(debdir,x) }
102 unlink(debdir,recursive=T)
105 # see if this is an architecture-dependent package.
106 # heuristic: if /src/ exists in pkg$path, then this is an
107 # architecture-dependent package.
108 # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
109 # says: ``The sources and headers for the compiled code are in src, plus
110 # optionally file Makevars or Makefile.'' It seems unlikely that
111 # architecture independent code would end up here.
113 # if it's a bundle, check each of the packages
115 for (pkgname in r_bundle_contains(pkg$name)) {
116 pkg$archdep = file.exists(file.path(pkg$path,pkgname,'src'))
122 pkg$archdep = file.exists(file.path(pkg$path,'src'))
126 pkg$arch <- host_arch()
129 pkg$license <- accept_license(pkg)
130 pkg$depends <- get_dependencies(pkg,extra_deps)
132 generate_changelog(pkg)
134 generate_copyright(pkg)
135 generate_control(pkg)
137 # convert text to utf8 (who knows what the original character set is --
138 # let's hope iconv DTRT).
139 for (file in c('control','changelog','copyright')) {
140 log_system('iconv -o ',shQuote(pkg$debfile(file))
142 ,shQuote(pkg$debfile(paste(file,'in',sep='.'))))
143 file.remove(pkg$debfile(paste(file,'in',sep='.')))