From 4485e94e318597948179380d0d0c8417db096a76 Mon Sep 17 00:00:00 2001 From: Pawel Rucki Date: Wed, 15 Feb 2023 14:27:30 +0100 Subject: [PATCH 1/4] use libpath arg during build --- NAMESPACE | 1 + NEWS.md | 4 +++- R/build.R | 6 +++--- .../testthat/dependent_pkgs/pkg1/DESCRIPTION | 10 +++++++++ tests/testthat/dependent_pkgs/pkg1/NAMESPACE | 3 +++ tests/testthat/dependent_pkgs/pkg1/R/foo1.R | 5 +++++ .../testthat/dependent_pkgs/pkg1/man/foo1.Rd | 11 ++++++++++ .../dependent_pkgs/pkg1_0.0.0.9000.tar.gz | Bin 0 -> 717 bytes .../testthat/dependent_pkgs/pkg2/DESCRIPTION | 16 +++++++++++++++ tests/testthat/dependent_pkgs/pkg2/NAMESPACE | 4 ++++ tests/testthat/dependent_pkgs/pkg2/R/foo2.R | 6 ++++++ .../testthat/dependent_pkgs/pkg2/man/foo2.Rd | 11 ++++++++++ .../dependent_pkgs/pkg2/vignettes/test.Rmd | 19 ++++++++++++++++++ tests/testthat/test-build.R | 16 +++++++++++++++ 14 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 tests/testthat/dependent_pkgs/pkg1/DESCRIPTION create mode 100644 tests/testthat/dependent_pkgs/pkg1/NAMESPACE create mode 100644 tests/testthat/dependent_pkgs/pkg1/R/foo1.R create mode 100644 tests/testthat/dependent_pkgs/pkg1/man/foo1.Rd create mode 100644 tests/testthat/dependent_pkgs/pkg1_0.0.0.9000.tar.gz create mode 100644 tests/testthat/dependent_pkgs/pkg2/DESCRIPTION create mode 100644 tests/testthat/dependent_pkgs/pkg2/NAMESPACE create mode 100644 tests/testthat/dependent_pkgs/pkg2/R/foo2.R create mode 100644 tests/testthat/dependent_pkgs/pkg2/man/foo2.Rd create mode 100644 tests/testthat/dependent_pkgs/pkg2/vignettes/test.Rmd 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 4ba56cd..c818b3e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # development version +* Fix usage of `libpath` argument (#195). + # 1.4.0 * `cran_check_results()` now downloads results in parallel, so it is @@ -32,7 +34,7 @@ `rcmdcheck.test_output` global option, to control whether to print the full test output or not. (#121) -* RStudio's Pandoc is now on the path during `rcmdcheck()` +* RStudio's Pandoc is now on the path during `rcmdcheck()` and `rcmdcheck_process` (#109, #132, @dpprdan). * `rcmdcheck()` now errors if the check process crashes (#110, #163). diff --git a/R/build.R b/R/build.R index 630ed86..ae89839 100644 --- a/R/build.R +++ b/R/build.R @@ -1,6 +1,6 @@ #' @importFrom pkgbuild pkgbuild_process -#' @importFrom withr with_envvar +#' @importFrom withr with_libpaths build_package <- function(path, tmpdir, build_args, libpath, quiet) { path <- normalizePath(path) @@ -16,8 +16,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/pkg1_0.0.0.9000.tar.gz b/tests/testthat/dependent_pkgs/pkg1_0.0.0.9000.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..60a563db7752ff7c35ced89c46704904f9f52974 GIT binary patch literal 717 zcmV;;0y6y{iwFP!000001MOH*Z`v>r=GnjEL{&ABfW`?4Yt~JzfKEs)ppb*|YG)aeNVHzh&zvQ>2CB@Pry)-FuNy;WE zOQvRnbVVqmSWJAl8lBZ&kwD(wO*oF9$C)w~ES*L2M&NX#;HqnG)P1SYd##4ua7dr? zC~M0_63^LsY9UGC&&UVcvYonR*QpEC@vS4@v2m*QYgp%D;Xxm?#~^nXd_q6e0KM=T zj7N(!$pwpr!Y_Y3;`rCjeM=tVpNIXhe|piq9G_6xHzYoJX$4mcO8p&{(U%&PB7GeRLV+6StY{6G~=bl`% zdCam+N9BJUtbW{aP_fMLUcAzqjA0TKe5YQEQCODi5+zEM_-ptI#SS8O02lxOA*yE_ literal 0 HcmV?d00001 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 7e3279a..30a8e82 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -44,3 +44,19 @@ 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() + dir.create(lib) + on.exit(unlink(lib, recursive = TRUE), add = TRUE) + + pkg1 <- test_path("dependent_pkgs", "pkg1_0.0.0.9000.tar.gz") + utils::install.packages(pkg1, lib = lib, type = "source") + + pkg2_source <- test_path("dependent_pkgs", "pkg2") + expect_error({ + build_package(pkg2_source, tempfile(), character(), .libPaths(), TRUE) + }) + pkg2 <- build_package(pkg2_source, tempfile(), character(), lib, TRUE) + expect_true(file.exists(pkg2)) +}) From 65b3f17eb369b56dacd6e37b6991baaa659ed75d Mon Sep 17 00:00:00 2001 From: Pawel Rucki Date: Wed, 15 Feb 2023 15:10:36 +0100 Subject: [PATCH 2/4] build during test --- .../dependent_pkgs/pkg1_0.0.0.9000.tar.gz | Bin 717 -> 0 bytes tests/testthat/test-build.R | 8 +++++--- 2 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 tests/testthat/dependent_pkgs/pkg1_0.0.0.9000.tar.gz diff --git a/tests/testthat/dependent_pkgs/pkg1_0.0.0.9000.tar.gz b/tests/testthat/dependent_pkgs/pkg1_0.0.0.9000.tar.gz deleted file mode 100644 index 60a563db7752ff7c35ced89c46704904f9f52974..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 717 zcmV;;0y6y{iwFP!000001MOH*Z`v>r=GnjEL{&ABfW`?4Yt~JzfKEs)ppb*|YG)aeNVHzh&zvQ>2CB@Pry)-FuNy;WE zOQvRnbVVqmSWJAl8lBZ&kwD(wO*oF9$C)w~ES*L2M&NX#;HqnG)P1SYd##4ua7dr? zC~M0_63^LsY9UGC&&UVcvYonR*QpEC@vS4@v2m*QYgp%D;Xxm?#~^nXd_q6e0KM=T zj7N(!$pwpr!Y_Y3;`rCjeM=tVpNIXhe|piq9G_6xHzYoJX$4mcO8p&{(U%&PB7GeRLV+6StY{6G~=bl`% zdCam+N9BJUtbW{aP_fMLUcAzqjA0TKe5YQEQCODi5+zEM_-ptI#SS8O02lxOA*yE_ diff --git a/tests/testthat/test-build.R b/tests/testthat/test-build.R index 30a8e82..83a60c3 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -47,11 +47,13 @@ test_that("inst/doc can be kept", { test_that("libpath argument is used in build_package", { lib <- tempfile() - dir.create(lib) on.exit(unlink(lib, recursive = TRUE), add = TRUE) + dir.create(lib) - pkg1 <- test_path("dependent_pkgs", "pkg1_0.0.0.9000.tar.gz") - utils::install.packages(pkg1, lib = lib, type = "source") + 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, type = "source", quiet = TRUE) pkg2_source <- test_path("dependent_pkgs", "pkg2") expect_error({ From e4385460382a3303e8f51f5fe7f3750d072ae454 Mon Sep 17 00:00:00 2001 From: Pawel Rucki Date: Wed, 15 Feb 2023 16:08:33 +0100 Subject: [PATCH 3/4] install additional packages --- tests/testthat/test-build.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-build.R b/tests/testthat/test-build.R index 83a60c3..cf91154 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -51,9 +51,10 @@ test_that("libpath argument is used in build_package", { dir.create(lib) pkg1_source <- test_path("dependent_pkgs", "pkg1") - pkg1 <- pkgbuild::build(pkg1_source, quiet = TRUE) + pkg1 <- pkgbuild::build(pkg1_source, quiet = TRUE) on.exit(unlink(pkg1, recursive = TRUE), add = TRUE) - install.packages(pkg1, lib = lib, type = "source", quiet = TRUE) + install.packages(pkg1, lib = lib, repos = NULL, type = "source", quiet = TRUE) + install.packages(c("knitr", "markdown"), lib = lib, quiet = TRUE) pkg2_source <- test_path("dependent_pkgs", "pkg2") expect_error({ From 98cfb06afee66cd149008c3e5ac4bde0fd0fa70a Mon Sep 17 00:00:00 2001 From: Pawel Rucki Date: Wed, 15 Feb 2023 16:19:48 +0100 Subject: [PATCH 4/4] combine libpaths --- tests/testthat/test-build.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test-build.R b/tests/testthat/test-build.R index cf91154..84fbb19 100644 --- a/tests/testthat/test-build.R +++ b/tests/testthat/test-build.R @@ -54,12 +54,11 @@ test_that("libpath argument is used in build_package", { 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) - install.packages(c("knitr", "markdown"), lib = lib, 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(), lib, TRUE) + pkg2 <- build_package(pkg2_source, tempfile(), character(), c(lib, .libPaths()), TRUE) expect_true(file.exists(pkg2)) })