|
159 | 159 | return("") |
160 | 160 | } |
161 | 161 |
|
| 162 | +.defaultBuildsFile <- function(tgt, force=FALSE) { |
| 163 | + pkgdir <- tools::R_user_dir(packageName()) # ~/.local/share/R/ + package |
| 164 | + if (dir.exists(pkgdir)) { |
| 165 | + fname <- file.path(pkgdir, paste0("builds.", tgt, ".rds")) |
| 166 | + if (file.exists(fname) || force) { |
| 167 | + return(fname) |
| 168 | + } |
| 169 | + } else { |
| 170 | + .debug_message("No builds file for ", tgt, "\n") |
| 171 | + } |
| 172 | + return("") |
| 173 | +} |
| 174 | + |
162 | 175 |
|
163 | 176 | .loadConfig <- function() { |
164 | 177 | if (is.na(match("config_file", names(.pkgenv)))) { |
|
369 | 382 | file.exists(tfile) |
370 | 383 | } |
371 | 384 |
|
372 | | -.allBuilds <- function(tgt, pltfrm) { |
| 385 | +## The caching layer helps with the build matrix and avoids a possible (if rare) error |
| 386 | +## when downloading it in each build run |
| 387 | +.allBuilds <- function(tgt, hrs = .pkgenv[["cache_age_hours_cran_db"]]) { |
373 | 388 | if (missing(tgt)) tgt <- .pkgenv[["distribution_name"]] |
374 | 389 | if (missing(pltfrm)) pltfrm <- .platform() |
375 | | - tfile <- tempfile(fileext=".rds") |
376 | | - url <- file.path("https://r2u.stat.illinois.edu/ubuntu/pool/dists", tgt, "main/builds.rds") |
377 | | - .retrying.downloader(url, tfile) |
378 | | - B <- readRDS(tfile) |
379 | | - unlink(tfile) |
| 390 | + B <- NULL |
| 391 | + bfile <- .defaultBuildsFile(tgt) |
| 392 | + if (file.exists(bfile) && !is.null(hrs)) { |
| 393 | + age <- as.numeric(difftime(Sys.time(), file.info(bfile)$ctime, units="hours")) |
| 394 | + if (age < hrs) { |
| 395 | + B <- readRDS(bfile) |
| 396 | + .debug_message("Cached all builds\n") |
| 397 | + } |
| 398 | + } |
| 399 | + if (is.null(B)) { |
| 400 | + .debug_message("Fresh builds file for ", tgt, "\n") |
| 401 | + url <- file.path("https://r2u.stat.illinois.edu/ubuntu/pool/dists", tgt, "main/builds.rds") |
| 402 | + bfile <- .defaultBuildsFile(tgt, force=TRUE) |
| 403 | + download.file(url, bfile, quiet=TRUE) |
| 404 | + B <- readRDS(bfile) |
| 405 | + .debug_message("Fresh all builds\n") |
| 406 | + } |
380 | 407 | B <- B[arch %in% c("all", pltfrm), ] |
381 | 408 | B |
382 | 409 | } |
383 | 410 |
|
384 | | -.loadBuilds <- function(tgt, pltfrm) { |
| 411 | +.loadBuilds <- function(tgt, pltfrm, force=TRUE) { |
385 | 412 | if (missing(tgt)) tgt <- .pkgenv[["distribution_name"]] |
386 | 413 | if (missing(pltfrm)) pltfrm <- .platform() |
387 | 414 | dd <- file.path(.pkgenv[["deb_directory"]], "dists", tgt, "main") |
388 | 415 | if (isFALSE(.pkgenv[["in_docker"]]) && isTRUE(nzchar(dd)) && dir.exists(dd)) { ## this is specific to local build with the local pool of builds |
389 | 416 | ## cannot read builds.rds which only exists for noble |
| 417 | + .debug_message("Read build files\n") |
390 | 418 | cwd <- getwd() |
391 | 419 | setwd(dd) |
392 | 420 | fls <- list.files(".", pattern="\\.deb$", full.names=FALSE) |
|
398 | 426 | B <- B[arch %in% c("all", pltfrm), ] |
399 | 427 | .pkgenv[["builds"]] <- B |
400 | 428 | setwd(cwd) |
401 | | - } else if (nzchar(Sys.getenv("CI", ""))) { ## this is specific to the arm64 build at GH |
| 429 | + } else if (nzchar(Sys.getenv("CI", "")) && isTRUE(force)) { # this is specific to the builds at GH |
402 | 430 | ## get packages already Built |
403 | 431 | #B <- data.table::fread(cmd=r"(links -dump https://r2u.stat.illinois.edu/ubuntu/pool/dists/noble/main/| awk '/r-.*arm64.deb/ { print $1 "," $2 " "$3 "," $4 }')", col.names=c("file","date","size")) |
404 | 432 | #B[, version := gsub(".*_(.*)_arm64.deb", "\\1", file), by=file] |
405 | 433 | #B[, r2u := grepl("ca2404", version), by=file] # needed ? |
406 | 434 | #B[, ver := gsub("(.*)-(\\d\\.ca\\d{4}\\.\\d)$", "\\1", version)][] # upstream |
407 | 435 | #B[, pkgver := gsub("(.*)-(\\d\\.ca\\d{4}\\.\\d)_(arm64|amd64|all).deb$", "\\1", file)] |
| 436 | + .debug_message("Fetching builds.rds\n") |
408 | 437 | B <- .allBuilds(tgt) |
409 | 438 | B <- B[arch == pltfrm, ] |
410 | 439 | .pkgenv[["builds"]] <- B |
|
474 | 503 | repos = c(CRAN="https://cran.r-project.org")) # instead of cloud.r-p.o |
475 | 504 | } |
476 | 505 |
|
| 506 | +## execute when r2u functions executed via :: or ::: |
477 | 507 | .onLoad <- function(libname, pkgname) { |
478 | 508 | .setOptions() |
479 | 509 | .loadConfig() |
480 | 510 | .checkSystem() |
481 | 511 | .loadDB() |
482 | 512 | .loadAP() |
483 | | - .loadBuilds() |
| 513 | + .loadBuilds(force=FALSE) |
484 | 514 | .loadBuildDepends() |
485 | 515 | .loadBlacklist() |
486 | 516 | .loadRuntimedepends() |
487 | 517 | } |
488 | 518 |
|
| 519 | +## executed when library(r2u) is called |
489 | 520 | .onAttach <- function(libname, pkgname) { |
490 | 521 | .setOptions() |
491 | 522 | .loadConfig() |
492 | 523 | .checkSystem() |
493 | 524 | .loadDB() |
494 | 525 | .loadAP() |
495 | | - .loadBuilds() |
| 526 | + .loadBuilds(force=FALSE) |
496 | 527 | .loadBuildDepends() |
497 | 528 | .loadBlacklist() |
498 | 529 | .loadRuntimedepends() |
|
0 commit comments