]> git.donarmstrong.com Git - cran2deb.git/blob - branch/split_build/R/version.R
rename double_build -> split_build
[cran2deb.git] / branch / split_build / R / version.R
1 version_new <- function(rver,debian_revision=1, debian_epoch=db_get_base_epoch()) {
2     # generate a string representation of the Debian version of an
3     # R version of a package
4     pkgver = rver
5
6     # ``Writing R extensions'' says that the version consists of at least two
7     # non-negative integers, separated by . or -
8     if (!length(grep('^([0-9]+[.-])+[0-9]+$',rver))) {
9         fail('Not a valid R package version',rver)
10     }
11
12     # Debian policy says that an upstream version should start with a digit and
13     # may only contain ASCII alphanumerics and '.+-:~'
14     if (!length(grep('^[0-9][A-Za-z0-9.+:~-]*$',rver))) {
15         fail('R package version',rver
16                   ,'does not obviously translate into a valid Debian version.')
17     }
18
19     # if rver contains a : then the Debian version must also have a colon
20     if (debian_epoch == 0 && length(grep(':',pkgver)))
21         debian_epoch = 1
22
23     # if the epoch is non-zero then include it
24     if (debian_epoch != 0)
25         pkgver = paste(debian_epoch,':',pkgver,sep='')
26
27     # always add the '-1' Debian release; nothing is lost and rarely will R
28     # packages be Debian packages without modification.
29     return(paste(pkgver,'-',version_suffix_step,version_suffix,debian_revision,sep=''))
30 }
31
32 version_epoch <- function(pkgver) {
33     # return the Debian epoch of a Debian package version
34     if (!length(grep(':',pkgver)))
35         return(0)
36     return(as.integer(sub('^([0-9]+):.*$','\\1',pkgver)))
37 }
38 # version_epoch . version_new(x,y) = id
39 # version_epoch(version_new(x,y)) = base_epoch
40
41 version_revision <- function(pkgver) {
42     # return the Debian revision of a Debian package version
43     return(as.integer(sub(paste('.*-([0-9]+',version_suffix,')?([0-9]+)$',sep=''),'\\2',pkgver)))
44 }
45 # version_revision . version_new(x) = id
46 # version_revision(version_new(x)) = 1
47
48 version_upstream <- function(pkgver) {
49     # return the upstream version of a Debian package version
50     return(sub('-[a-zA-Z0-9+.~]+$','',sub('^[0-9]+:','',pkgver)))
51 }
52 # version_upstream . version_new = id
53
54 version_update <- function(rver, prev_pkgver, prev_success) {
55     # return the next debian package version
56     prev_rver <- version_upstream(prev_pkgver)
57     if (prev_rver == rver) {
58         # increment the Debian revision if the previous build was successful
59         inc = 0
60         if (prev_success) {
61             inc = 1
62         }
63         return(version_new(rver
64                           ,debian_revision = version_revision(prev_pkgver)+inc
65                           ,debian_epoch    = version_epoch(prev_pkgver)
66                           ))
67     }
68     # new release
69     # TODO: implement Debian ordering over version and then autoincrement
70     #       Debian epoch when upstream version does not increment.
71     return(version_new(rver
72                       ,debian_epoch = version_epoch(prev_pkgver)
73                       ))
74 }
75
76 new_build_version <- function(pkgname) {
77     if (!(pkgname %in% rownames(available))) {
78         fail('tried to discover new version of',pkgname,'but it does not appear to be available')
79     }
80     db_ver <- db_latest_build_version(pkgname)
81     db_succ <- db_latest_build_status(pkgname)[[1]]
82     latest_r_ver <- available[pkgname,'Version']
83     if (!is.null(db_ver)) {
84         return(version_update(latest_r_ver, db_ver, db_succ))
85     }
86     return(version_new(latest_r_ver))
87 }
88