Skip to content

Commit

Permalink
Merge pull request #307 from ropensci/fix-proc-nix-build-sigint
Browse files Browse the repository at this point in the history
- `nix_build()`: Fix SIGINT termination (ctrl+c) for linux, so that all the `nix-build` background processes are properly stopped for user interrupts.
  • Loading branch information
philipp-baumann authored Sep 19, 2024
2 parents 3ee9962 + a1cdf47 commit c424cf7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
8 changes: 8 additions & 0 deletions R/nix_build_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ poll_sys_proc_nonblocking <- function(cmd,

status <- sys::exec_status(proc, wait = TRUE)

if (is.na(status)) {
tools::pskill(pid = proc)
stop(
"`nix_build()` likely interrupted by SIGINT (ctrl+c)\n",
"Stop process with PID ", proc
)
}

if (isFALSE(is_quiet)) {
if (status == 0L) {
cat(paste0("\n==> `", what, "` succeeded!"))
Expand Down
10 changes: 6 additions & 4 deletions R/with_nix.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,12 @@ with_nix <- function(expr,
if (nzchar(LD_LIBRARY_PATH_default)) {
# set old LD_LIBRARY_PATH (only if system's R session and if it wasn't
# `""`)
on.exit({
Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default)
},
add = TRUE)
on.exit(
{
Sys.setenv(LD_LIBRARY_PATH = LD_LIBRARY_PATH_default)
},
add = TRUE
)
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-fetchers.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
testthat::test_that("Test fetchgit works", {
testthat::skip_on_cran()
testthat::expect_equal(
fetchgit(
list(
Expand All @@ -12,6 +13,7 @@ testthat::test_that("Test fetchgit works", {
})

testthat::test_that("Test fetchgit fails gracefully", {
testthat::skip_on_cran()
testthat::expect_error(
fetchgit(
list(
Expand All @@ -24,6 +26,7 @@ testthat::test_that("Test fetchgit fails gracefully", {
})

testthat::test_that("Test fetchgit works with gitlab packages", {
testthat::skip_on_cran()
testthat::expect_equal(
fetchgit(
list(
Expand All @@ -39,20 +42,23 @@ testthat::test_that("Test fetchgit works with gitlab packages", {


testthat::test_that("Test fetchzip works", {
testthat::skip_on_cran()
testthat::expect_equal(
fetchzip("AER@1.2-8"),
"\n (pkgs.rPackages.buildRPackage {\n name = \"AER\";\n src = pkgs.fetchzip {\n url = \"https://cran.r-project.org/src/contrib/Archive/AER/AER_1.2-8.tar.gz\";\n sha256 = \"sha256-OqxXcnUX/2C6wfD5fuNayc8OU+mstI3tt4eBVGQZ2S0=\";\n };\n propagatedBuildInputs = builtins.attrValues {\n inherit (pkgs.rPackages) \n car\n lmtest\n sandwich\n survival\n zoo\n Formula;\n };\n })\n"
)
})

testthat::test_that("Test fetchzip fails gracefully", {
testthat::skip_on_cran()
testthat::expect_error(
fetchzip("AER@999999"),
"Are these correct?"
)
})

testthat::test_that("Test fetchgits", {
testthat::skip_on_cran()
testthat::expect_equal(
fetchgits(
list(
Expand All @@ -73,6 +79,7 @@ testthat::test_that("Test fetchgits", {
})

testthat::test_that("Test fetchzips works", {
testthat::skip_on_cran()
testthat::expect_equal(
fetchzips(
c("dplyr@0.8.0", "AER@1.2-8")
Expand All @@ -83,6 +90,7 @@ testthat::test_that("Test fetchzips works", {


testthat::test_that("Test fetchpkgs works", {
testthat::skip_on_cran()
testthat::expect_equal(
fetchpkgs(
git_pkgs = list(
Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/test-rix.R
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,14 @@ testthat::test_that("rix(), frozen_edge", {
)


on.exit({
system(
paste0("sed -i 's/", frozen_edge_commit, "/REVISION/' _snaps/rix/frozen_edge_default.nix")
)
unlink(path_default_nix, recursive = TRUE, force = FALSE)
},
add = TRUE
on.exit(
{
system(
paste0("sed -i 's/", frozen_edge_commit, "/REVISION/' _snaps/rix/frozen_edge_default.nix")
)
unlink(path_default_nix, recursive = TRUE, force = FALSE)
},
add = TRUE
)
})

Expand Down

0 comments on commit c424cf7

Please sign in to comment.