]> git.donarmstrong.com Git - cran2deb.git/blob - branch/split_build/R/build.R
rename double_build -> split_build
[cran2deb.git] / branch / split_build / 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         notice('R dependencies:',paste(pkg$depends$r,collapse=', '))
35         try_upload <- function(pkg, arch) {
36             ret = log_system('umask 002; reprepro -b ',reprepro_dir,' include testing', changesfile(pkg$srcname,pkg$debversion, arch))
37             if (ret != 0) {
38                 fail('upload failed!')
39             }
40         }
41         if (pkg$archdep) {
42             build_debian(pkg, indep_arch)
43             try_upload(pkg, indep_arch)
44         } else {
45             for (arch in archs) {
46                 build_debian(pkg, arch)
47                 try_upload(pkg, arch)
48             }
49         }
50
51         return(pkg$debversion)
52     })())
53     if (do_cleanup) {
54         cleanup(dir)
55     } else {
56         notice('output is in',dir,'. you must clean this up yourself.')
57     }
58     if (is.null(result)) {
59         # nothing was done so escape asap.
60         return(result)
61     }
62
63     # otherwise record progress
64     failed = inherits(result,'try-error')
65     if (failed) {
66         error('failure of',name,'means these packages will fail:'
67                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', '))
68     }
69     db_record_build(name, version, log_retrieve(), !failed)
70     return(!failed)
71 }
72
73 needs_build <- function(name,version) {
74     # see if the last build was successful
75     build <- db_latest_build(name)
76     if (!is.null(build) && build$success) {
77         # then something must have changed for us to attempt this
78         # build
79         if (build$r_version == version_upstream(version) &&
80             build$deb_epoch == version_epoch(version) &&
81             build$db_version == db_get_version()) {
82             return(F)
83         }
84     } else {
85         # always rebuild on failure or no record
86         notice('rebuilding',name,': no build record or previous build failed')
87         return(T)
88     }
89     # see if it has already been built *and* successfully uploaded
90     srcname <- pkgname_as_debian(name,binary=F)
91     debname <- pkgname_as_debian(name,binary=T)
92     all=TRUE
93     for (arch in archs) {
94         all = all && file.exists(changesfile(srcname, version, arch))
95     }
96     if (all || file.exists(changesfile(srcname, version,indep_arch))) {
97         notice('already built',srcname,'version',version)
98         return(F)
99     }
100
101     if (build$r_version != version_upstream(version)) {
102         notice('rebuilding',name,': new upstream version',build$r_version,'(old) vs',version_upstream(version),'(new)')
103     }
104     if (build$deb_epoch != version_epoch(version)) {
105         notice('rebuilding',name,': new cran2deb epoch',build$deb_epoch,'(old) vs',version_epoch(version),'(new)')
106     }
107     if (build$db_version != db_get_version()) {
108         notice('rebuilding',name,': new db version',build$db_version,'(old) vs',db_get_version(),'(new)')
109     }
110     rm(debname,srcname)
111     return(T)
112 }
113
114 build_debian <- function(pkg,arch) {
115     wd <- getwd()
116     setwd(pkg$path)
117     notice('building Debian package'
118                  ,pkg$debname
119                  ,paste('(',pkg$debversion,')',sep='')
120                  ,'for',arch,'...')
121
122     cmd = paste('pdebuild --configfile',shQuote(get_pbuilder_config(arch)))
123     if (version_revision(pkg$debversion) > 2) {
124         cmd = paste(cmd,'--debbuildopts','-sd')
125         notice('build should exclude original source')
126     }
127     ret = log_system(cmd)
128     setwd(wd)
129     if (ret != 0) {
130         fail('Failed to build package.')
131     }
132 }
133