Skip to content

Commit da1c84e

Browse files
committed
fix vendor
1 parent 10d3565 commit da1c84e

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

R/vendor.R

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@
3232
#' # cleanup
3333
#' unlink(dir, recursive = TRUE)
3434
cpp_vendor <- function(path = "./inst/include/") {
35-
new <- file.path(path, "cpp11")
35+
new <- file.path(path)
3636

3737
if (dir.exists(new)) {
3838
stop("'", new, "' already exists\n * run unlink('", new, "', recursive = TRUE)", call. = FALSE)
3939
}
4040

4141
# Vendor cpp11 ----
4242

43-
dir.create(new , recursive = TRUE, showWarnings = FALSE)
43+
dir.create(new, recursive = TRUE, showWarnings = FALSE)
44+
dir.create(file.path(new, "cpp11"), recursive = TRUE, showWarnings = FALSE)
4445

4546
current <- system.file("include", "cpp11", package = "cpp11")
47+
4648
if (!nzchar(current)) {
4749
stop("cpp11 is not installed", call. = FALSE)
4850
}
@@ -51,18 +53,50 @@ cpp_vendor <- function(path = "./inst/include/") {
5153

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

54-
write_header(path, "cpp11.hpp", "cpp11", cpp11_header)
56+
main_header <- list.files(current, pattern = "\\.hpp$", full.names = TRUE)
57+
headers <- list.files(file.path(current, "cpp11"), pattern = "\\.hpp$", full.names = TRUE)
58+
59+
writeLines(c(cpp11_header, readLines(main_header)), file.path(new, basename(main_header)))
5560

56-
copy_files(list.files(current, full.names = TRUE), path, "cpp11", cpp11_header)
61+
for (h in headers) {
62+
writeLines(c(cpp11_header, readLines(h)), file.path(new, "cpp11", basename(h)))
63+
}
5764

5865
# Additional steps to make vendoring work ----
5966

60-
message(paste(
61-
"Makevars and/or Makevars.win should have a line such as",
62-
"'PKG_CPPFLAGS = -I../inst/include'"
67+
message(sprintf(
68+
"Adding PKG_CPPFLAGS = -I../%s to src/Makevars and src/Makevars.win.",
69+
new
6370
))
6471

65-
message("DESCRIPTION should not have lines such as 'LinkingTo: cpp11'")
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+
desc <- readLines("DESCRIPTION")
95+
desc <- desc[!grepl("^LinkingTo:\\s*cpp11", desc)]
96+
desc <- gsub("^LinkingTo:\\s*cpp11,\\s*", "LinkingTo: ", desc)
97+
desc <- gsub(",\\s*cpp11", "", desc)
98+
99+
writeLines(descr, "DESCRIPTION")
66100

67101
invisible(new)
68102
}
@@ -84,4 +118,4 @@ copy_files <- function(files, path, out, cpp11_header) {
84118
file.path(path, out, basename(f))
85119
)
86120
}
87-
}
121+
}

0 commit comments

Comments
 (0)