|
8 | 8 | #' 'cpp11 version: XYZ' to the top of the files, where XYZ is the version of |
9 | 9 | #' cpp11 currently installed on your machine. |
10 | 10 | #' |
11 | | -#' If you choose to vendor the headers you should _remove_ `LinkingTo: |
12 | | -#' cpp11` from your DESCRIPTION. This is done automatically by this function. |
13 | | -#' |
14 | 11 | #' **Note**: vendoring places the responsibility of updating the code on |
15 | 12 | #' **you**. Bugfixes and new features in cpp11 will not be available for your |
16 | 13 | #' code until you run `cpp_vendor()` again. |
17 | 14 | #' |
18 | | -#' @param path The path to vendor the code into. The default is |
19 | | -#' `./inst/include/`. |
| 15 | +#' @param path The path to vendor the code into. |
20 | 16 | #' @return The file path to the vendored code (invisibly). |
21 | 17 | #' @export |
22 | 18 | #' @examples |
|
31 | 27 | #' |
32 | 28 | #' # cleanup |
33 | 29 | #' unlink(dir, recursive = TRUE) |
34 | | -cpp_vendor <- function(path = "./inst/include/") { |
| 30 | +cpp_vendor <- function(path = NULL) { |
| 31 | + if (is.null(path)) { |
| 32 | + stop("You must provide a path to vendor the code into", call. = FALSE) |
| 33 | + } else { |
| 34 | + path <- paste0(path, "/inst/include") |
| 35 | + } |
| 36 | + |
35 | 37 | new <- file.path(path) |
36 | 38 |
|
37 | 39 | if (dir.exists(new)) { |
@@ -64,57 +66,12 @@ cpp_vendor <- function(path = "./inst/include/") { |
64 | 66 |
|
65 | 67 | # Additional steps to make vendoring work ---- |
66 | 68 |
|
67 | | - message(sprintf( |
68 | | - "Adding PKG_CPPFLAGS = -I../%s to src/Makevars and src/Makevars.win.", |
69 | | - new |
| 69 | + message(paste( |
| 70 | + "Makevars and/or Makevars.win should have a line such as", |
| 71 | + "'PKG_CPPFLAGS = -I../inst/include'" |
70 | 72 | )) |
71 | 73 |
|
72 | | - makevars <- "src/Makevars" |
73 | | - makevars_win <- "src/Makevars.win" |
74 | | - makevars_line <- paste0("PKG_CPPFLAGS = -I ../", new) |
75 | | - |
76 | | - if (file.exists(makevars)) { |
77 | | - if (!any(grepl(paste0("^PKG_CPPFLAGS\\s*=\\s*-I\\s*\\.\\./", new), readLines(makevars)))) { |
78 | | - writeLines(c(readLines(makevars), makevars_line), makevars) |
79 | | - } |
80 | | - } else { |
81 | | - writeLines(makevars_line, makevars) |
82 | | - } |
83 | | - |
84 | | - if (file.exists(makevars_win)) { |
85 | | - if (!any(grepl(paste0("^PKG_CPPFLAGS\\s*=\\s*-I\\s*\\.\\./", new), readLines(makevars_win)))) { |
86 | | - writeLines(c(readLines(makevars_win), makevars_line), makevars_win) |
87 | | - } |
88 | | - } else { |
89 | | - writeLines(makevars_line, makevars_win) |
90 | | - } |
91 | | - |
92 | | - message("Removing 'LinkingTo: cpp11' from DESCRIPTION.") |
93 | | - |
94 | | - descr <- readLines("DESCRIPTION") |
95 | | - linking_to <- which(grepl("^LinkingTo:", descr)) |
96 | | - |
97 | | - if (length(linking_to) > 0) { |
98 | | - linking_to_end <- which(!grepl("^\\s", descr[-(1:linking_to)])) |
99 | | - if (length(linking_to_end) > 0) { |
100 | | - linking_to_end <- linking_to_end[1] + linking_to - 1 |
101 | | - } else { |
102 | | - linking_to_end <- length(descr) |
103 | | - } |
104 | | - linking_to_str <- paste(descr[linking_to:linking_to_end], collapse = "") |
105 | | - linking_to_str <- gsub("\\s+", " ", linking_to_str) |
106 | | - descr[linking_to] <- linking_to_str |
107 | | - descr <- descr[-((linking_to + 1):linking_to_end)] |
108 | | - linking_to_str <- gsub("\\s*cpp11(,|\\s*\\(.*\\))?", "", linking_to_str, perl = TRUE) |
109 | | - linking_to_str <- gsub(",\\s*$", "", linking_to_str) |
110 | | - descr[linking_to] <- linking_to_str |
111 | | - } |
112 | | - |
113 | | - if (grepl("^LinkingTo:\\s*$", descr[linking_to])) { |
114 | | - descr <- descr[-linking_to] |
115 | | - } |
116 | | - |
117 | | - writeLines(descr, "DESCRIPTION") |
| 74 | + message("DESCRIPTION should not have lines such as 'LinkingTo: cpp11'") |
118 | 75 |
|
119 | 76 | invisible(new) |
120 | 77 | } |
|
0 commit comments