]> git.donarmstrong.com Git - cran2deb.git/blob - pkg/trunk/exec/build
ctv: make CRAN task view mass building work again. (take 2)
[cran2deb.git] / pkg / trunk / exec / build
1 #!/usr/bin/env r
2 suppressMessages(library(cran2deb))
3
4 go <- function(name,extra_deps) {
5     dir <- setup()
6     pkg <- try((function() {
7         pkg <- prepare.new.debian(prepare.pkg(dir,name),extra_deps)
8         # XXX: what about building newer versions?
9         if (pkg$debname %in% debian_pkgs) {
10             message(paste('N:',pkg$srcname,' exists in Debian (perhaps a different version)'))
11             return(pkg)
12         }
13         if (file.exists(changesfile(pkg$srcname,pkg$debversion))) {
14             message(paste('N: already built',pkg$srcname,'version',pkg$debversion))
15             return(pkg)
16         }
17
18         # delete the current archive (XXX: assumes mini-dinstall)
19         for (subdir in c('mini-dinstall','unstable')) {
20             path = file.path(dinstall_archive,subdir)
21             if (file.exists(path)) {
22                 unlink(path,recursive=T)
23             }
24         }
25
26         # delete notes of upload
27         file.remove(Sys.glob(file.path(pbuilder_results,'*.upload')))
28
29         # make mini-dinstall generate the skeleton of the archive
30         ret = system(paste('umask 022;mini-dinstall --batch -c',dinstall_config))
31         if (ret != 0) {
32             stop('failed to create archive')
33         }
34
35         # pull in all the R dependencies
36         message(paste('N: dependencies:',paste(pkg$depends$r,collapse=', ')))
37         for (dep in pkg$depends$r) {
38             if (pkgname.as.debian(dep) %in% debian_pkgs) {
39                 message(paste('N: using Debian package of',dep))
40                 next
41             }
42             # otherwise, convert to source package name
43             srcdep = pkgname.as.debian(dep,binary=F)
44
45             message(paste('N: uploading',srcdep))
46             ret = system(paste('umask 022;dput','-c',shQuote(dput_config),'local'
47                         ,changesfile(srcdep)))
48             if (ret != 0) {
49                 stop('upload of dependency failed! maybe you did not build it first?')
50             }
51         }
52         build.debian(pkg)
53
54         # upload the package
55         ret = system(paste('umask 022;dput','-c',shQuote(dput_config),'local'
56                     ,changesfile(pkg$srcname,pkg$debversion)))
57         if (ret != 0) {
58             stop('upload failed!')
59         }
60
61         return(pkg)
62     })())
63     cleanup(dir)
64     if (inherits(pkg,'try-error')) {
65         message(paste('E: failure of',name,'means these packages will fail:'
66                      ,paste(r.dependency.closure(name,forward_arcs=F),collapse=', ')))
67         stop(call.=F)
68     }
69     return(pkg)
70 }
71
72 if (exists('argv')) { # check for littler
73     argc <- length(argv)
74     extra_deps = list()
75     extra_deps$deb = c()
76     extra_deps$r = c()
77     opts = c('-D','-R')
78     # first argument is the root --- this is dealt with elsewhere.
79     for (i in 2:argc) {
80         if (!(argv[i] %in% opts)) {
81             if (argc >= i) {
82                 argv <- argv[i:argc]
83             } else {
84                 argv <- list()
85             }
86             argc = argc - i + 1
87             break
88         }
89         if (i == argc) {
90             err('missing argument')
91         }
92         if (argv[i] == '-D') {
93             extra_deps$deb = c(extra_deps$deb,strsplit(chomp(argv[i+1]),',')[[1]])
94         }
95         if (argv[i] == '-R') {
96             extra_deps$r = c(extra_deps$r,strsplit(chomp(argv[i+1]),',')[[1]])
97             extra_deps$deb = c(extra_deps$deb,lapply(extra_deps$r,pkgname.as.debian))
98         }
99     }
100     if (argc == 0) {
101         err('usage: cran2deb [-D extra_dep1,extra_dep2,...] package package ...')
102     }
103     build_order <- r.dependency.closure(c(extra_deps$r,argv))
104     message(paste('N: build order',paste(build_order,collapse=', ')))
105     for (pkg in build_order) {
106         go(pkg,extra_deps)
107     }
108 }