-
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
1 changed file
with
54 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,54 @@ | ||
#' Add MSRV to DESCRIPTION | ||
#' | ||
#' @param version character scalar, the minimum supported Rust version | ||
#' @param path character scalar, path to folder containing DESCRIPTION file | ||
#' | ||
#' @details | ||
#' It is assumed that MSRV is greater than or equal to `version`. The result is | ||
#' "SystemRequirements: Cargo (Rust's package manager), rustc >= `version`." | ||
#' | ||
#' @return NULL | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' use_msrv("1.67.1") | ||
#' } | ||
#' | ||
use_msrv <- function(version = NULL, path = "."){ | ||
Check warning on line 18 in R/use_msrv.R GitHub Actions / lint
|
||
|
||
if (is.null(version)){ | ||
Check warning on line 20 in R/use_msrv.R GitHub Actions / lint
|
||
cli::cli_abort( | ||
"Minimum supported Rust {.arg version} not specified.", | ||
class = "rextendr_error" | ||
) | ||
} | ||
|
||
desc_path <- rprojroot::find_package_root_file("DESCRIPTION", path = path) | ||
|
||
if (!file.exists(desc_path)) { | ||
cli::cli_abort( | ||
"{.arg path} ({.path {path}}) does not contain a DESCRIPTION", | ||
class = "rextendr_error" | ||
) | ||
} | ||
|
||
cur <- paste("Cargo (Rust's package manager), rustc", paste(">=", version)) | ||
|
||
prev <- desc::desc_get("SystemRequirements", file = desc_path)[[1]] | ||
prev <- stringi::stri_trim_both(prev) | ||
|
||
if (is.na(prev)) { | ||
update_description("SystemRequirements", cur, desc_path = desc_path) | ||
} else if (!identical(cur, prev)) { | ||
cli::cli_ul( | ||
c( | ||
"The SystemRequirements field in the {.file DESCRIPTION} file is already set.", | ||
"Please update it manually if needed." | ||
) | ||
) | ||
} | ||
|
||
invisible(version) | ||
|
||
} |