-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 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,44 @@ | ||
#' Retrieve metadata for packages and workspaces | ||
#' | ||
#' @param path character scalar, the R package directory | ||
#' | ||
#' @details | ||
#' For more details, see | ||
#' \href{https://doc.rust-lang.org/cargo/commands/cargo-metadata.html}{Cargo docs} | ||
#' for `cargo-metadata`. See especially "JSON Format" to get a sense of what you | ||
#' can expect to find in the returned list. | ||
#' | ||
#' @return `list`, including the following elements: | ||
#' - "packages" | ||
#' - "workspace_members" | ||
#' - "workspace_default_members" | ||
#' - "resolve" | ||
#' - "target_directory" | ||
#' - "version" | ||
#' - "workspace_root" | ||
#' - "metadata" | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' read_cargo_metadata() | ||
#' } | ||
#' | ||
read_cargo_metadata <- function(path = ".") { | ||
root <- rprojroot::find_package_root_file(path = path) | ||
|
||
rust_folder <- normalizePath( | ||
file.path(root, "src", "rust"), | ||
winslash = "/", | ||
mustWork = FALSE | ||
) | ||
|
||
out <- processx::run( | ||
"cargo", | ||
args = c("metadata", "--format-version=1", "--no-deps"), | ||
wd = rust_folder | ||
) | ||
|
||
jsonlite::fromJSON(out[["stdout"]]) | ||
} |
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,14 @@ | ||
test_that("read_cargo_metadata() returns package or workspace metadata", { | ||
skip_if_not_installed("usethis") | ||
|
||
path <- local_package("testpkg") | ||
|
||
# capture setup messages | ||
withr::local_options(usethis.quiet = FALSE) | ||
|
||
use_extendr(path, quiet = TRUE) | ||
|
||
out <- read_cargo_metadata() | ||
|
||
expect_s3_class(out, "list") | ||
}) |