Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor path #353

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions R/vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#' cpp11 currently installed on your machine.
#'
#' If you choose to vendor the headers you should _remove_ `LinkingTo:
#' cpp11` from your DESCRIPTION.
#' cpp11` from your DESCRIPTION. This is done automatically by this function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! I added the changes for that, because I am a dummy

#'
#' **Note**: vendoring places the responsibility of updating the code on
#' **you**. Bugfixes and new features in cpp11 will not be available for your
#' code until you run `cpp_vendor()` again.
#'
#' @inheritParams cpp_register
#' @param path The path to vendor the code into. The default is
#' `./inst/include/`.
#' @return The file path to the vendored code (invisibly).
#' @export
#' @examples
Expand All @@ -30,13 +31,15 @@
#'
#' # cleanup
#' unlink(dir, recursive = TRUE)
cpp_vendor <- function(path = ".") {
new <- file.path(path, "inst", "include", "cpp11")
cpp_vendor <- function(path = "./inst/include/") {
new <- file.path(path, "cpp11")

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

# Vendor cpp11 ----

dir.create(new , recursive = TRUE, showWarnings = FALSE)

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

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

files <- list.files(current, full.names = TRUE)
write_header(path, "cpp11.hpp", "cpp11", cpp11_header)

copy_files(list.files(current, full.names = TRUE), path, "cpp11", cpp11_header)

# Additional steps to make vendoring work ----

message(paste(
"Makevars and/or Makevars.win should have a line such as",
"'PKG_CPPFLAGS = -I../inst/include'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this now need to show the new path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that line is added automatically, and uses the path the user wants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i reallize i never pushed that change, done now

))

message("DESCRIPTION should not have lines such as 'LinkingTo: cpp11'")

invisible(new)
}

write_header <- function(path, header, pkg, cpp11_header) {
writeLines(
c(cpp11_header, readLines(system.file("include", "cpp11.hpp", package = "cpp11"))),
file.path(dirname(new), "cpp11.hpp")
c(
cpp11_header,
readLines(system.file("include", header, package = pkg))
),
file.path(path, header)
)
}

copy_files <- function(files, path, out, cpp11_header) {
for (f in files) {
writeLines(c(cpp11_header, readLines(f)), file.path(new, basename(f)))
writeLines(
c(cpp11_header, readLines(f)),
file.path(path, out, basename(f))
)
}

invisible(new)
}
}
7 changes: 4 additions & 3 deletions man/cpp_vendor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test-vendor.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe("cpp_vendor", {

cpp_vendor(pkg_path(pkg))
pachadotdev marked this conversation as resolved.
Show resolved Hide resolved

expect_true(dir.exists(file.path(p, "inst", "include", "cpp11")))
expect_true(file.exists(file.path(p, "inst", "include", "cpp11.hpp")))
expect_true(file.exists(file.path(p, "inst", "include", "cpp11", "declarations.hpp")))
expect_true(dir.exists(file.path(p, "cpp11")))
expect_true(file.exists(file.path(p, "cpp11.hpp")))
expect_true(file.exists(file.path(p, "cpp11", "declarations.hpp")))
})
})
Loading