-
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.
* draft and test * use expect_type() * list under utility functions * document * check string * more meaningful test * update news * Update NEWS.md Co-authored-by: Ilia Kosenkov <[email protected]> --------- Co-authored-by: Ilia Kosenkov <[email protected]>
- Loading branch information
1 parent
a8d7434
commit ea68f4e
Showing
6 changed files
with
127 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
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
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,46 @@ | ||
#' 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 = ".") { | ||
check_string(path, class = "rextendr_error") | ||
|
||
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 |
---|---|---|
|
@@ -29,3 +29,4 @@ reference: | |
- to_toml | ||
- make_module_macro | ||
- rust_sitrep | ||
- read_cargo_metadata |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
test_that("read_cargo_metadata() returns crate 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(path) | ||
|
||
expect_type(out, "list") | ||
|
||
expect_equal( | ||
out[["packages"]][["name"]], | ||
"testpkg" | ||
) | ||
|
||
expect_equal( | ||
out[["packages"]][["version"]], | ||
"0.1.0" | ||
) | ||
|
||
expect_equal( | ||
out[["packages"]][["dependencies"]][[1]][["name"]], | ||
"extendr-api" | ||
) | ||
|
||
expect_equal( | ||
out[["workspace_root"]], | ||
normalizePath( | ||
file.path(path, "src", "rust"), | ||
winslash = "\\", | ||
mustWork = FALSE | ||
) | ||
) | ||
}) |