Skip to content

Commit

Permalink
Update embedded pkgdepends
Browse files Browse the repository at this point in the history
For #669
  • Loading branch information
gaborcsardi committed Aug 1, 2024
1 parent f8971a7 commit 33e2a92
Show file tree
Hide file tree
Showing 16 changed files with 2,236 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/library/pkgdepends/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ Imports: callr (>= 3.3.1), cli (>= 3.6.0), curl, desc (>= 1.4.3),
pkgcache (>= 2.2.0), processx (>= 3.4.2), ps, R6, stats, utils,
zip (>= 2.3.0)
Suggests: asciicast (>= 2.2.0.9000), codetools, covr, debugme, fansi,
fs, glue, htmlwidgets, mockery, pak, pingr (>= 2.0.0),
rmarkdown, rstudioapi, spelling, svglite, testthat (>= 3.2.0),
tibble, webfakes (>= 1.1.5.9000), withr (>= 2.1.1)
fs, gh, gitcreds, glue, htmlwidgets, mockery, pak, pingr (>=
2.0.0), rmarkdown, rstudioapi, spelling, svglite, testthat (>=
3.2.0), tibble, webfakes (>= 1.1.5.9000), withr (>= 2.1.1),
Remotes: r-lib/pkgcache
Config/Needs/builder: gh, pkgsearch, withr (>= 2.1.1)
Config/Needs/coverage: r-lib/asciicast, covr
Config/Needs/website: r-lib/asciicast, pkgdown (>= 2.0.2),
tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.3.1.9000
NeedsCompilation: no
Packaged: 2024-04-23 21:39:51 UTC; gaborcsardi
Packaged: 2024-08-01 16:40:26 UTC; gaborcsardi
Author: Gábor Csárdi [aut, cre],
Posit Software, PBC [cph, fnd]
Maintainer: Gábor Csárdi <[email protected]>
4 changes: 4 additions & 0 deletions src/library/pkgdepends/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export(as_pkg_dependencies)
export(current_config)
export(current_r_platform)
export(default_platforms)
export(ghr)
export(ghrepo)
export(install_package_plan)
export(is_valid_package_name)
export(lib_status)
Expand All @@ -41,6 +43,7 @@ export(new_pkg_installation_plan)
export(new_pkg_installation_proposal)
export(parse_pkg_ref)
export(parse_pkg_refs)
export(pkg_build)
export(pkg_dep_types)
export(pkg_dep_types_hard)
export(pkg_dep_types_soft)
Expand All @@ -50,6 +53,7 @@ export(pkg_installation_plan)
export(pkg_installation_proposal)
export(pkg_name_check)
export(pkg_rx)
export(repo)
export(sysreqs_check_installed)
export(sysreqs_db_list)
export(sysreqs_db_match)
Expand Down
86 changes: 86 additions & 0 deletions src/library/pkgdepends/R/builder.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

#' Create a binary package from an installed package
#'
#' The built package will be in the current working directory.
#'
#' This function is currently experimental.
#'
#' @param pkg Package name.
#' @param library Library path.
#' @param flavor Platform flavor. Defaults to the `PKG_BUILD_FLAVOR`
#' environment variable. If not `NULL` or an empty string, then it is
#' appended to the platform string with a dash.
#' @param build_number An integer number that is added to the file name,
#' after the version number, to be able to have multiple builds for the
#' same package version.
#' @return Path to the built package.
#'
#' @export
#' @keywords internal

pkg_build <- function(pkg, library = .libPaths()[1],
flavor = Sys.getenv("PKG_BUILD_FLAVOR"),
build_number = 1L) {
pkgdir <- file.path(library, pkg)
if (!dir.exists(pkgdir)) {
throw(pkg_error(
"Cannot find package {.pkg {pkg}} in library at {.path {library}}."
))
}
platform <- pkgcache::current_r_platform()
if (nzchar(flavor %||% "")) {
platform <- paste0(platform, "-", flavor)
}
meta <- c(
RemoteBuildPlatform = platform,
GraphicsAPIVersion = pkgcache::get_graphics_api_version(),
InternalsId = pkgcache::get_internals_id()
)
add_metadata(pkgdir, meta)
dsc <- desc::desc(file = pkgdir)
version <- dsc$get_field("Version")
rversion <- get_minor_r_version(getRversion())

sys <- sysname()
if (sys == "windows") {
install_md5_sums(pkg)
fn <- paste0(
pkg, "_", version, "_",
"b", build_number, "_",
"R", rversion,
if (nzchar(flavor %||% "")) paste0("_", flavor),
".zip"
)
zip::zip(fn, pkgdir, mode = "cherry-pick")

} else {
ext <- if (sys == "mac") ".tgz" else ".tar.gz"
fn <- paste0(
pkg, "_", version, "_",
"b", build_number, "_",
"R", rversion, "_",
platform,
ext
)
ffn <- file.path(normalizePath("."), fn)
old <- getwd()
on.exit(setwd(old), add = TRUE)
setwd(dirname(pkgdir))
utils::tar(ffn, pkg, compression = "gzip", compression_level = 9)
}

fn
}

install_md5_sums <- function(pkgdir) {
old <- getwd()
on.exit(setwd(old), add = TRUE)

setwd(pkgdir)
fns <- setdiff(dir(".", recursive = TRUE), "MD5")
md5 <- cli::hash_file_md5(fns)
writeLines(
paste0(md5, " *", fns),
"MD5"
)
}
Loading

0 comments on commit 33e2a92

Please sign in to comment.