]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/R/build.R
do not destroy archive between builds: accumulate. for this reason, no reason for...
[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         # make mini-dinstall generate the skeleton of the archive
32         ret = log_system('umask 002;mini-dinstall --batch -c',dinstall_config)
33         if (ret != 0) {
34             fail('failed to create archive')
35         }
36
37         notice('R dependencies:',paste(pkg$depends$r,collapse=', '))
38         build_debian(pkg)
39
40         # upload the package
41         ret = log_system('umask 002;dput','-c',shQuote(dput_config),'local'
42                     ,changesfile(pkg$srcname,pkg$debversion))
43         if (ret != 0) {
44             fail('upload failed!')
45         }
46
47         return(pkg$debversion)
48     })())
49     cleanup(dir)
50     if (is.null(result)) {
51         # nothing was done so escape asap.
52         return(result)
53     }
54
55     # otherwise record progress
56     failed = inherits(result,'try-error')
57     if (failed) {
58         error('failure of',name,'means these packages will fail:'
59                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', '))
60     }
61     db_record_build(name, version, log_retrieve(), !failed)
62     return(!failed)
63 }
64
65 needs_build <- function(name,version) {
66     # see if the last build was successful
67     build <- db_latest_build(name)
68     if (!is.null(build) && build$success) {
69         # then something must have changed for us to attempt this
70         # build
71         if (build$r_version == version_upstream(version) &&
72             build$deb_epoch == version_epoch(version) &&
73             build$db_version == db_get_version()) {
74             return(F)
75         }
76     } else {
77         # always rebuild on failure or no record
78         return(T)
79     }
80     # see if it has already been built
81     srcname <- pkgname_as_debian(name,binary=F)
82     debname <- pkgname_as_debian(name,binary=T)
83     if (file.exists(changesfile(srcname, version))) {
84         notice('already built',srcname,'version',version)
85         return(F)
86     }
87
88     # XXX: what about building newer versions of Debian packages?
89     if (debname %in% debian_pkgs) {
90         notice(srcname,' exists in Debian (perhaps a different version)')
91         return(F)
92     }
93
94     rm(debname,srcname)
95     return(T)
96 }
97
98 build_debian <- function(pkg) {
99     wd <- getwd()
100     setwd(pkg$path)
101     notice('building Debian package'
102                  ,pkg$debname
103                  ,paste('(',pkg$debversion,')',sep='')
104                  ,'...')
105
106     cmd = paste('pdebuild --configfile',shQuote(pbuilder_config))
107     if (version_revision(pkg$debversion) > 2) {
108         cmd = paste(cmd,'--debbuildopts','-sd')
109         notice('build should exclude original source')
110     }
111     ret = log_system(cmd)
112     setwd(wd)
113     if (ret != 0) {
114         fail('Failed to build package.')
115     }
116 }
117