Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add and test unvendor function #418

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cpp11
Title: A C++11 Interface for R's C Interface
Version: 0.5.1.9000
Version: 0.5.1.9001
Authors@R:
c(
person("Davis", "Vaughan", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4777-038X")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export(cpp_eval)
export(cpp_function)
export(cpp_register)
export(cpp_source)
export(cpp_unvendor)
export(cpp_vendor)
39 changes: 39 additions & 0 deletions R/unvendor.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' Unvendor the cpp11 dependency
#'
#' This function removes the vendored cpp11 headers from your package and
#' restores the `LinkingTo: cpp11` field in the DESCRIPTION file if it was removed.
#'
#' @inheritParams cpp_register
#' @return The file path to the unvendored code (invisibly).
#' @export
#' @examples
#' # create a new directory
#' dir <- tempfile()
#' dir.create(dir)
#'
#' # vendor the cpp11 headers into the directory
#' cpp_vendor(dir)
#'
#' # unvendor the cpp11 headers from the directory
#' cpp_unvendor(dir)
#'
#' list.files(file.path(dir, "inst", "include", "cpp11"))
#'
#' # cleanup
#' unlink(dir, recursive = TRUE)
cpp_unvendor <- function(path = ".") {
new <- file.path(path, "inst", "include", "cpp11")

if (!dir.exists(new)) {
stop("'", new, "' does not exist", call. = FALSE)

Check warning on line 28 in R/unvendor.R

View check run for this annotation

Codecov / codecov/patch

R/unvendor.R#L28

Added line #L28 was not covered by tests
}

unlink(new, recursive = TRUE)

cpp11_hpp <- file.path(dirname(new), "cpp11.hpp")
if (file.exists(cpp11_hpp)) {
unlink(cpp11_hpp)
}

invisible(new)
}
3 changes: 2 additions & 1 deletion R/vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
new <- file.path(path, "inst", "include", "cpp11")

if (dir.exists(new)) {
stop("'", new, "' already exists\n * run unlink('", new, "', recursive = TRUE)", call. = FALSE)
message("'", new, "' already exists, removing it")
cpp_unvendor(path)

Check warning on line 38 in R/vendor.R

View check run for this annotation

Codecov / codecov/patch

R/vendor.R#L37-L38

Added lines #L37 - L38 were not covered by tests
}

dir.create(new , recursive = TRUE, showWarnings = FALSE)
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ reference:
- title: Vendoring cpp11
contents:
- cpp_vendor
- cpp_unvendor

navbar:
type: default
Expand Down
34 changes: 34 additions & 0 deletions man/cpp_unvendor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions tests/testthat/test-vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ describe("cpp_vendor", {
)
})

it("errors if cpp11 is already vendored", {
pkg <- local_package()
cpp_vendor(pkg_path(pkg))

expect_error(
cpp_vendor(pkg_path(pkg)),
"already exists"
)
})

it("vendors cpp11", {
pkg <- local_package()
p <- pkg_path(pkg)
Expand All @@ -27,5 +17,7 @@ describe("cpp_vendor", {
expect_true(dir.exists(file.path(p, "inst", "include", "cpp11")))
expect_true(file.exists(file.path(p, "inst", "include", "cpp11.hpp")))
expect_true(file.exists(file.path(p, "inst", "include", "cpp11", "declarations.hpp")))

expect_silent(cpp_unvendor(pkg_path(pkg)))
})
})
Loading