|
15 | 15 | #' vendor(dir) |
16 | 16 | #' |
17 | 17 | #' # unvendor the cpp4r headers from the directory |
18 | | -#' unvendor() |
| 18 | +#' unvendor(dir) |
19 | 19 | #' |
20 | 20 | #' # cleanup |
21 | 21 | #' unlink(dir, recursive = TRUE) |
22 | 22 | unvendor <- function(path = "./src/vendor") { |
23 | | - # Find the vendoring info file |
24 | | - info_files <- list.files(path, pattern = "00-cpp4r-vendoring-info.txt", recursive = TRUE, full.names = TRUE) |
25 | | - |
26 | | - if (length(info_files) != 1L) { |
| 23 | + # Check if the cpp4r directory exists |
| 24 | + cpp4r_dir <- file.path(path, "cpp4r") |
| 25 | + cpp4r_hpp_path <- file.path(path, "cpp4r.hpp") |
| 26 | + info_file_path <- file.path(path, "00-cpp4r-vendoring-info.txt") |
| 27 | + |
| 28 | + # Check if vendored files exist |
| 29 | + has_cpp4r_dir <- dir.exists(cpp4r_dir) |
| 30 | + has_cpp4r_hpp <- file.exists(cpp4r_hpp_path) |
| 31 | + has_info_file <- file.exists(info_file_path) |
| 32 | + |
| 33 | + if (!has_cpp4r_dir && !has_cpp4r_hpp && !has_info_file) { |
27 | 34 | if (is_interactive()) { message("Could not find vendored headers") } |
28 | 35 | return(invisible(NULL)) |
29 | 36 | } |
30 | | - |
31 | | - # The info file is in the cpp4r directory, so dirname(info_files) gives us the cpp4r directory |
32 | | - cpp4r_dir <- dirname(info_files) |
33 | | - # The parent of the cpp4r directory is where cpp4r.hpp should be |
34 | | - parent_dir <- dirname(cpp4r_dir) |
35 | 37 |
|
36 | | - # Remove the cpp4r directory |
37 | | - unlink(cpp4r_dir, recursive = TRUE) |
| 38 | + # Remove the cpp4r directory if it exists |
| 39 | + if (has_cpp4r_dir) { |
| 40 | + unlink(cpp4r_dir, recursive = TRUE) |
| 41 | + } |
38 | 42 |
|
39 | | - # Remove cpp4r.hpp from the parent directory |
40 | | - cpp4r_hpp_path <- file.path(parent_dir, "cpp4r.hpp") |
41 | | - if (file.exists(cpp4r_hpp_path)) { |
| 43 | + # Remove cpp4r.hpp if it exists |
| 44 | + if (has_cpp4r_hpp) { |
42 | 45 | unlink(cpp4r_hpp_path) |
43 | 46 | } |
| 47 | + |
| 48 | + # Remove the info file if it exists |
| 49 | + if (has_info_file) { |
| 50 | + unlink(info_file_path) |
| 51 | + } |
44 | 52 |
|
45 | 53 | if (is_interactive()) { |
46 | | - message("Unvendored cpp4r from '", parent_dir, "'") |
| 54 | + message("Unvendored cpp4r from '", path, "'") |
47 | 55 | message("DESCRIPTION should link to cpp4r (e.g., 'LinkingTo: cpp4r')") |
48 | 56 | } |
49 | 57 |
|
50 | | - invisible(parent_dir) |
| 58 | + invisible(path) |
51 | 59 | } |
0 commit comments