diff --git a/NAMESPACE b/NAMESPACE index 045e85d..329c61e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -43,4 +43,5 @@ importFrom(utils,tail) importFrom(withr,local_path) importFrom(withr,with_dir) importFrom(withr,with_envvar) +importFrom(withr,with_libpaths) importFrom(xopen,xopen) diff --git a/NEWS.md b/NEWS.md index fef4bf9..121f54e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ * Update pkgdown template and move url to https://rcmdcheck.r-lib.org. +* Fix usage of `libpath` argument (#195). + * `cran_check_results()` works again. # rcmdcheck 1.4.0 diff --git a/R/build.R b/R/build.R index 5de414d..2e732b0 100644 --- a/R/build.R +++ b/R/build.R @@ -1,5 +1,5 @@ #' @importFrom pkgbuild pkgbuild_process -#' @importFrom withr with_envvar +#' @importFrom withr with_libpaths build_package <- function(path, tmpdir, build_args, libpath, quiet) { path <- normalizePath(path) @@ -15,9 +15,8 @@ build_package <- function(path, tmpdir, build_args, libpath, quiet) { desc <- desc(path) clean_doc <- as_flag(desc$get("Config/build/clean-inst-doc"), NULL) - with_envvar( - c("R_LIBS_USER" = paste(libpath, collapse = .Platform$path.sep)), - { + with_libpaths( + libpath, { proc <- pkgbuild_process$new( path, tmpdir, diff --git a/tests/testthat/dependent_pkgs/pkg1/DESCRIPTION b/tests/testthat/dependent_pkgs/pkg1/DESCRIPTION new file mode 100644 index 0000000..338fd28 --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg1/DESCRIPTION @@ -0,0 +1,10 @@ +Package: pkg1 +Title: What the Package Does (One Line, Title Case) +Version: 0.0.0.9000 +Authors@R: + person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), + comment = c(ORCID = "YOUR-ORCID-ID")) +Description: What the package does (one paragraph). +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.2.3 diff --git a/tests/testthat/dependent_pkgs/pkg1/NAMESPACE b/tests/testthat/dependent_pkgs/pkg1/NAMESPACE new file mode 100644 index 0000000..b4c65a1 --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg1/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(foo1) diff --git a/tests/testthat/dependent_pkgs/pkg1/R/foo1.R b/tests/testthat/dependent_pkgs/pkg1/R/foo1.R new file mode 100644 index 0000000..d75849c --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg1/R/foo1.R @@ -0,0 +1,5 @@ +#' foo1 description +#' +#' foo1 +#' @export +foo1 <- function() {1} \ No newline at end of file diff --git a/tests/testthat/dependent_pkgs/pkg1/man/foo1.Rd b/tests/testthat/dependent_pkgs/pkg1/man/foo1.Rd new file mode 100644 index 0000000..166cff6 --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg1/man/foo1.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/foo1.R +\name{foo1} +\alias{foo1} +\title{foo1 description} +\usage{ +foo1() +} +\description{ +foo1 +} diff --git a/tests/testthat/dependent_pkgs/pkg2/DESCRIPTION b/tests/testthat/dependent_pkgs/pkg2/DESCRIPTION new file mode 100644 index 0000000..2091f3d --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg2/DESCRIPTION @@ -0,0 +1,16 @@ +Package: pkg2 +Title: What the Package Does (One Line, Title Case) +Version: 0.0.0.9000 +Authors@R: + person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), + comment = c(ORCID = "YOUR-ORCID-ID")) +Description: What the package does (one paragraph). +Imports: + pkg1 +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.2.3 +Suggests: + knitr, + rmarkdown +VignetteBuilder: knitr diff --git a/tests/testthat/dependent_pkgs/pkg2/NAMESPACE b/tests/testthat/dependent_pkgs/pkg2/NAMESPACE new file mode 100644 index 0000000..9149b79 --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg2/NAMESPACE @@ -0,0 +1,4 @@ +# Generated by roxygen2: do not edit by hand + +export(foo2) +import(pkg1) diff --git a/tests/testthat/dependent_pkgs/pkg2/R/foo2.R b/tests/testthat/dependent_pkgs/pkg2/R/foo2.R new file mode 100644 index 0000000..27353ff --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg2/R/foo2.R @@ -0,0 +1,6 @@ +#' foo2 description +#' +#' foo2 +#' @import pkg1 +#' @export +foo2 <- function() {2} \ No newline at end of file diff --git a/tests/testthat/dependent_pkgs/pkg2/man/foo2.Rd b/tests/testthat/dependent_pkgs/pkg2/man/foo2.Rd new file mode 100644 index 0000000..ad6a6d1 --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg2/man/foo2.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/foo2.R +\name{foo2} +\alias{foo2} +\title{foo2 description} +\usage{ +foo2() +} +\description{ +foo2 +} diff --git a/tests/testthat/dependent_pkgs/pkg2/vignettes/test.Rmd b/tests/testthat/dependent_pkgs/pkg2/vignettes/test.Rmd new file mode 100644 index 0000000..01719b9 --- /dev/null +++ b/tests/testthat/dependent_pkgs/pkg2/vignettes/test.Rmd @@ -0,0 +1,19 @@ +--- +title: "test" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{test} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(pkg2) +``` diff --git a/tests/testthat/test-build.R b/tests/testthat/test-build.R index a975f68..054158d 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -39,3 +39,21 @@ test_that("inst/doc can be kept", { pkg <- build_package(bad3, tempfile(), character(), .libPaths(), TRUE) expect_true(file.exists(rubbish)) }) + +test_that("libpath argument is used in build_package", { + lib <- tempfile() + on.exit(unlink(lib, recursive = TRUE), add = TRUE) + dir.create(lib) + + pkg1_source <- test_path("dependent_pkgs", "pkg1") + pkg1 <- pkgbuild::build(pkg1_source, quiet = TRUE) + on.exit(unlink(pkg1, recursive = TRUE), add = TRUE) + install.packages(pkg1, lib = lib, repos = NULL, type = "source", quiet = TRUE) + + pkg2_source <- test_path("dependent_pkgs", "pkg2") + expect_error({ + build_package(pkg2_source, tempfile(), character(), .libPaths(), TRUE) + }) + pkg2 <- build_package(pkg2_source, tempfile(), character(), c(lib, .libPaths()), TRUE) + expect_true(file.exists(pkg2)) +})