]> git.donarmstrong.com Git - cran2deb.git/blob - pkg/trunk/R/build.R
build: refactor, add autobuild command to build outdated packages.
[cran2deb.git] / pkg / trunk / R / build.R
1
2 build <- function(name,extra_deps) {
3     dir <- setup()
4     pkg <- try((function() {
5         # see if it has already been built
6         srcname <- pkgname_as_debian(name,binary=F)
7         debname <- pkgname_as_debian(name,binary=T)
8         version <- version_new(available[name,'Version'])
9         if (file.exists(changesfile(srcname, version))) {
10             message(paste('N: already built',srcname,'version',version))
11             return(NA)
12         }
13         # XXX: what about building newer versions?
14         if (debname %in% debian_pkgs) {
15             message(paste('N:',srcname,' exists in Debian (perhaps a different version)'))
16             return(NA)
17         }
18
19         rm(debname,srcname,version)
20
21         pkg <- prepare_new_debian(prepare_pkg(dir,name),extra_deps)
22         # delete the current archive (XXX: assumes mini-dinstall)
23         for (subdir in c('mini-dinstall','unstable')) {
24             path = file.path(dinstall_archive,subdir)
25             if (file.exists(path)) {
26                 unlink(path,recursive=T)
27             }
28         }
29
30         # delete notes of upload
31         file.remove(Sys.glob(file.path(pbuilder_results,'*.upload')))
32
33         # make mini-dinstall generate the skeleton of the archive
34         ret = system(paste('umask 022;mini-dinstall --batch -c',dinstall_config))
35         if (ret != 0) {
36             stop('failed to create archive')
37         }
38
39         # pull in all the R dependencies
40         message(paste('N: dependencies:',paste(pkg$depends$r,collapse=', ')))
41         for (dep in pkg$depends$r) {
42             if (pkgname_as_debian(dep) %in% debian_pkgs) {
43                 message(paste('N: using Debian package of',dep))
44                 next
45             }
46             # otherwise, convert to source package name
47             srcdep = pkgname_as_debian(dep,binary=F)
48
49             message(paste('N: uploading',srcdep))
50             ret = system(paste('umask 022;dput','-c',shQuote(dput_config),'local'
51                         ,changesfile(srcdep)))
52             if (ret != 0) {
53                 stop('upload of dependency failed! maybe you did not build it first?')
54             }
55         }
56         build_debian(pkg)
57
58         # upload the package
59         ret = system(paste('umask 022;dput','-c',shQuote(dput_config),'local'
60                     ,changesfile(pkg$srcname,pkg$debversion)))
61         if (ret != 0) {
62             stop('upload failed!')
63         }
64
65         return(pkg)
66     })())
67     cleanup(dir)
68     if (inherits(pkg,'try-error')) {
69         message(paste('E: failure of',name,'means these packages will fail:'
70                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', ')))
71         stop(call.=F)
72     }
73     return(pkg)
74 }
75
76 build_debian <- function(pkg) {
77     wd <- getwd()
78     setwd(pkg$path)
79     message(paste('N: building Debian package'
80                  ,pkg$debname
81                  ,paste('(',pkg$debversion,')',sep='')
82                  ,'...'))
83     ret = system(paste('pdebuild --configfile',shQuote(pbuilder_config)))
84     setwd(wd)
85     if (ret != 0) {
86         stop('Failed to build package.')
87     }
88 }
89