diff --git a/R/build_binaries.R b/R/build_binaries.R index 1d81d14..dc3e4be 100644 --- a/R/build_binaries.R +++ b/R/build_binaries.R @@ -76,21 +76,6 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL, package_name <- rep(package_name, length(tag)) } - ### Install system dependencies - if (install_system_dependencies) { - tryCatch( - { - install_package_system_dependencies(package_name, tag, platform, local_clone_dir, deps_verbose) - }, - # NB: here we need to use conditionMessage() to extract the actual error - as opposed to using $stderr for errors within the tryCatch used in the future* calls - error = function(e) { - cli::cli_alert_warning("Error in installing dependencies for package {.pkg {package_name[1]}} with tag {.field {tag[1]}}: {e}") - store_build_metadata(package_name[1], tag[1], platform, error_occurred = TRUE, force = TRUE, error = conditionMessage(e)) - return(TRUE) - } - ) - } - t1 <- Sys.time() cli::cli_h2("Building ({.pkg {package_name[1]}})") @@ -106,7 +91,11 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL, tryCatch( { # p() - dump <- build_single_tag(x, y, dir_out_bin, local_clone_dir, platform = platform, debug = debug, force = force) + dump <- build_single_tag(x, y, dir_out_bin, local_clone_dir, + platform = platform, debug = debug, force = force, + install_system_dependencies = install_system_dependencies, + deps_verbose = deps_verbose + ) # if for some reason an underlying error didnt' get caught in the tryCatch calls, we check again here for the existence of the binary file on disk and mark the build as failed if it is not found tarball_name <- sprintf("%s_%s.tar.gz", x, y) @@ -164,7 +153,9 @@ build_single_tag <- function( dir_out_bin, local_clone_dir, debug = FALSE, - force = FALSE) { + force = FALSE, + install_system_dependencies = TRUE, + deps_verbose = FALSE) { cli::cli_alert("{.fun build_single_tag}: (1/3) Cloning package {.pkg {package_name}} with tag {.field {tag}}.") local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag) @@ -175,6 +166,21 @@ build_single_tag <- function( sprintf("https://github.com/cran/%s", package_name), local_clone_dir_single )) + ### Install system dependencies + if (install_system_dependencies) { + tryCatch( + { + install_package_system_dependencies(package_name, tag, platform, local_clone_dir_single, deps_verbose) + }, + # NB: here we need to use conditionMessage() to extract the actual error - as opposed to using $stderr for errors within the tryCatch used in the future* calls + error = function(e) { + cli::cli_alert_warning("Error in installing dependencies for package {.pkg {package_name[1]}} with tag {.field {tag[1]}}: {e}") + store_build_metadata(package_name[1], tag[1], platform, error_occurred = TRUE, force = TRUE, error = conditionMessage(e)) + return(TRUE) + } + ) + } + if (file.exists(sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag))) { cli::cli_alert("{.fun build_single_tag}: (2/3) Tarball for package {.pkg {package_name}} with tag {.field {tag}} already exists. Skipping build.") } else { @@ -188,17 +194,24 @@ build_single_tag <- function( t1 <- Sys.time() tryCatch( { - dump <- pkgbuild::build( + if (debug) { + message(sprintf("DEBUG1: Printing 'dir_out_bin': %s", dir_out_bin)) + } + pkgbuild::build( path = sprintf("%s", local_clone_dir_single), binary = TRUE, vignettes = FALSE, dest_path = dir_out_bin, quiet = quiet ) + if (debug) { + message(sprintf("DEBUG: Listing dir 'dir_out_bin': %s", dir_out_bin)) + print(fs::dir_ls(dir_out_bin)) + } }, error = function(e) { cli::cli_alert_warning("Error in starting build command for package {.pkg {package_name}} with tag {.field {tag}}: {e}") local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag) unlink(local_clone_dir_single, force = TRUE, recursive = TRUE) - store_build_metadata(package_name, tag, platform, error_occurred = TRUE, force = TRUE, error = "Error trying to initiate pkgbuild - likely a non-valid R package structure") + store_build_metadata(package_name, tag, platform, error_occurred = TRUE, force = TRUE, error = sprintf("Error trying to initiate pkgbuild - likely a non-valid R package structure. Full error: %s", e)) return(invisible(TRUE)) } ) @@ -220,7 +233,7 @@ build_single_tag <- function( if (!file.exists(sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag))) { if (debug) { - cli::cli_alert_info('{.fun build_single_tag}: Moving package from {.path {sprintf("%s/%s_%s_R_%s-%s-linux-%s.tar.gz", dir_out_bin, package_name, tag, arch, whatever_id, linux_suffix)}} to {.path {sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag)}}') + cli::cli_alert_info('{.fun build_single_tag}: DEBUG: Moving package from {.path {sprintf("%s/%s_%s_R_%s-%s-linux-%s.tar.gz", dir_out_bin, package_name, tag, arch, whatever_id, linux_suffix)}} to {.path {sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag)}}') } # double-check that file exists (some packages like https://github.com/cran/BACCO/tree/1.0-14 don't include R/ and hence don't procude a valid binary) if (fs::file_exists(sprintf("%s/%s_%s_R_%s-%s-linux-%s.tar.gz", dir_out_bin, package_name, tag, arch, whatever_id, linux_suffix))) { @@ -231,6 +244,10 @@ build_single_tag <- function( ) } else { cli::cli_alert_info('{.fun build_single_tag}: File for package {.pkg {package_name}} {.field {tag}} at {.path {sprintf("%s/%s_%s_R_%s-%s-linux-%s.tar.gz", dir_out_bin, package_name, tag, arch, whatever_id, linux_suffix)}} does not exist - skipping.') + if (debug) { + message(sprintf("DEBUG: Listing dir 'dir_out_bin': %s", dir_out_bin)) + message(fs::dir_ls(dir_out_bin)) + } } } else { cli::cli_alert_warning('{.fun build_single_tag}: Binary {sprintf("%s_%s.tar.gz", package_name, tag)} already exists. Skipping copy.')