add sqlite db for metadata build info
This commit is contained in:
parent
de2d7878e3
commit
fe99870a94
1 changed files with 307 additions and 40 deletions
|
|
@ -8,8 +8,9 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL,
|
|||
r_version_minor = NULL, build_for_minor = TRUE,
|
||||
local_build_root = "/root",
|
||||
local_clone_dir = "/tmp",
|
||||
pak_pkg_syrsreqs_platform = "redhat-9",
|
||||
platform = "redhat-9",
|
||||
install_system_dependencies = TRUE) {
|
||||
cli::cli_h2("Preparations")
|
||||
codename <- set_codename(codename)
|
||||
|
||||
if (is.null(r_version_minor)) {
|
||||
|
|
@ -27,11 +28,6 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL,
|
|||
|
||||
cli::cli_h2("Installing system dependencies")
|
||||
|
||||
### Install system dependencies
|
||||
if (install_system_dependencies) {
|
||||
install_package_system_dependencies(package_name, pak_pkg_syrsreqs_platform, tag, local_clone_dir_single)
|
||||
}
|
||||
|
||||
gert::git_config_global_set("advice.detachedHead", "false")
|
||||
|
||||
if (is.null(tag)) {
|
||||
|
|
@ -46,63 +42,103 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL,
|
|||
tag <- all_tags$name
|
||||
package_name <- rep(package_name, length(tag))
|
||||
|
||||
cli::cli_alert_info("Building binaries for {.pkg {package_name[[1]]}} with tags {.env {tag}}.")
|
||||
# if (reset_db_metadata) {
|
||||
# cli::cli_alert_warning("{.fun build_binary_package}: Resetting metadata for {.pkg {package_name}}.")
|
||||
|
||||
# con <- dbConnect(RSQLite::SQLite(), dbname = "metadata_summary.db")
|
||||
# # Remove all entries from the metadata_summary table
|
||||
# dbExecute(con, "DELETE FROM metadata_summary")
|
||||
# }
|
||||
}
|
||||
|
||||
### Install system dependencies
|
||||
if (install_system_dependencies) {
|
||||
install_package_system_dependencies(package_name, tag, platform, local_clone_dir)
|
||||
}
|
||||
|
||||
t1 <- Sys.time()
|
||||
cli::cli_h2("Building")
|
||||
|
||||
cli::cli_alert_info("Building binaries for {.pkg {package_name[[1]]}} with tags {.strong {tag}}.")
|
||||
|
||||
# devtools::install(quiet = TRUE)
|
||||
|
||||
# Set up the progress handler
|
||||
progressr::handlers(global = TRUE)
|
||||
progressr::handlers("cli")
|
||||
|
||||
# cli::cli_alert("{package_name}")
|
||||
# cli::cli_alert("{tag}")
|
||||
progressr::handlers("cli", "debug")
|
||||
|
||||
out <- progressr::with_progress({
|
||||
p <- progressr::progressor(along = tag)
|
||||
future_mapply(function(x, y) {
|
||||
p()
|
||||
build_single_tag(x, y, dir_out_bin, local_clone_dir)
|
||||
tryCatch(
|
||||
{
|
||||
p()
|
||||
build_single_tag(x, y, dir_out_bin, local_clone_dir)
|
||||
store_build_metadata(x, y, platform, FALSE)
|
||||
},
|
||||
error = function(e) {
|
||||
message("Error in processing package ", x, " with tag ", y, ": ")
|
||||
unlink(local_clone_dir_single, force = TRUE, recursive = TRUE)
|
||||
store_build_metadata(x, y, platform, TRUE)
|
||||
}
|
||||
)
|
||||
}, package_name, tag, future.seed = TRUE)
|
||||
})
|
||||
|
||||
# future.apply::future_mapply(build_single_tag,
|
||||
# package_name = package_name, tag = tag,
|
||||
# MoreArgs = list(
|
||||
# dir_out_bin = dir_out_bin,
|
||||
# local_clone_dir = local_clone_dir
|
||||
# ),
|
||||
# future.seed = TRUE
|
||||
# )
|
||||
# round(Sys.time() - t1, 2)}} {units(difftime(Sys.time(), t1))}
|
||||
|
||||
total_build_time <- round(Sys.time() - t1, 2)
|
||||
cli::cli_alert_info("Execution time for {.pkg {package_name[[1]]}} ({length(tag)} tags): {.strong {total_build_time} {units(difftime(Sys.time(), t1))}}.")
|
||||
|
||||
# add average_build_time_per_tag to metadata summary table
|
||||
average_build_time_per_tag <- round(total_build_time / length(tag), 2)
|
||||
con <- dbConnect(RSQLite::SQLite(), dbname = "metadata.db")
|
||||
# Check if the entry exists in the metadata_summary table
|
||||
# Check if a valid entry exists in the metadata_summary table
|
||||
entry <- dbGetQuery(con, paste0(
|
||||
"SELECT average_build_time_per_tag FROM metadata_summary WHERE package_name = '", package_name[[1]],
|
||||
"' AND platform = '", platform, "'"
|
||||
))
|
||||
# If the entry does not exist or is not valid, entry will be NULL or NA
|
||||
entry_exists <- !is.null(entry$average_build_time_per_tag) && !is.na(entry$average_build_time_per_tag)
|
||||
|
||||
# If the entry does not exist, update the average_build_time_per_tag
|
||||
if (!entry_exists) {
|
||||
dbExecute(con, paste0(
|
||||
"UPDATE metadata_summary SET average_build_time_per_tag = ", average_build_time_per_tag,
|
||||
" WHERE package_name = '", package_name[[1]], "' AND platform = '", platform, "'"
|
||||
))
|
||||
}
|
||||
|
||||
cli::cli_alert_info("{.fun build_binary_package}: Building/updating metadata summary for {.pkg {package_name[[1]]}}.")
|
||||
build_metadata_summary(package_name[[1]], platform)
|
||||
|
||||
return(invisible(TRUE))
|
||||
}
|
||||
|
||||
install_package_system_dependencies <- function(package_name,
|
||||
pak_pkg_syrsreqs_platform = "redhat-9",
|
||||
tag,
|
||||
local_clone_dir_single) {
|
||||
cli::cli_alert_info("{.fun install_package_system_dependencies}: Cloning package {.env {package_name}} with tag {.env {tag}}.")
|
||||
platform = "redhat-9",
|
||||
local_clone_dir) {
|
||||
cli::cli_alert_info("{.fun install_package_system_dependencies}: Cloning package {.pkg {package_name[1]}} with tag {.strong {tag}}.")
|
||||
|
||||
local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name[1], tail(tag, 1))
|
||||
|
||||
if (!dir.exists(local_clone_dir_single)) {
|
||||
system2("git", args = c(
|
||||
"clone", "-q", sprintf("--branch=%s", tag),
|
||||
sprintf("https://github.com/cran/%s", package_name), local_clone_dir_single
|
||||
"clone", "-q", sprintf("--branch=%s", tail(tag, 1)),
|
||||
sprintf("https://github.com/cran/%s", package_name[1]), local_clone_dir_single
|
||||
))
|
||||
}
|
||||
|
||||
Sys.setenv(PKG_SYSREQS_PLATFORM = pak_pkg_syrsreqs_platform)
|
||||
Sys.setenv(PKG_SYSREQS_PLATFORM = platform)
|
||||
Sys.setenv(PKG_SYSREQS = TRUE)
|
||||
Sys.setenv(PKG_SYSREQS_VERBOSE = TRUE)
|
||||
pak::local_install_dev_deps(sprintf("%s", local_clone_dir_single))
|
||||
|
||||
cli::cli_alert_info("{.fun install_package_system_dependencies}: 4. Removing {.path {local_clone_dir_single}}.")
|
||||
# delete clone again as we need a full clone of the repo when not only building a single tag
|
||||
if (!is.null(tag)) {
|
||||
unlink(sprintf("%s", local_clone_dir_single), recursive = TRUE, force = TRUE)
|
||||
}
|
||||
|
||||
unlink(sprintf("%s", local_clone_dir_single), recursive = TRUE, force = TRUE)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -111,18 +147,17 @@ install_package_system_dependencies <- function(package_name,
|
|||
build_single_tag <- function(package_name, tag = NULL,
|
||||
dir_out_bin,
|
||||
local_clone_dir) {
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 1. Cloning package {.pkg {package_name}} with tag {.strong {tag}}.")
|
||||
|
||||
local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag)
|
||||
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 1. Cloning package {.pkg {package_name}} with tag {.env {tag}}.")
|
||||
|
||||
# Using system git here as {gert} does not provide this functionality
|
||||
system2("git", args = c(
|
||||
"clone", "-q", sprintf("--branch=%s", tag),
|
||||
sprintf("https://github.com/cran/%s", package_name), local_clone_dir_single
|
||||
))
|
||||
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 2. Building package {.pkg {package_name}} with tag {.env {tag}}.")
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 2. Building package {.pkg {package_name}} with tag {.strong {tag}}.")
|
||||
|
||||
pkgbuild::build(
|
||||
path = sprintf("%s", local_clone_dir_single),
|
||||
|
|
|
|||
Loading…
Reference in a new issue