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