Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ linters: linters_with_defaults(
encoding: "UTF-8"
exclusions: list(
"R/import-standalone-obj-type.R"
)
)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Added `use_msrv()` to aid in specifying the minimum supported rust version (MSRV) for an R package
* Added `read_cargo_metadata()` to retrieve Cargo metadata for packages and
workspaces. (#389)
* `rustup_sitrep()` now checks if a default toolchain has been set. <https://github.com/extendr/rextendr/pull/416>

# rextend 0.3.1

Expand Down
14 changes: 10 additions & 4 deletions R/rust_sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@
# ----------------
#
# stable-x86_64-pc-windows-msvc (default)
host <- try_exec_cmd("rustup", "show") %>%
stringi::stri_sub(from = 15L) %>%
vctrs::vec_slice(1L)
host <- if (get_os() == "osx" && is.na(try_exec_cmd("rustup", "show"))) {
output <- try_exec_cmd("rustc", c("--version", "--verbose"))
host_index <- grep("host:", output)
gsub("host: ", "", output[host_index])

Check warning on line 121 in R/rust_sitrep.R

View check run for this annotation

Codecov / codecov/patch

R/rust_sitrep.R#L119-L121

Added lines #L119 - L121 were not covered by tests
} else {
try_exec_cmd("rustup", "show") %>%
stringi::stri_sub(from = 15L) %>%
vctrs::vec_slice(1L)
}

# > rustup toolchain list
# stable-x86_64-pc-windows-msvc
Expand Down Expand Up @@ -177,7 +183,7 @@
} else {
toolchains[default_toolchain_index] <- cli::col_red(toolchains[default_toolchain_index])
candidates <- stringi::stri_detect_fixed(toolchains, host)
if (any(candidates)) {
if (!all(is.na(candidates)) && any(candidates)) {
candidate_toolchains <- toolchains[candidates]
toolchains[candidates] <- cli::col_yellow(toolchains[candidates])
} else {
Expand Down
16 changes: 16 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@
}
data
}

get_os <- function() {
sysinf <- Sys.info()
if (!is.null(sysinf)) {
os <- sysinf["sysname"]
if (os == "Darwin")
os <- "osx"

Check warning on line 86 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L86

Added line #L86 was not covered by tests
} else { ## mystery machine
os <- .Platform$OS.type
if (grepl("^darwin", R.version$os))
os <- "osx"
if (grepl("linux-gnu", R.version$os))
os <- "linux"

Check warning on line 92 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L88-L92

Added lines #L88 - L92 were not covered by tests
}
tolower(os)
}
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/rust-sitrep.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@
! Target required-target is required on this host machine
i Run `rustup target add required-target` to install it

# Detects host when default toolchain is not set (MacOS)

Code
rust_sitrep()
Message
Rust infrastructure sitrep:
v "rustup": 1.0.0 (0000000 0000-00-00)
v "cargo": 1.0.0 (0000000 0000-00-00)
i host: aarch64-apple-darwin
i toolchain: stable-aarch64-apple-darwin
! This toolchain should be default: stable-aarch64-apple-darwin
i Run e.g. `rustup default stable-aarch64-apple-darwin`

24 changes: 24 additions & 0 deletions tests/testthat/test-rust-sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,27 @@ test_that("Required target is not available", {
})
expect_snapshot(rust_sitrep())
})

test_that("Detects host when default toolchain is not set (MacOS)", {
skip_if_not(get_os() == "osx")

local_mocked_bindings(try_exec_cmd = function(cmd, args) {
if (cmd == "cargo") {
"cargo 1.0.0 (0000000 0000-00-00)"
} else if (cmd == "rustup" & all(args %in% "--version")) {
"rustup 1.0.0 (0000000 0000-00-00)"
} else if (cmd == "rustc") {
"host: aarch64-apple-darwin"
} else if (all(args %in% "--version")) {
"rustup 1.0.0 (0000000 0000-00-00)"
NA_character_
} else if (all(args %in% c("toolchain", "list"))) {
"stable-aarch64-apple-darwin"
} else if (all(args %in% c("target", "list", "--installed"))) {
NA_character_
} else {
NA_character_
}
})
expect_snapshot(rust_sitrep())
})
5 changes: 5 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ test_that("`try_exec_cmd()` returns stdout when command is available", {
expect_equal(try_exec_cmd("echo", echo), echo)
})

test_that("`get_os()` returns a non-empty string", {
os <- get_os()
expect_true(is.character(os))
expect_true(nzchar(os))
})

test_that("`replace_na()` respects type", {
x <- 1:5
Expand Down
Loading