Skip to content

Commit

Permalink
Support ?ignore-build-errors parameter
Browse files Browse the repository at this point in the history
Not documented yet.
  • Loading branch information
gaborcsardi committed Feb 9, 2024
1 parent fcdfa2b commit 2d65d98
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 7 deletions.
23 changes: 18 additions & 5 deletions R/install-plan.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ handle_event <- function(state, evidx) {
worker <- state$workers[[evidx]]
state$workers[evidx] <- list(NULL)

## Post-process, this will throw on error
if (is.function(proc$get_result)) proc$get_result()

## Cut stdout to lines
Expand Down Expand Up @@ -690,6 +689,7 @@ stop_task_build <- function(state, worker) {
version <- state$plan$version[pkgidx]
time <- Sys.time() - state$plan$build_time[[pkgidx]]
ptime <- format_time$pretty_sec(as.numeric(time, units = "secs"))
prms <- state$plan$params[[pkgidx]]

if (success) {
alert("success", paste0(
Expand All @@ -699,7 +699,14 @@ stop_task_build <- function(state, worker) {
## Need to save the name of the built package
state$plan$file[pkgidx] <- worker$process$get_built_file()
} else {
alert("danger", "Failed to build {.pkg {pkg}} {.version {version}}")
ignore_error <- is_true_param(prms, "ignore-build-errors")
alert(
if (ignore_error) "warning" else "danger",
paste0(
"Failed to build {.pkg {pkg}} {.version {version}}",
if (isTRUE(state$config$show_time)) " {.timestamp {ptime}}"
)
)
}
update_progress_bar(state, 1L)

Expand All @@ -709,7 +716,14 @@ stop_task_build <- function(state, worker) {
state$plan$build_stdout[[pkgidx]] <- worker$stdout
state$plan$worker_id[[pkgidx]] <- NA_character_

if (!success) {
if (success) {
# do nothing
} else if (ignore_error) {
# upstream will probably fail as well, but march on, neverthelesss
state$plan$install_done[[pkgidx]] <- TRUE
## Need to remove from the dependency list
state$plan$deps_left <- lapply(state$plan$deps_left, setdiff, pkg)
} else {
throw(pkg_error(
"Failed to build source package {.pkg {pkg}}.",
.data = list(
Expand All @@ -722,8 +736,7 @@ stop_task_build <- function(state, worker) {
))
}

prms <- state$plan$params[[pkgidx]]
if (!is.null(state$cache) && !is_true_param(prms, "nocache")) {
if (success && !is.null(state$cache) && !is_true_param(prms, "nocache")) {
ptfm <- current_r_platform()
rv <- current_r_version()
target <- paste0(state$plan$target[pkgidx], "-", ptfm, "-", rv)
Expand Down
4 changes: 2 additions & 2 deletions R/parse-remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ add_ref_params <- function(res, params) {
res
}

known_query_params <- c("ignore", "ignore-before-r", "nocache",
"reinstall", "source")
known_query_params <- c("ignore", "ignore-before-r", "ignore-build-errors",
"nocache", "reinstall", "source")

parse_query <- function(ref) {
query <- sub("^[^?]*(\\?|$)", "", ref)
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/_snaps/install-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,35 @@
character(0)

# ignore-build-errors parameter

Code
suppressMessages(inst$solve())
suppressMessages(inst$download())
inst$install()
Message
i Packaging badbuild 1.0.0
v Packaged badbuild 1.0.0
i Building badbuild 1.0.0
x Failed to build badbuild 1.0.0
Condition
Error:
! Failed to build source package badbuild.

---

Code
suppressMessages(inst$solve())
suppressMessages(inst$download())
inst$install()
Message
i Packaging badbuild 1.0.0
v Packaged badbuild 1.0.0
i Building badbuild 1.0.0
! Failed to build badbuild 1.0.0
i Packaging goodbuild 1.0.0
v Packaged goodbuild 1.0.0
i Building goodbuild 1.0.0
! Failed to build goodbuild 1.0.0
v Summary: 2 new

9 changes: 9 additions & 0 deletions tests/testthat/fixtures/packages/badbuild/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: badbuild
Title: Title
Version: 1.0.0
Author: Gábor Csárdi
Maintainer: Gábor Csárdi <[email protected]>
Description: Test package.
License: MIT + file LICENSE
LazyData: true
Encoding: UTF-8
Empty file.
2 changes: 2 additions & 0 deletions tests/testthat/fixtures/packages/badbuild/R/foo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is an error, sorry!
fun <- function() NULL
11 changes: 11 additions & 0 deletions tests/testthat/fixtures/packages/goodbuild/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: goodbuild
Title: Title
Version: 1.0.0
Author: Gábor Csárdi
Maintainer: Gábor Csárdi <[email protected]>
Description: Test package.
License: MIT + file LICENSE
LazyData: true
Imports:
badbuild
Encoding: UTF-8
Empty file.
1 change: 1 addition & 0 deletions tests/testthat/fixtures/packages/goodbuild/R/foo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fun <- function() NULL
28 changes: 28 additions & 0 deletions tests/testthat/test-install-plan.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ test_that("add_recursive_dependencies", {
expect_snapshot(add_recursive_dependencies(plan)$dependencies)
})

test_that("ignore-build-errors parameter", {
setup_fake_apps()
local_cli_config()
dir.create(tmplib <- tempfile())
on.exit(rimraf(tmplib), add = TRUE)
pkgdir1 <- test_path("fixtures", "packages", "badbuild")
pkgdir2 <- test_path("fixtures", "packages", "goodbuild")
inst <- new_pkg_installation_proposal(
paste0("local::", c(pkgdir1, pkgdir2), "?nocache"),
config = list(library = tmplib, platforms = "source")
)
expect_snapshot({
suppressMessages(inst$solve())
suppressMessages(inst$download())
inst$install()
}, error = TRUE)

inst <- new_pkg_installation_proposal(
paste0("local::", c(pkgdir1, pkgdir2), "?nocache&ignore-build-errors"),
config = list(library = tmplib, platforms = "source")
)
expect_snapshot({
suppressMessages(inst$solve())
suppressMessages(inst$download())
inst$install()
})
})

test_that("install package from GH", {
setup_fake_apps()
setup_fake_gh_app()
Expand Down

0 comments on commit 2d65d98

Please sign in to comment.