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