-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal utilities to find rust crate and cargo manifest (#399)
* internal functions and tests * Update R/find_extendr.R Co-authored-by: Josiah Parry <[email protected]> * Update R/find_extendr.R Co-authored-by: Josiah Parry <[email protected]> --------- Co-authored-by: Josiah Parry <[email protected]>
- Loading branch information
1 parent
4aefce1
commit d8689d9
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
#' } | ||
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( | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) |