]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/R/build.R
daemonize mini-dinstall
[cran2deb.git] / trunk / R / build.R
1
2 build <- function(name,extra_deps,force=F) {
3     # can't, and hence don't need to, build base packages
4     if (name %in% base_pkgs) {
5         return(T)
6     }
7     log_clear()
8     dir <- setup()
9
10     # obtain the Debian version-to-be
11     version <- try(new_build_version(name))
12     if (inherits(version,'try-error')) {
13         error('failed to build',name)
14         return(NULL)
15     }
16
17     result <- try((function() {
18         if (!force && !needs_build(name,version)) {
19             notice('skipping build of',name)
20             return(NULL)
21         }
22
23         pkg <- prepare_new_debian(prepare_pkg(dir,name),extra_deps)
24         if (pkg$debversion != version) {
25             fail('expected Debian version',version,'not equal to actual version',pkg$debversion)
26         }
27
28         # delete notes of upload
29         file.remove(Sys.glob(file.path(pbuilder_results,'*.upload')))
30
31         notice('R dependencies:',paste(pkg$depends$r,collapse=', '))
32         build_debian(pkg)
33
34         # upload the package
35         ret = log_system('umask 002;dput','-c',shQuote(dput_config),'local'
36                     ,changesfile(pkg$srcname,pkg$debversion))
37         if (ret != 0) {
38             fail('upload failed!')
39         }
40
41         return(pkg$debversion)
42     })())
43     cleanup(dir)
44     if (is.null(result)) {
45         # nothing was done so escape asap.
46         return(result)
47     }
48
49     # otherwise record progress
50     failed = inherits(result,'try-error')
51     if (failed) {
52         error('failure of',name,'means these packages will fail:'
53                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', '))
54     }
55     db_record_build(name, version, log_retrieve(), !failed)
56     return(!failed)
57 }
58
59 needs_build <- function(name,version) {
60     # see if the last build was successful
61     build <- db_latest_build(name)
62     if (!is.null(build) && build$success) {
63         # then something must have changed for us to attempt this
64         # build
65         if (build$r_version == version_upstream(version) &&
66             build$deb_epoch == version_epoch(version) &&
67             build$db_version == db_get_version()) {
68             return(F)
69         }
70     } else {
71         # always rebuild on failure or no record
72         return(T)
73     }
74     # see if it has already been built
75     srcname <- pkgname_as_debian(name,binary=F)
76     debname <- pkgname_as_debian(name,binary=T)
77     if (file.exists(changesfile(srcname, version))) {
78         notice('already built',srcname,'version',version)
79         return(F)
80     }
81
82     # XXX: what about building newer versions of Debian packages?
83     if (debname %in% debian_pkgs) {
84         notice(srcname,' exists in Debian (perhaps a different version)')
85         return(F)
86     }
87
88     rm(debname,srcname)
89     return(T)
90 }
91
92 build_debian <- function(pkg) {
93     wd <- getwd()
94     setwd(pkg$path)
95     notice('building Debian package'
96                  ,pkg$debname
97                  ,paste('(',pkg$debversion,')',sep='')
98                  ,'...')
99
100     cmd = paste('pdebuild --configfile',shQuote(pbuilder_config))
101     if (version_revision(pkg$debversion) > 2) {
102         cmd = paste(cmd,'--debbuildopts','-sd')
103         notice('build should exclude original source')
104     }
105     ret = log_system(cmd)
106     setwd(wd)
107     if (ret != 0) {
108         fail('Failed to build package.')
109     }
110 }
111