]> git.donarmstrong.com Git - cran2deb.git/blob - branch/multisys/R/build.R
multisys: support for multiple os-arch configurations (preliminary)
[cran2deb.git] / branch / multisys / 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         # delete the current archive (XXX: assumes mini-dinstall)
28         for (subdir in c('mini-dinstall','unstable')) {
29             path = file.path(dinstall_archive,subdir)
30             if (file.exists(path)) {
31                 unlink(path,recursive=T)
32             }
33         }
34
35         # delete notes of upload
36         file.remove(Sys.glob(file.path(pbuilder_results,'*.upload')))
37
38         # make mini-dinstall generate the skeleton of the archive
39         ret = log_system('umask 002;mini-dinstall --batch -c',dinstall_config)
40         if (ret != 0) {
41             fail('failed to create archive')
42         }
43
44         # pull in all the R dependencies
45         notice('R dependencies:',paste(pkg$depends$r,collapse=', '))
46         for (dep in pkg$depends$r) {
47             if (pkgname_as_debian(dep) %in% debian_pkgs) {
48                 notice('using Debian package of',dep)
49                 next
50             }
51             # otherwise, convert to source package name
52             srcdep = pkgname_as_debian(dep,binary=F)
53
54             notice('uploading',srcdep)
55             ret = log_system('umask 002;dput','-c',shQuote(dput_config),'local'
56                         ,changesfile(srcdep))
57             if (ret != 0) {
58                 fail('upload of dependency failed! maybe you did not build it first?')
59             }
60         }
61         build_debian(pkg)
62
63         # upload the package
64         ret = log_system('umask 002;dput','-c',shQuote(dput_config),'local'
65                     ,changesfile(pkg$srcname,pkg$debversion))
66         if (ret != 0) {
67             fail('upload failed!')
68         }
69
70         # delete the current archive (XXX: assumes mini-dinstall)
71         # this is handy for group operation
72         for (subdir in c('mini-dinstall','unstable')) {
73             path = file.path(dinstall_archive,subdir)
74             if (file.exists(path)) {
75                 unlink(path,recursive=T)
76             }
77         }
78
79         return(pkg$debversion)
80     })())
81     cleanup(dir)
82     if (is.null(result)) {
83         # nothing was done so escape asap.
84         return(result)
85     }
86
87     # otherwise record progress
88     failed = inherits(result,'try-error')
89     if (failed) {
90         error('failure of',name,'means these packages will fail:'
91                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', '))
92     }
93     db_record_build(name, version, log_retrieve(), !failed)
94     return(!failed)
95 }
96
97 needs_build <- function(name,version) {
98     # see if the last build was successful
99     build <- db_latest_build(name)
100     if (!is.null(build) && build$success) {
101         # then something must have changed for us to attempt this
102         # build
103         if (build$r_version == version_upstream(version) &&
104             build$deb_epoch == version_epoch(version) &&
105             build$db_version == db_get_version()) {
106             return(F)
107         }
108     } else {
109         # always rebuild on failure or no record
110         return(T)
111     }
112     # see if it has already been built
113     srcname <- pkgname_as_debian(name,binary=F)
114     debname <- pkgname_as_debian(name,binary=T)
115     if (file.exists(changesfile(srcname, version))) {
116         notice('already built',srcname,'version',version)
117         return(F)
118     }
119
120     # XXX: what about building newer versions of Debian packages?
121     if (debname %in% debian_pkgs) {
122         notice(srcname,' exists in Debian (perhaps a different version)')
123         return(F)
124     }
125
126     rm(debname,srcname)
127     return(T)
128 }
129
130 build_debian <- function(pkg) {
131     wd <- getwd()
132     setwd(pkg$path)
133     notice('building Debian package'
134                  ,pkg$debname
135                  ,paste('(',pkg$debversion,')',sep='')
136                  ,'...')
137
138     cmd = paste('pdebuild --configfile',shQuote(pbuilder_config))
139     if (version_revision(pkg$debversion) > 2) {
140         cmd = paste(cmd,'--debbuildopts','-sd')
141         notice('build should exclude original source')
142     }
143     ret = log_system(cmd)
144     setwd(wd)
145     if (ret != 0) {
146         fail('Failed to build package.')
147     }
148 }
149