Skip to content

Commit 06bb183

Browse files
committed
better unvendor approach
1 parent 074ab4b commit 06bb183

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

R/unvendor.R

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,45 @@
1515
#' vendor(dir)
1616
#'
1717
#' # unvendor the cpp4r headers from the directory
18-
#' unvendor()
18+
#' unvendor(dir)
1919
#'
2020
#' # cleanup
2121
#' unlink(dir, recursive = TRUE)
2222
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) {
2734
if (is_interactive()) { message("Could not find vendored headers") }
2835
return(invisible(NULL))
2936
}
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)
3537

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+
}
3842

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) {
4245
unlink(cpp4r_hpp_path)
4346
}
47+
48+
# Remove the info file if it exists
49+
if (has_info_file) {
50+
unlink(info_file_path)
51+
}
4452

4553
if (is_interactive()) {
46-
message("Unvendored cpp4r from '", parent_dir, "'")
54+
message("Unvendored cpp4r from '", path, "'")
4755
message("DESCRIPTION should link to cpp4r (e.g., 'LinkingTo: cpp4r')")
4856
}
4957

50-
invisible(parent_dir)
58+
invisible(path)
5159
}

man/unvendor.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)