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