Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# devtools (development version)

* `build_manual()` reports more details on failure (#2586).
* New `check_mac_devel()` function to check a package using the macOS builder at https://mac.r-project.org/macbuilder/submit.html (@nfrerebeau, #2507)
* `is_loading()` is now re-exported from pkgload (#2556).
* `load_all()` now errors if called recursively, i.e. if you accidentally include a `load_all()` call in one of your R source files (#2617).
Expand Down
37 changes: 20 additions & 17 deletions R/build-manual.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@
build_manual <- function(pkg = ".", path = NULL) {
pkg <- as.package(pkg)
path <- path %||% path_dir(pkg$path)
name <- paste0(pkg$package, "_", pkg$version, ".pdf", collapse = " ")
tryCatch(
msg <- callr::rcmd(
"Rd2pdf",
cmdargs = c(
"--force",
paste0("--output=", path, "/", name),
pkg$path
),
fail_on_status = TRUE,
stderr = "2>&1",
spinner = FALSE
),
name <- paste0(pkg$package, "_", pkg$version, ".pdf")
output <- file.path(path, name)

cli::cli_inform("Saving manual to {.file {output}}")
withCallingHandlers(
invisible(rd2pdf(pkg$path, output)),
error = function(e) {
cat(e$stdout)
cli::cli_abort("Failed to build manual")
cli::cli_abort(
c("Failed to build manual.", no_wrap(e$stderr)),
call = quote(build_manual()),
parent = e
)
}
)
}

cat(msg$stdout)
invisible(msg)
rd2pdf <- function(pkg_path, output_path) {
callr::rcmd(
"Rd2pdf",
cmdargs = c("--force", paste0("--output=", output_path), pkg_path),
stdout = "",
fail_on_status = TRUE,
spinner = FALSE
)
}
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ is_testing <- function() {
is_rstudio_running <- function() {
!is_testing() && rstudioapi::isAvailable()
}

# Suppress cli wrapping
no_wrap <- function(x) {
x <- gsub(" ", "\u00a0", x, fixed = TRUE)
x <- gsub("\n", "\f", x, fixed = TRUE)
x
}
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/build-manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# build_manual() shows stderr on failure

Code
build_manual(pkg)
Message
Saving manual to '<pkgdir>_0.0.0.9000.pdf'
Condition
Error in `build_manual()`:
! Failed to build manual.
! LaTeX Error: File `inconsolata.sty' not found.
Caused by error in `rd2pdf()`:
! System command 'R' failed

17 changes: 17 additions & 0 deletions tests/testthat/test-build-manual.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test_that("build_manual() shows stderr on failure", {
skip_on_os("windows")

pkg <- local_package_create()
pkg <- normalizePath(pkg)

# Too hard to replicate actual error, so we just simulate
local_mocked_bindings(rd2pdf = function(...) {
stderr <- "! LaTeX Error: File `inconsolata.sty' not found."
rlang::abort("System command 'R' failed", stderr = stderr) #nolint
})

expect_snapshot(build_manual(pkg), error = TRUE, transform = function(x) {
x <- gsub(pkg, "<pkgdir>", x, fixed = TRUE)
x
})
})