Skip to content

Commit 6778095

Browse files
committed
fix eventual CRAN warning
1 parent 8845015 commit 6778095

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ Config/Needs/cpp11/cpp_register:
5555
vctrs
5656
Encoding: UTF-8
5757
Roxygen: list(markdown = TRUE)
58-
RoxygenNote: 7.2.3
58+
RoxygenNote: 7.3.1

R/vendor.R

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#' **you**. Bugfixes and new features in cpp11 will not be available for your
1313
#' code until you run `cpp_vendor()` again.
1414
#'
15-
#' @param path The path to vendor the code into.
15+
#' @param dir The directoyy to vendor the code into.
16+
#' @param subdir The subdirectory to vendor the code into.
1617
#' @return The file path to the vendored code (invisibly).
1718
#' @export
1819
#' @examples
@@ -27,42 +28,53 @@
2728
#'
2829
#' # cleanup
2930
#' unlink(dir, recursive = TRUE)
30-
cpp_vendor <- function(path = NULL) {
31-
if (is.null(path)) {
31+
cpp_vendor <- function(dir = NULL, subdir = "/inst/include") {
32+
if (is.null(dir)) {
3233
stop("You must provide a path to vendor the code into", call. = FALSE)
33-
} else {
34-
path <- paste0(path, "/inst/include")
3534
}
36-
37-
new <- file.path(path)
3835

39-
if (dir.exists(new)) {
40-
stop("'", new, "' already exists\n * run unlink('", new, "', recursive = TRUE)", call. = FALSE)
36+
path <- paste0(dir, subdir)
37+
38+
path2 <- file.path(path, "cpp11")
39+
if (dir.exists(path2)) {
40+
stop("'", path2, "' already exists\n * run unlink('", path2, "', recursive = TRUE)", call. = FALSE)
4141
}
4242

4343
# Vendor cpp11 ----
4444

45-
dir.create(new, recursive = TRUE, showWarnings = FALSE)
46-
dir.create(file.path(new, "cpp11"), recursive = TRUE, showWarnings = FALSE)
45+
dir.create(
46+
path2,
47+
recursive = TRUE,
48+
showWarnings = FALSE
49+
)
4750

48-
current <- system.file("include", "cpp11", package = "cpp11")
51+
current_cpp11 <- system.file(
52+
"include",
53+
"cpp11",
54+
package = "cpp11"
55+
)
4956

50-
if (!nzchar(current)) {
57+
if (!nzchar(current_cpp11)) {
5158
stop("cpp11 is not installed", call. = FALSE)
5259
}
5360

5461
cpp11_version <- utils::packageVersion("cpp11")
5562

56-
cpp11_header <- sprintf("// cpp11 version: %s\n// vendored on: %s", cpp11_version, Sys.Date())
57-
58-
main_header <- list.files(current, pattern = "\\.hpp$", full.names = TRUE)
59-
headers <- list.files(file.path(current, "cpp11"), pattern = "\\.hpp$", full.names = TRUE)
63+
cpp11_header <- sprintf(
64+
"// cpp11 version: %s\n// vendored on: %s",
65+
cpp11_version,
66+
Sys.Date()
67+
)
6068

61-
writeLines(c(cpp11_header, readLines(main_header)), file.path(new, basename(main_header)))
69+
write_header(
70+
path, "cpp11.hpp", "cpp11",
71+
cpp11_header
72+
)
6273

63-
for (h in headers) {
64-
writeLines(c(cpp11_header, readLines(h)), file.path(new, "cpp11", basename(h)))
65-
}
74+
copy_files(
75+
list.files(current_cpp11, full.names = TRUE),
76+
path, "cpp11", cpp11_header
77+
)
6678

6779
# Additional steps to make vendoring work ----
6880

@@ -73,23 +85,25 @@ cpp_vendor <- function(path = NULL) {
7385

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

76-
invisible(new)
88+
invisible(path)
7789
}
7890

79-
write_header <- function(path, header, pkg, cpp11_header) {
91+
write_header <- function(path, header, pkg, cpp11armadillo_header) {
8092
writeLines(
8193
c(
82-
cpp11_header,
83-
readLines(system.file("include", header, package = pkg))
94+
cpp11armadillo_header,
95+
readLines(
96+
system.file("include", header, package = pkg)
97+
)
8498
),
8599
file.path(path, header)
86100
)
87101
}
88102

89-
copy_files <- function(files, path, out, cpp11_header) {
103+
copy_files <- function(files, path, out, cpp11armadillo_header) {
90104
for (f in files) {
91105
writeLines(
92-
c(cpp11_header, readLines(f)),
106+
c(cpp11armadillo_header, readLines(f)),
93107
file.path(path, out, basename(f))
94108
)
95109
}

man/cpp_vendor.Rd

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-vendor.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ describe("cpp_vendor", {
2222
pkg <- local_package()
2323
p <- pkg_path(pkg)
2424

25-
cpp_vendor(file.path(pkg_path(pkg), "inst/include"))
25+
cpp_vendor(pkg_path(pkg))
2626

27-
expect_true(dir.exists(file.path(p, "cpp11")))
28-
expect_true(file.exists(file.path(p, "cpp11.hpp")))
29-
expect_true(file.exists(file.path(p, "cpp11", "declarations.hpp")))
27+
expect_true(dir.exists(file.path(p, "inst", "include", "cpp11")))
28+
expect_true(file.exists(file.path(p, "inst", "include", "cpp11.hpp")))
29+
expect_true(file.exists(file.path(p, "inst", "include", "cpp11", "declarations.hpp")))
3030
})
3131
})

0 commit comments

Comments
 (0)