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
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+ }
0 commit comments