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