Skip to content

Commit

Permalink
(min_isolatd): enforce Rcpp min version and select min version duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Jul 10, 2023
1 parent 11188af commit c670bf4
Showing 1 changed file with 66 additions and 36 deletions.
102 changes: 66 additions & 36 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,69 @@ solve_ip.deps_installation_proposal <- function(ip) {
resolve_ignoring_release_remote(ip)
}

#' For each direct dependency, resolve that package using PPM snapshot as of release date + 1.
#' Finally, combine resolutions and run solve.
#' Resolve the dependencies of package based on the release data + 1
#'
#' @keywords internal
#' @importFrom pkgcache ppm_repo_url
#' @importFrom pkgdepends new_pkg_deps parse_pkg_ref
resolve_ppm_snapshot <- function(i_pkg, i_op, i_op_ver, i_ref_str) {

i_ref <- pkgdepends::parse_pkg_ref(i_ref_str)

i_ref_minver <- get_ref_min_incl_cran(i_ref, i_op, i_op_ver)

i_release_date <- get_release_date(i_ref_minver)

if (is.na(i_release_date)) {
ppm_repo <- file.path(pkgcache::ppm_repo_url(), "latest")
} else {
ppm_repo <- parse_ppm_url(get_ppm_snapshot_by_date(i_release_date))
}

i_pkg_deps <- pkgdepends::new_pkg_deps(
if (inherits(i_ref_minver, "remote_ref_github")) i_ref_minver$ref else i_ref$ref,
config = list(dependencies = "hard", cran_mirror = ppm_repo)
)
suppressMessages(i_pkg_deps$resolve())

i_res <- i_pkg_deps$get_resolution()
i_res$direct <- i_res$directpkg <- FALSE
i_res$parent <- i_pkg
i_res
}

#' Enforce a minimum version of Rcpp (>=1.0.0) for R version above 4.0.0
#' A change in base R on 4.0.0 makes Rcpp incompatible in previous versions
#' @keywords internal
enforce_rcpp <- function(pkg_resolution) {
rcpp_index <- pkg_resolution$package == "Rcpp"
if (!any(rcpp_index)) return(NULL)

version_lt_1 <- as.numeric_version(pkg_resolution$version) < as.numeric_version("1") &
rcpp_index

if (NROW(pkg_resolution[version_lt_1,]) == 0) return(NULL)

if (as.numeric_version(R.version$major) < as.numeric_version("4")) {
return(NULL)
}

# Resolve for Rcpp_1.0.0 to replace entries that don't comply with this
# hard requirement
rcpp_res <- resolve_ppm_snapshot("Rcpp", "==", "1.0.0", "Rcpp")
pkg_resolution[version_lt_1,] <- rcpp_res

pkg_resolution
}

#' For each direct dependency, resolve that package using PPM snapshot as of release date + 1.
#' Finally, combine resolutions and run solve.
#' @keywords internal
#' @exportS3Method solve_ip min_isolated_deps_installation_proposal
solve_ip.min_isolated_deps_installation_proposal <- function(ip) { # nolint
ip$resolve()
res <- ip$get_resolution()
res$parent <- NA_character_

deps <- res[1, "deps"][[1]]
## copy op and version to Config\Needs\verdepcheck rows
Expand All @@ -137,46 +191,22 @@ solve_ip.min_isolated_deps_installation_proposal <- function(ip) { # nolint

cli_pb_init("min_isolated", total = nrow(deps))

deps_res <- lapply(
seq_len(nrow(deps)),
function(i) {
i_pkg <- deps[i, "package"]

cli_pb_update(package = i_pkg, n = 4L)

if (i_pkg %in% base_pkgs()) {
return(NULL)
}
deps_res <- lapply(seq_len(nrow(deps)), function(i) {
i_pkg <- deps[i, "package"]

i_op <- deps[i, "op"]
i_op_ver <- deps[i, "version"]
cli_pb_update(package = i_pkg, n = 4L)

i_ref_str <- deps[i, "ref"]
i_ref <- pkgdepends::parse_pkg_ref(i_ref_str)

i_ref_minver <- get_ref_min_incl_cran(i_ref, i_op, i_op_ver)

i_release_date <- get_release_date(i_ref_minver)

if (is.na(i_release_date)) {
ppm_repo <- file.path(pkgcache::ppm_repo_url(), "latest")
} else {
ppm_repo <- parse_ppm_url(get_ppm_snapshot_by_date(i_release_date))
}

i_pkg_deps <- pkgdepends::new_pkg_deps(
if (inherits(i_ref_minver, "remote_ref_github")) i_ref_minver$ref else i_ref$ref,
config = list(dependencies = "hard", cran_mirror = ppm_repo)
)
suppressMessages(i_pkg_deps$resolve())
i_res <- i_pkg_deps$get_resolution()
i_res$direct <- i_res$directpkg <- FALSE
i_res
if (i_pkg %in% base_pkgs()) {
return(NULL)
}
)

resolve_ppm_snapshot(i_pkg, deps[i, "op"], deps[i, "version"], deps[i, "ref"])
})

new_res <- rbind(res[1, ], do.call(rbind, deps_res))
new_res <- new_res[order(as.numeric_version(new_res$version)),]
new_res <- new_res[!duplicated(new_res), ]
new_res <- enforce_rcpp(new_res)

ip$.__enclos_env__$private$plan$.__enclos_env__$private$resolution$result <- new_res
ip$solve()
Expand Down

0 comments on commit c670bf4

Please sign in to comment.