Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
69 changes: 69 additions & 0 deletions R/find_extendr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#' Get path to Rust crate in R package directory
#'
#' @param path character scalar, the R package directory
#' @param error_call call scalar, from rlang docs: "the defused call with which
#' the function running in the frame was invoked"
#'
#' @return character scalar, path to Rust crate
#'
#' @examples
#' \dontrun{
#' find_extendr_crate()
#' @keywords internal
#' @noRd
#' }
Comment thread
kbvernon marked this conversation as resolved.
find_extendr_crate <- function(
path = ".",
error_call = rlang::caller_call()) {
check_character(path, call = error_call, class = "rextendr_error")

rust_folder <- rprojroot::find_package_root_file(
"src", "rust",
path = path
)

if (!dir.exists(rust_folder)) {
cli::cli_abort(
"Could not find Rust crate at {.path rust_folder}.",
call = error_call,
class = "rextendr_error"
)
}

rust_folder
}

#' Get path to Cargo manifest in R package directory
#'
#' @param path character scalar, the R package directory
#' @param error_call call scalar, from rlang docs: "the defused call with which
#' the function running in the frame was invoked"
#'
#' @return character scalar, path to Cargo manifest
#'
#' @examples
#' \dontrun{
#' find_extendr_manifest()
#' @keywords internal
#' @noRd
#' }
find_extendr_manifest <- function(
Comment thread
kbvernon marked this conversation as resolved.
path = ".",
error_call = rlang::caller_call()) {
check_character(path, call = error_call, class = "rextendr_error")

manifest_path <- rprojroot::find_package_root_file(
"src", "rust", "Cargo.toml",
path = path
)

if (!file.exists(manifest_path)) {
cli::cli_abort(
"Could not find Cargo manifest at {.path manifest_path}.",
call = error_call,
class = "rextendr_error"
)
}

manifest_path
}
33 changes: 33 additions & 0 deletions tests/testthat/test-find_extendr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
test_that("find_extendr_crate() returns path to Rust crate", {
skip_if_not_installed("usethis")

path <- local_package("testpkg")

# capture setup messages
withr::local_options(usethis.quiet = FALSE)

expect_error(find_extendr_crate(), class = "rextendr_error")

use_extendr(path, quiet = TRUE)

rust_folder <- find_extendr_crate()

expect_true(dir.exists(rust_folder))
})

test_that("find_extendr_manifest() returns path to Cargo manifest", {
skip_if_not_installed("usethis")

path <- local_package("testpkg")

# capture setup messages
withr::local_options(usethis.quiet = FALSE)

expect_error(find_extendr_manifest(), class = "rextendr_error")

use_extendr(path, quiet = TRUE)

manifest_path <- find_extendr_manifest()

expect_true(file.exists(manifest_path))
})