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
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)
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.')
19 # if rver contains a : then the Debian version must also have a colon
20 if (debian_epoch == 0 && length(grep(':',pkgver)))
23 # if the epoch is non-zero then include it
24 if (debian_epoch != 0)
25 pkgver = paste(debian_epoch,':',pkgver,sep='')
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,'-',debian_revision,sep=''))
32 version_epoch <- function(pkgver) {
33 # return the Debian epoch of a Debian package version
34 if (!length(grep(':',pkgver)))
36 return(as.integer(sub('^([0-9]+):.*','\\1',pkgver)))
38 # version_epoch . version_new(x,y) = id
39 # version_epoch(version_new(x,y)) = base_epoch
41 version_revision <- function(pkgver) {
42 # return the Debian revision of a Debian package version
43 return(as.integer(sub('.*-([0-9]+)$','\\1',pkgver)))
45 # version_revision . version_new(x) = id
46 # version_revision(version_new(x)) = 1
48 version_upstream <- function(pkgver) {
49 # return the upstream version of a Debian package version
50 return(sub('-[0-9]+$','',sub('^[0-9]+:','',pkgver)))
52 # version_upstream . version_new = id
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
63 return(version_new(rver
64 ,debian_revision = version_revision(prev_pkgver)+inc
65 ,debian_epoch = version_epoch(prev_pkgver)
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)
76 new_build_version <- function(pkgname) {
77 if (!(pkgname %in% rownames(available))) {
78 bundle <- r_bundle_of(pkgname)
79 if (is.null(bundle)) {
80 fail('tried to discover new version of',pkgname,'but it does not appear to be available')
84 db_ver <- db_latest_build_version(pkgname)
85 db_succ <- db_latest_build_status(pkgname)[[1]]
86 latest_r_ver <- available[pkgname,'Version']
87 if (!is.null(db_ver)) {
88 return(version_update(latest_r_ver, db_ver, db_succ))
90 return(version_new(latest_r_ver))