Skip to content

Commit 71c2dcc

Browse files
committed
vendor path
1 parent 51f4cd5 commit 71c2dcc

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

R/vendor.R

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#' cpp11 currently installed on your machine.
1010
#'
1111
#' If you choose to vendor the headers you should _remove_ `LinkingTo:
12-
#' cpp11` from your DESCRIPTION.
12+
#' cpp11` from your DESCRIPTION. This is done automatically by this function.
1313
#'
1414
#' **Note**: vendoring places the responsibility of updating the code on
1515
#' **you**. Bugfixes and new features in cpp11 will not be available for your
1616
#' code until you run `cpp_vendor()` again.
1717
#'
18-
#' @inheritParams cpp_register
18+
#' @param path The path to vendor the code into. The default is
19+
#' `./inst/include/`.
1920
#' @return The file path to the vendored code (invisibly).
2021
#' @export
2122
#' @examples
@@ -30,13 +31,15 @@
3031
#'
3132
#' # cleanup
3233
#' unlink(dir, recursive = TRUE)
33-
cpp_vendor <- function(path = ".") {
34-
new <- file.path(path, "inst", "include", "cpp11")
34+
cpp_vendor <- function(path = "./inst/include/") {
35+
new <- file.path(path, "cpp11")
3536

3637
if (dir.exists(new)) {
3738
stop("'", new, "' already exists\n * run unlink('", new, "', recursive = TRUE)", call. = FALSE)
3839
}
3940

41+
# Vendor cpp11 ----
42+
4043
dir.create(new , recursive = TRUE, showWarnings = FALSE)
4144

4245
current <- system.file("include", "cpp11", package = "cpp11")
@@ -48,16 +51,37 @@ cpp_vendor <- function(path = ".") {
4851

4952
cpp11_header <- sprintf("// cpp11 version: %s\n// vendored on: %s", cpp11_version, Sys.Date())
5053

51-
files <- list.files(current, full.names = TRUE)
54+
write_header(path, "cpp11.hpp", "cpp11", cpp11_header)
55+
56+
copy_files(list.files(current, full.names = TRUE), path, "cpp11", cpp11_header)
57+
58+
# Additional steps to make vendoring work ----
59+
60+
message(paste(
61+
"Makevars and/or Makevars.win should have a line such as",
62+
"'PKG_CPPFLAGS = -I../inst/include'"
63+
))
64+
65+
message("DESCRIPTION should not have lines such as 'LinkingTo: cpp11'")
66+
67+
invisible(new)
68+
}
5269

70+
write_header <- function(path, header, pkg, cpp11_header) {
5371
writeLines(
54-
c(cpp11_header, readLines(system.file("include", "cpp11.hpp", package = "cpp11"))),
55-
file.path(dirname(new), "cpp11.hpp")
72+
c(
73+
cpp11_header,
74+
readLines(system.file("include", header, package = pkg))
75+
),
76+
file.path(path, header)
5677
)
78+
}
5779

80+
copy_files <- function(files, path, out, cpp11_header) {
5881
for (f in files) {
59-
writeLines(c(cpp11_header, readLines(f)), file.path(new, basename(f)))
82+
writeLines(
83+
c(cpp11_header, readLines(f)),
84+
file.path(path, out, basename(f))
85+
)
6086
}
61-
62-
invisible(new)
63-
}
87+
}

man/cpp_vendor.Rd

Lines changed: 4 additions & 3 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ describe("cpp_vendor", {
2424

2525
cpp_vendor(pkg_path(pkg))
2626

27-
expect_true(dir.exists(file.path(p, "inst", "include", "cpp11")))
28-
expect_true(file.exists(file.path(p, "inst", "include", "cpp11.hpp")))
29-
expect_true(file.exists(file.path(p, "inst", "include", "cpp11", "declarations.hpp")))
27+
expect_true(dir.exists(file.path(p, "cpp11")))
28+
expect_true(file.exists(file.path(p, "cpp11.hpp")))
29+
expect_true(file.exists(file.path(p, "cpp11", "declarations.hpp")))
3030
})
3131
})

0 commit comments

Comments
 (0)