101 lines
4.6 KiB
R
101 lines
4.6 KiB
R
#' @importFrom gert git_config_set
|
|
#' @importFrom pak local_install_dev_deps
|
|
#' @importFrom pkgbuild build
|
|
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",
|
|
install_system_dependencies = TRUE) {
|
|
codename <- set_codename(codename)
|
|
|
|
if (is.null(r_version_minor)) {
|
|
r_version_minor <- sub("R version (\\d+\\.\\d+).*", "\\1", R.Version()$version.string)
|
|
}
|
|
|
|
# create directory structure
|
|
dir_out_bin <- set_bin_path(r_version_minor, build_for_minor, local_build_root, codename)
|
|
dir_out_src <- sprintf("%s/src/contrib/Archive", local_build_root)
|
|
cli::cli_alert_info("{.fun build_binary_package}: Creating dir {.path {dir_out_bin}}.")
|
|
cli::cli_alert_info("{.fun build_binary_package}: Creating dir {.path {dir_out_src}}.")
|
|
dir.create(sprintf("%s/Archive", dir_out_bin), sprintf("%s/Archive", dir_out_src),
|
|
recursive = TRUE
|
|
)
|
|
|
|
local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag)
|
|
|
|
### 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 tag = NULL, build all tags
|
|
if (is.null(tag)) {
|
|
# when building all tags, we do a full clone to checkout all subsequent tags
|
|
# Using system git here as {gert} does not provide this functionality
|
|
# FIXME:
|
|
# system2("git", args = c("config", "advice.detachedHead", "false"))
|
|
# system2("git", args = c(
|
|
# "clone", sprintf("https://github.com/cran/%s", package_name), sprintf("%s/%s", local_clone_dir, package_name)
|
|
# ))
|
|
} else {
|
|
cli::cli_alert_info("{.fun build_binary_package}: 1. Cloning package {.env {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_binary_package}: 2. Building package {.env {package_name}} with tag {.env {tag}}.")
|
|
|
|
pkgbuild::build(
|
|
path = sprintf("%s", local_clone_dir_single),
|
|
binary = TRUE, vignettes = FALSE,
|
|
dest_path = dir_out_bin
|
|
)
|
|
|
|
if (!file.exists(sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag))) {
|
|
cli::cli_alert_info('{.fun build_binary_package}: 3. Moving package from {.path {sprintf("%s/%s*.tar.gz", dir_out_bin, package_name)}} to {.path {sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag)}}')
|
|
# remove _aarch64-unknown-linux-gnu part in filename
|
|
system2("rsync", args = c(
|
|
sprintf("%s/%s_%s*.tar.gz", dir_out_bin, package_name, tag),
|
|
sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag)
|
|
))
|
|
} else {
|
|
cli::cli_alert_warning('{.fun build_binary_package}: Binary {sprintf("%s_%s.tar.gz", package_name, tag)} already exists. Skipping copy.')
|
|
}
|
|
unlink(sprintf("%s/%s_%s_R*.tar.gz", dir_out_bin, package_name, tag))
|
|
|
|
cli::cli_alert_info("{.fun build_binary_package}: 4. Removing {.path {local_clone_dir_single}}.")
|
|
unlink(local_clone_dir_single, force = TRUE, recursive = 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}}.")
|
|
|
|
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
|
|
))
|
|
}
|
|
|
|
Sys.setenv(PKG_SYSREQS_PLATFORM = pak_pkg_syrsreqs_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)
|
|
}
|
|
}
|