Skip to content

Commit 2729233

Browse files
committed
add and test unvendor function
1 parent aeb1895 commit 2729233

File tree

6 files changed

+79
-12
lines changed

6 files changed

+79
-12
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: cpp11
22
Title: A C++11 Interface for R's C Interface
3-
Version: 0.5.1.9000
3+
Version: 0.5.1.9001
44
Authors@R:
55
c(
66
person("Davis", "Vaughan", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4777-038X")),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export(cpp_eval)
44
export(cpp_function)
55
export(cpp_register)
66
export(cpp_source)
7+
export(cpp_unvendor)
78
export(cpp_vendor)

R/unvendor.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#' Unvendor the cpp11 dependency
2+
#'
3+
#' This function removes the vendored cpp11 headers from your package and
4+
#' restores the `LinkingTo: cpp11` field in the DESCRIPTION file if it was removed.
5+
#'
6+
#' @inheritParams cpp_register
7+
#' @return The file path to the unvendored code (invisibly).
8+
#' @export
9+
#' @examples
10+
#' # create a new directory
11+
#' dir <- tempfile()
12+
#' dir.create(dir)
13+
#'
14+
#' # vendor the cpp11 headers into the directory
15+
#' cpp_vendor(dir)
16+
#'
17+
#' # unvendor the cpp11 headers from the directory
18+
#' unvendor_cpp11(dir)
19+
#'
20+
#' list.files(file.path(dir, "inst", "include", "cpp11"))
21+
#'
22+
#' # cleanup
23+
#' unlink(dir, recursive = TRUE)
24+
cpp_unvendor <- function(path = ".") {
25+
new <- file.path(path, "inst", "include", "cpp11")
26+
27+
if (!dir.exists(new)) {
28+
stop("'", new, "' does not exist", call. = FALSE)
29+
}
30+
31+
unlink(new, recursive = TRUE)
32+
33+
cpp11_hpp <- file.path(dirname(new), "cpp11.hpp")
34+
if (file.exists(cpp11_hpp)) {
35+
unlink(cpp11_hpp)
36+
}
37+
38+
invisible(new)
39+
}

R/vendor.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ cpp_vendor <- function(path = ".") {
3434
new <- file.path(path, "inst", "include", "cpp11")
3535

3636
if (dir.exists(new)) {
37-
stop("'", new, "' already exists\n * run unlink('", new, "', recursive = TRUE)", call. = FALSE)
37+
message("'", new, "' already exists, removing it")
38+
cpp_unvendor(path)
3839
}
3940

4041
dir.create(new , recursive = TRUE, showWarnings = FALSE)

man/cpp_unvendor.Rd

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-vendor.R

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ describe("cpp_vendor", {
88
)
99
})
1010

11-
it("errors if cpp11 is already vendored", {
12-
pkg <- local_package()
13-
cpp_vendor(pkg_path(pkg))
14-
15-
expect_error(
16-
cpp_vendor(pkg_path(pkg)),
17-
"already exists"
18-
)
19-
})
20-
2111
it("vendors cpp11", {
2212
pkg <- local_package()
2313
p <- pkg_path(pkg)
@@ -27,5 +17,7 @@ describe("cpp_vendor", {
2717
expect_true(dir.exists(file.path(p, "inst", "include", "cpp11")))
2818
expect_true(file.exists(file.path(p, "inst", "include", "cpp11.hpp")))
2919
expect_true(file.exists(file.path(p, "inst", "include", "cpp11", "declarations.hpp")))
20+
21+
expect_silent(cpp_unvendor(pkg_path(pkg)))
3022
})
3123
})

0 commit comments

Comments
 (0)