]> git.donarmstrong.com Git - cran2deb.git/blob - branch/double_build/R/debianpkg.R
split view of debian_dependency and blacklist_packages by system; preparation for...
[cran2deb.git] / branch / double_build / R / debianpkg.R
1 append_build_from_pkg <- function(pkg, builds) {
2     pkg_build <- data.frame(id = -1     # never used
3                            ,package = pkg$name
4                            ,system = which_system
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
13                            )
14     return(cbind(data.frame(srcname=pkg$srcname), rbind(builds, pkg_build)))
15 }
16
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'))
22 }
23
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,') testing; 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)
32 }
33
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'
38              ,'',sep='\n')
39        ,file=pkg$debfile('rules'))
40     if (pkg$name %in% c("Rmpi", "npRmpi", "doMPI")) {
41         cat("extraInstallFlags=\"--no-test-load\"\n", file=pkg$debfile('rules'), append=TRUE)
42     }      
43     Sys.chmod(pkg$debfile('rules'),'0700')
44 }
45
46 generate_copyright <- function(pkg) {
47     # generate_copyright file; we trust DESCRIPTION
48
49     # if maintainer is missing then try to use author
50     if (!('Maintainer' %in% colnames(pkg$description))) {
51         if ('Author' %in% colnames(pkg$description)) {
52             maintainer = pkg$description[1,'Author']
53         } else {
54             fail('Maintainer and Author not defined in R DESCRIPTION')
55         }
56     } else {
57         maintainer = pkg$description[1,'Maintainer']
58     }
59     # likewise if author is missing then try to use maintainer
60     if (!('Author' %in% colnames(pkg$description))) {
61         author = maintainer
62     } else {
63         author = pkg$description[1,'Author']
64     }
65
66     writeLines(strwrap(
67         paste('This Debian package of the GNU R package',pkg$name
68              ,'was generated automatically using cran2deb by'
69              ,paste(maintainer,'.',sep='')
70              ,''
71              ,'The original GNU R package is Copyright (C) '
72              # TODO: copyright start date, true copyright date
73              ,format(Sys.time(),'%Y')
74              ,author
75              ,'and possibly others.'
76              ,''
77              ,'The original GNU R package is maintained by'
78              ,maintainer,'and was obtained from:'
79              ,''
80              ,pkg$repoURL
81              ,''
82              ,''
83              ,'The GNU R package DESCRIPTION offers a'
84              ,'Copyright licenses under the terms of the license:'
85              ,pkg$license,'.  On a Debian GNU/Linux system, common'
86              ,'licenses are included in the directory'
87              ,'/usr/share/common-licenses/.'
88              ,''
89              ,'The DESCRIPTION file for the original GNU R package '
90              ,'can be found in '
91              ,file.path('/usr/lib/R/site-library'
92                    ,pkg$debname
93                    ,'DESCRIPTION'
94                    )
95              ,sep='\n'), width=72), con=pkg$debfile('copyright.in'))
96 }
97
98 prepare_new_debian <- function(pkg,extra_deps) {
99     # generate Debian version and name
100     pkg$debversion = new_build_version(pkg$name)
101
102     # make the debian/ directory
103     debdir <- file.path(pkg$path,'debian')
104     pkg$debfile <- function(x) { file.path(debdir,x) }
105     unlink(debdir,recursive=T)
106     dir.create(debdir)
107
108     # see if this is an architecture-dependent package.
109     # heuristic: if /src/ exists in pkg$path, then this is an
110     #            architecture-dependent package.
111     # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
112     # says: ``The sources and headers for the compiled code are in src, plus
113     # optionally file Makevars or Makefile.'' It seems unlikely that
114     # architecture independent code would end up here.
115     pkg$archdep = file.exists(file.path(pkg$path,'src'))
116     pkg$license <- accept_license(pkg)
117     pkg$depends <- get_dependencies(pkg,extra_deps)
118     apply_patches(pkg)
119     generate_lintian(pkg)
120     generate_changelog(pkg)
121     generate_rules(pkg)
122     generate_copyright(pkg)
123     generate_control(pkg)
124     ## debdir <- file.path(pkg$path,'debian')
125     ## system(paste("ls ", debdir, "; ls -l ", debdir, "/patches/*", sep=""))
126
127     # convert text to utf8 (who knows what the original character set is --
128     # let's hope iconv DTRT).
129     for (file in c('control','changelog','copyright')) {
130         log_system('iconv -o ',shQuote(pkg$debfile(file))
131                     ,' -t utf8 -c '
132                     ,shQuote(pkg$debfile(paste(file,'in',sep='.'))))
133         file.remove(pkg$debfile(paste(file,'in',sep='.')))
134     }
135     return(pkg)
136 }