r4pi / pkg_builder

4 stars 1 forks source link

Enhancement proposal: build in parallel #4

Open andresrcs opened 1 year ago

andresrcs commented 1 year ago

Hi, I'm just going to leave my proposal here to document it. If you decide at some point it is worthy to implement, let me know to make a PR.

build_package <- function(pkg) {
    cat(paste("-",pkg, "\n"), file = "../../../../build.log", append = TRUE)
    result <- system2(r_binary, paste("--vanilla CMD INSTALL -l '~/R/r4pi/' --no-multiarch --build", pkg))
    if (result == 0) file.rename(pkg, gsub("pkgsrc", "pkgarchive", pkg))
    return(result)
}

pkgs <- dir(path = "../../../../pkgsrc", full.names = TRUE)

results <- parallel::mclapply(pkgs, build_package, mc.cores = 3) |> unlist()
results <- ifelse(results == 0, FALSE, TRUE)