Skip to content
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
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)
}

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 @@ cpp_vendor <- function(path = ".") {
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)
}

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