Skip to content

Commit 8845015

Browse files
committed
replace DESC/Make funs with user msg
1 parent e2df430 commit 8845015

File tree

1 file changed

+12
-55
lines changed

1 file changed

+12
-55
lines changed

R/vendor.R

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
#' 'cpp11 version: XYZ' to the top of the files, where XYZ is the version of
99
#' cpp11 currently installed on your machine.
1010
#'
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-
#'
1411
#' **Note**: vendoring places the responsibility of updating the code on
1512
#' **you**. Bugfixes and new features in cpp11 will not be available for your
1613
#' code until you run `cpp_vendor()` again.
1714
#'
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.
2016
#' @return The file path to the vendored code (invisibly).
2117
#' @export
2218
#' @examples
@@ -31,7 +27,13 @@
3127
#'
3228
#' # cleanup
3329
#' 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+
3537
new <- file.path(path)
3638

3739
if (dir.exists(new)) {
@@ -64,57 +66,12 @@ cpp_vendor <- function(path = "./inst/include/") {
6466

6567
# Additional steps to make vendoring work ----
6668

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'"
7072
))
7173

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'")
11875

11976
invisible(new)
12077
}

0 commit comments

Comments
 (0)