2015-06-12 01:39:48 +01:00
|
|
|
#!/usr/bin/env Rscript
|
2014-11-21 13:23:36 +00:00
|
|
|
library(data.table)
|
|
|
|
library(parallel)
|
2021-09-15 02:09:17 +01:00
|
|
|
library(BiocManager)
|
2014-11-21 13:23:36 +00:00
|
|
|
cl <- makeCluster(10)
|
|
|
|
|
2021-09-15 02:09:17 +01:00
|
|
|
biocVersion <- BiocManager:::.version_map()
|
|
|
|
biocVersion <- biocVersion[biocVersion$R == getRversion()[, 1:2],c("Bioc", "BiocStatus")]
|
|
|
|
if ("release" %in% biocVersion$BiocStatus) {
|
|
|
|
biocVersion <- as.numeric(as.character(biocVersion[biocVersion$BiocStatus == "release", "Bioc"]))
|
|
|
|
} else {
|
|
|
|
biocVersion <- max(as.numeric(as.character(biocVersion$Bioc)))
|
|
|
|
}
|
2017-02-15 02:54:55 +00:00
|
|
|
snapshotDate <- Sys.Date()-1
|
2015-02-25 22:43:43 +00:00
|
|
|
|
2018-02-15 05:22:52 +00:00
|
|
|
mirrorUrls <- list( bioc=paste0("http://bioconductor.statistik.tu-dortmund.de/packages/", biocVersion, "/bioc/src/contrib/")
|
|
|
|
, "bioc-annotation"=paste0("http://bioconductor.statistik.tu-dortmund.de/packages/", biocVersion, "/data/annotation/src/contrib/")
|
|
|
|
, "bioc-experiment"=paste0("http://bioconductor.statistik.tu-dortmund.de/packages/", biocVersion, "/data/experiment/src/contrib/")
|
2016-03-23 05:40:47 +00:00
|
|
|
, cran=paste0("http://mran.revolutionanalytics.com/snapshot/", snapshotDate, "/src/contrib/")
|
2015-06-16 11:58:58 +01:00
|
|
|
)
|
2016-03-23 05:40:47 +00:00
|
|
|
|
|
|
|
mirrorType <- commandArgs(trailingOnly=TRUE)[1]
|
|
|
|
stopifnot(mirrorType %in% names(mirrorUrls))
|
|
|
|
packagesFile <- paste(mirrorType, 'packages.nix', sep='-')
|
|
|
|
readFormatted <- as.data.table(read.table(skip=8, sep='"', text=head(readLines(packagesFile), -1)))
|
|
|
|
|
|
|
|
write(paste("downloading package lists"), stderr())
|
2015-11-24 13:59:04 +00:00
|
|
|
knownPackages <- lapply(mirrorUrls, function(url) as.data.table(available.packages(url, filters=c("R_version", "OS_type", "duplicates")), method="libcurl"))
|
2015-06-16 11:58:58 +01:00
|
|
|
pkgs <- knownPackages[mirrorType][[1]]
|
|
|
|
setkey(pkgs, Package)
|
|
|
|
knownPackages <- c(unique(do.call("rbind", knownPackages)$Package))
|
|
|
|
knownPackages <- sapply(knownPackages, gsub, pattern=".", replacement="_", fixed=TRUE)
|
|
|
|
|
2016-03-23 05:40:47 +00:00
|
|
|
mirrorUrl <- mirrorUrls[mirrorType][[1]]
|
2014-11-21 13:23:36 +00:00
|
|
|
nixPrefetch <- function(name, version) {
|
2015-02-25 22:43:43 +00:00
|
|
|
prevV <- readFormatted$V2 == name & readFormatted$V4 == version
|
2016-03-23 05:40:47 +00:00
|
|
|
if (sum(prevV) == 1)
|
|
|
|
as.character(readFormatted$V6[ prevV ])
|
|
|
|
|
|
|
|
else {
|
|
|
|
# avoid nix-prefetch-url because it often fails to fetch/hash large files
|
|
|
|
url <- paste0(mirrorUrl, name, "_", version, ".tar.gz")
|
|
|
|
tmp <- tempfile(pattern=paste0(name, "_", version), fileext=".tar.gz")
|
|
|
|
cmd <- paste0("wget -q -O '", tmp, "' '", url, "'")
|
|
|
|
cmd <- paste0(cmd, " && nix-hash --type sha256 --base32 --flat '", tmp, "'")
|
|
|
|
cmd <- paste0(cmd, " && echo >&2 ' added ", name, " v", version, "'")
|
|
|
|
cmd <- paste0(cmd, " ; rm -rf '", tmp, "'")
|
|
|
|
system(cmd, intern=TRUE)
|
|
|
|
}
|
|
|
|
|
2014-11-21 13:23:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-02 22:20:29 +00:00
|
|
|
escapeName <- function(name) {
|
|
|
|
switch(name, "import" = "r_import", "assert" = "r_assert", name)
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:58:58 +01:00
|
|
|
formatPackage <- function(name, version, sha256, depends, imports, linkingTo) {
|
2021-06-25 03:33:54 +01:00
|
|
|
attr <- gsub(".", "_", escapeName(name), fixed=TRUE)
|
2017-02-15 02:54:55 +00:00
|
|
|
options(warn=5)
|
2015-06-16 11:58:58 +01:00
|
|
|
depends <- paste( if (is.na(depends)) "" else gsub("[ \t\n]+", "", depends)
|
|
|
|
, if (is.na(imports)) "" else gsub("[ \t\n]+", "", imports)
|
|
|
|
, if (is.na(linkingTo)) "" else gsub("[ \t\n]+", "", linkingTo)
|
|
|
|
, sep=","
|
|
|
|
)
|
|
|
|
depends <- unlist(strsplit(depends, split=",", fixed=TRUE))
|
2017-02-15 02:54:55 +00:00
|
|
|
depends <- lapply(depends, gsub, pattern="([^ \t\n(]+).*", replacement="\\1")
|
|
|
|
depends <- lapply(depends, gsub, pattern=".", replacement="_", fixed=TRUE)
|
2015-06-16 11:58:58 +01:00
|
|
|
depends <- depends[depends %in% knownPackages]
|
2021-01-02 22:20:29 +00:00
|
|
|
depends <- lapply(depends, escapeName)
|
2017-02-15 02:54:55 +00:00
|
|
|
depends <- paste(depends)
|
2015-06-16 11:58:58 +01:00
|
|
|
depends <- paste(sort(unique(depends)), collapse=" ")
|
2015-11-24 13:59:04 +00:00
|
|
|
paste0(" ", attr, " = derive2 { name=\"", name, "\"; version=\"", version, "\"; sha256=\"", sha256, "\"; depends=[", depends, "]; };")
|
2014-11-21 13:23:36 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 11:58:58 +01:00
|
|
|
clusterExport(cl, c("nixPrefetch","readFormatted", "mirrorUrl", "knownPackages"))
|
2014-11-21 13:23:36 +00:00
|
|
|
|
2015-11-24 13:59:04 +00:00
|
|
|
pkgs <- as.data.table(available.packages(mirrorUrl, filters=c("R_version", "OS_type", "duplicates"), method="libcurl"))
|
2014-11-21 13:23:36 +00:00
|
|
|
pkgs <- pkgs[order(Package)]
|
|
|
|
|
2016-03-23 05:40:47 +00:00
|
|
|
write(paste("updating", mirrorType, "packages"), stderr())
|
|
|
|
pkgs$sha256 <- parApply(cl, pkgs, 1, function(p) nixPrefetch(p[1], p[2]))
|
2015-06-16 11:58:58 +01:00
|
|
|
nix <- apply(pkgs, 1, function(p) formatPackage(p[1], p[2], p[18], p[4], p[5], p[6]))
|
2016-03-23 05:40:47 +00:00
|
|
|
write("done", stderr())
|
2014-11-21 13:23:36 +00:00
|
|
|
|
2021-09-24 12:17:37 +01:00
|
|
|
# Mark deleted packages as broken
|
|
|
|
setkey(readFormatted, V2)
|
|
|
|
markBroken <- function(name) {
|
|
|
|
str <- paste0(readFormatted[name], collapse='"')
|
|
|
|
if(sum(grep("broken = true;", str)))
|
|
|
|
return(str)
|
|
|
|
write(paste("marked", name, "as broken"), stderr())
|
|
|
|
gsub("};$", "broken = true; };", str)
|
|
|
|
}
|
|
|
|
broken <- lapply(setdiff(readFormatted[[2]], pkgs[[1]]), markBroken)
|
|
|
|
|
2015-05-23 01:51:24 +01:00
|
|
|
cat("# This file is generated from generate-r-packages.R. DO NOT EDIT.\n")
|
2014-11-21 13:23:36 +00:00
|
|
|
cat("# Execute the following command to update the file.\n")
|
|
|
|
cat("#\n")
|
2015-06-16 11:58:58 +01:00
|
|
|
cat(paste("# Rscript generate-r-packages.R", mirrorType, ">new && mv new", packagesFile))
|
2015-05-23 01:51:24 +01:00
|
|
|
cat("\n\n")
|
2015-11-24 13:59:04 +00:00
|
|
|
cat("{ self, derive }:\n")
|
|
|
|
cat("let derive2 = derive ")
|
2016-03-23 05:40:47 +00:00
|
|
|
if (mirrorType == "cran") { cat("{ snapshot = \"", paste(snapshotDate), "\"; }", sep="")
|
|
|
|
} else if (mirrorType == "irkernel") { cat("{}")
|
2018-02-15 05:22:52 +00:00
|
|
|
} else { cat("{ biocVersion = \"", biocVersion, "\"; }", sep="") }
|
2015-11-24 13:59:04 +00:00
|
|
|
cat(";\n")
|
|
|
|
cat("in with self; {\n")
|
|
|
|
cat(paste(nix, collapse="\n"), "\n", sep="")
|
2021-09-24 12:17:37 +01:00
|
|
|
cat(paste(broken, collapse="\n"), "\n", sep="")
|
2014-11-21 13:23:36 +00:00
|
|
|
cat("}\n")
|
|
|
|
|
|
|
|
stopCluster(cl)
|