]> git.donarmstrong.com Git - cran2deb.git/blob - pkg/trunk/R/build.R
misc fixes: update database fully rather than just licenses, initialise a variable...
[cran2deb.git] / pkg / trunk / R / build.R
1
2 build <- function(name,extra_deps) {
3     log_clear()
4     dir <- setup()
5     version <- new_build_version(name)
6     result <- try((function() {
7         # see if it has already been built
8         srcname <- pkgname_as_debian(name,binary=F)
9         debname <- pkgname_as_debian(name,binary=T)
10         if (file.exists(changesfile(srcname, version))) {
11             notice('already built',srcname,'version',version)
12             return(NA)
13         }
14         # XXX: what about building newer versions?
15         if (debname %in% debian_pkgs) {
16             notice(srcname,' exists in Debian (perhaps a different version)')
17             return(NA)
18         }
19
20         rm(debname,srcname)
21
22         pkg <- prepare_new_debian(prepare_pkg(dir,name),extra_deps)
23         # delete the current archive (XXX: assumes mini-dinstall)
24         for (subdir in c('mini-dinstall','unstable')) {
25             path = file.path(dinstall_archive,subdir)
26             if (file.exists(path)) {
27                 unlink(path,recursive=T)
28             }
29         }
30
31         # delete notes of upload
32         file.remove(Sys.glob(file.path(pbuilder_results,'*.upload')))
33
34         # make mini-dinstall generate the skeleton of the archive
35         ret = system(paste('umask 022;mini-dinstall --batch -c',dinstall_config))
36         if (ret != 0) {
37             fail('failed to create archive')
38         }
39
40         # pull in all the R dependencies
41         notice('dependencies:',paste(pkg$depends$r,collapse=', '))
42         for (dep in pkg$depends$r) {
43             if (pkgname_as_debian(dep) %in% debian_pkgs) {
44                 notice('using Debian package of',dep)
45                 next
46             }
47             # otherwise, convert to source package name
48             srcdep = pkgname_as_debian(dep,binary=F)
49
50             notice('uploading',srcdep)
51             ret = system(paste('umask 022;dput','-c',shQuote(dput_config),'local'
52                         ,changesfile(srcdep)))
53             if (ret != 0) {
54                 fail('upload of dependency failed! maybe you did not build it first?')
55             }
56         }
57         build_debian(pkg)
58
59         # upload the package
60         ret = system(paste('umask 022;dput','-c',shQuote(dput_config),'local'
61                     ,changesfile(pkg$srcname,pkg$debversion)))
62         if (ret != 0) {
63             fail('upload failed!')
64         }
65
66         return(pkg$debversion)
67     })())
68     cleanup(dir)
69     if (is.na(result)) {
70         # nothing was done so escape asap.
71         return(result)
72     }
73     # otherwise record progress
74     failed = inherits(result,'try-error')
75     if (failed) {
76         error('failure of',name,'means these packages will fail:'
77                      ,paste(r_dependency_closure(name,forward_arcs=F),collapse=', '))
78     }
79     db_record_build(name, version, log_retrieve(), !failed)
80     return(!failed)
81 }
82
83 build_debian <- function(pkg) {
84     wd <- getwd()
85     setwd(pkg$path)
86     notice('building Debian package'
87                  ,pkg$debname
88                  ,paste('(',pkg$debversion,')',sep='')
89                  ,'...')
90
91     cmd = paste('pdebuild --configfile',shQuote(pbuilder_config))
92     if (version_revision(pkg$debversion) > 2) {
93         cmd = paste(cmd,'--debbuildopts','-sd')
94     }
95     ret = system(cmd)
96     setwd(wd)
97     if (ret != 0) {
98         fail('Failed to build package.')
99     }
100 }
101