]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/R/build.R
switch to reprepro instead of dput + mini-dinstall -- this works for i386 but we...
[cran2deb.git] / trunk / R / build.R
1
2 build <- function(name,extra_deps,force=F,do_cleanup=T) {
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         if (name %in% db_blacklist_packages()) {
24             fail('package',name,'is blacklisted. consult database for reason.')
25         }
26
27         pkg <- prepare_new_debian(prepare_pkg(dir,name),extra_deps)
28         if (pkg$debversion != version) {
29             fail('expected Debian version',version,'not equal to actual version',pkg$debversion)
30         }
31
32         # delete notes of upload
33         file.remove(Sys.glob(file.path(pbuilder_results,'*.upload')))
34
35         notice('R dependencies:',paste(pkg$depends$r,collapse=', '))
36         build_debian(pkg)
37
38         # upload the package
39 ##         ret = log_system('umask 002;dput','-c',shQuote(dput_config),'local' ,changesfile(pkg$srcname,pkg$debversion))
40         ret = log_system('umask 002; cd /var/www/rep; reprepro -b . include testing', changesfile(pkg$srcname,pkg$debversion))
41         if (ret != 0) {
42             fail('upload failed!')
43         }
44 ##         # wait for mini-dinstall to get to work
45 ##         upload_success = FALSE
46 ##         for (i in seq(1,12)) {
47 ##             if (file.exists(file.path(dinstall_archive,'testing',paste(pkg$srcname, '_', pkg$version, '.orig.tar.gz', sep='')))) {
48 ##                 upload_success = TRUE
49 ##                 break
50 ##             }
51 ##             warn(i,'/12: does not exist',file.path(dinstall_archive,'testing',paste(pkg$srcname, '_', pkg$version, '.orig.tar.gz', sep='')))
52
53 ##             Sys.sleep(5)
54 ##         }
55 ##         if (!upload_success) {
56 ##             warn('upload took too long; continuing as normal (some builds may fail temporarily)')
57 ##         }
58         return(pkg$debversion)
59     })())
60     if (do_cleanup) {
61         cleanup(dir)
62     } else {
63         notice('output is in',dir,'. you must clean this up yourself.')
64     }
65     if (is.null(result)) {
66         # nothing was done so escape asap.
67         return(result)
68     }
69
70     # otherwise record progress
71     failed = inherits(result,'try-error')
72     if (failed) {
73         error('failure of',name,'means these packages will fail:'
74                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', '))
75     }
76     db_record_build(name, version, log_retrieve(), !failed)
77     return(!failed)
78 }
79
80 needs_build <- function(name,version) {
81     # see if the last build was successful
82     build <- db_latest_build(name)
83     if (!is.null(build) && build$success) {
84         # then something must have changed for us to attempt this
85         # build
86         if (build$r_version == version_upstream(version) &&
87             build$deb_epoch == version_epoch(version) &&
88             build$db_version == db_get_version()) {
89             return(F)
90         }
91     } else {
92         # always rebuild on failure or no record
93         notice('rebuilding',name,': no build record or previous build failed')
94         return(T)
95     }
96     # see if it has already been built *and* successfully uploaded
97     srcname <- pkgname_as_debian(name,binary=F)
98     debname <- pkgname_as_debian(name,binary=T)
99     if (file.exists(changesfile(srcname, version))) {
100         notice('already built',srcname,'version',version)
101         return(F)
102     }
103
104     if (build$r_version != version_upstream(version)) {
105         notice('rebuilding',name,': new upstream version',build$r_version,'(old) vs',version_upstream(version),'(new)')
106     }
107     if (build$deb_epoch != version_epoch(version)) {
108         notice('rebuilding',name,': new cran2deb epoch',build$deb_epoch,'(old) vs',version_epoch(version),'(new)')
109     }
110     if (build$db_version != db_get_version()) {
111         notice('rebuilding',name,': new db version',build$db_version,'(old) vs',db_get_version(),'(new)')
112     }
113     rm(debname,srcname)
114     return(T)
115 }
116
117 build_debian <- function(pkg) {
118     wd <- getwd()
119     setwd(pkg$path)
120     notice('building Debian package'
121                  ,pkg$debname
122                  ,paste('(',pkg$debversion,')',sep='')
123                  ,'...')
124
125     cmd = paste('pdebuild --configfile',shQuote(pbuilder_config))
126     if (version_revision(pkg$debversion) > 2) {
127         cmd = paste(cmd,'--debbuildopts','-sd')
128         notice('build should exclude original source')
129     }
130     ret = log_system(cmd)
131     setwd(wd)
132     if (ret != 0) {
133         fail('Failed to build package.')
134     }
135 }
136