]> git.donarmstrong.com Git - cran2deb.git/blob - pkg/trunk/R/debianpkg.R
build: log system output, build if last build failed. don't build if last build succe...
[cran2deb.git] / pkg / trunk / R / debianpkg.R
1 generate_changelog <- function(pkg) {
2     # construct a dummy changelog
3     # TODO: ``Writing R extensions'' mentions that a package may also have
4     # {NEWS,ChangeLog} files.
5     cat(paste(paste(pkg$srcname,' (',pkg$debversion,') unstable; urgency=low',sep='')
6              ,'' ,'  * Initial release.',''
7              ,paste(' --',maintainer,'',format(Sys.time(),'%a, %d %b %Y %H:%M:%S %z'))
8              ,'',sep='\n'),file=pkg$debfile('changelog.in'))
9 }
10
11 generate_rules <- function(pkg) {
12     cat(paste('#!/usr/bin/make -f'
13              ,paste('debRreposname :=',pkg$repo)
14              ,'include /usr/share/R/debian/r-cran.mk'
15              ,'',sep='\n')
16        ,file=pkg$debfile('rules'))
17     Sys.chmod(pkg$debfile('rules'),'0700')
18 }
19
20 generate_copyright <- function(pkg) {
21     # generate_copyright file; we trust DESCRIPTION
22     writeLines(strwrap(
23         paste('This Debian package of the GNU R package',pkg$name
24              ,'was generated automatically using cran2deb by'
25              ,paste(maintainer,'.',sep='')
26              ,''
27              ,'The original GNU R package is Copyright (C) '
28              # TODO: copyright start date, true copyright date
29              ,format(Sys.time(),'%Y')
30              ,pkg$description[1,'Author']
31              ,'and possibly others.'
32              ,''
33              ,'The original GNU R package is maintained by'
34              ,pkg$description[1,'Maintainer'],'and was obtained from:'
35              ,''
36              ,pkg$repoURL
37              ,''
38              ,''
39              ,'The GNU R package DESCRIPTION offers a'
40              ,'Copyright licenses under the terms of the',pkg$license
41              ,'license.  On a Debian GNU/Linux system, common'
42              ,'licenses are included in the directory'
43              ,'/usr/share/common-licenses/.'
44              ,''
45              ,'The DESCRIPTION file for the original GNU R package '
46              ,'can be found in '
47              ,file.path('/usr/lib/R/site-library'
48                    ,pkg$debname
49                    ,'DESCRIPTION'
50                    )
51              ,sep='\n'), width=72), con=pkg$debfile('copyright.in'))
52 }
53
54 prepare_new_debian <- function(pkg,extra_deps) {
55     # generate Debian version and name
56     pkg$repo = repourl_as_debian(pkg$repoURL)
57     if (pkg$version != available[pkg$name,'Version']) {
58         # should never happen since available is the basis upon which the
59         # package is retrieved.
60         error('available version:',available[pkg$name,'Version'])
61         error('package version:',pkg$version)
62         fail('inconsistency between R package version and cached R version')
63     }
64     pkg$debversion = new_build_version(pkg$name)
65     if (!length(grep('^[A-Za-z0-9][A-Za-z0-9+.-]+$',pkg$name))) {
66         fail('Cannot convert package name into a Debian name',pkg$name)
67     }
68     pkg$srcname = tolower(pkg$name)
69     pkg$debname = pkgname_as_debian(pkg$name,repo=pkg$repo)
70
71     if (!length(grep('\\.tar\\.gz',pkg$archive))) {
72         fail('archive is not tarball')
73     }
74
75     # re-pack into a Debian-named archive with a Debian-named directory.
76     debpath = file.path(dirname(pkg$archive)
77                    ,paste(pkg$srcname,'-'
78                          ,pkg$version
79                          ,sep=''))
80     file.rename(pkg$path, debpath)
81     pkg$path = debpath
82     debarchive = file.path(dirname(pkg$archive)
83                           ,paste(pkg$srcname,'_'
84                                 ,pkg$version,'.orig.tar.gz'
85                                 ,sep=''))
86     wd <- getwd()
87     setwd(dirname(pkg$path))
88     # remove them pesky +x files
89     log_system('find',shQuote(basename(pkg$path))
90                 ,'-type f -exec chmod -x {} \\;')
91     # tar it all back up
92     log_system('tar -czf',shQuote(debarchive),shQuote(basename(pkg$path)))
93     setwd(wd)
94     file.remove(pkg$archive)
95     pkg$archive = debarchive
96
97     # make the debian/ directory
98     debdir <- file.path(pkg$path,'debian')
99     pkg$debfile <- function(x) { file.path(debdir,x) }
100     unlink(debdir,recursive=T)
101     dir.create(debdir)
102
103     # see if this is an architecture-dependent package.
104     # heuristic: if /src/ exists in pkg$path, then this is an
105     #            architecture-dependent package.
106     # CRAN2DEB.pm is a bit fancier about this but ``Writing R extensions''
107     # says: ``The sources and headers for the compiled code are in src, plus
108     # optionally file Makevars or Makefile.'' It seems unlikely that
109     # architecture independent code would end up here.
110     if (pkg$is_bundle) {
111         # if it's a bundle, check each of the packages
112         pkg$archdep = F
113         for (pkgname in r_bundle_contains(pkg$name)) {
114             pkg$archdep = file.exists(file.path(pkg$path,pkgname,'src'))
115             if (pkg$archdep) {
116                 break
117             }
118         }
119     } else {
120         pkg$archdep = file.exists(file.path(pkg$path,'src'))
121     }
122     pkg$arch <- 'all'
123     if (pkg$archdep) {
124         pkg$arch <- host_arch()
125     }
126
127     pkg$license <- accept_license(pkg)
128     pkg$depends <- get_dependencies(pkg,extra_deps)
129     generate_changelog(pkg)
130     generate_rules(pkg)
131     generate_copyright(pkg)
132     generate_control(pkg)
133
134     # TODO: debian/watch from pkg$repoURL
135
136     # convert text to utf8 (who knows what the original character set is --
137     # let's hope iconv DTRT).
138     for (file in c('control','changelog','copyright')) {
139         log_system('iconv -o ',shQuote(pkg$debfile(file))
140                     ,' -t utf8 '
141                     ,shQuote(pkg$debfile(paste(file,'in',sep='.'))))
142         file.remove(pkg$debfile(paste(file,'in',sep='.')))
143     }
144     return(pkg)
145 }