Skip to content

Commit

Permalink
Add CALLR_NO_TEMP_DLLS env var
Browse files Browse the repository at this point in the history
Closes #273.
  • Loading branch information
gaborcsardi committed Mar 25, 2024
1 parent 3109ec3 commit 72175f7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/load-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ load_client_lib <- function(sofile = NULL, pxdir = NULL) {
# install path since that library might be shared (e.g. in tests)
need_cleanup <- TRUE

if (is.null(sofile)) {
if (is.null(sofile) || Sys.getenv("CALLR_NO_TEMP_DLLS", "false") == "true") {
sofile <- sofile_in_processx()
lib <- dyn.load(sofile)
need_cleanup <- FALSE
Expand Down
13 changes: 13 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ callr::rcmd("config", "CC")

This returns a list with three components: the standard output, the standard error, and the exit (status) code of the `R CMD` command.

## Configuration

### Environment variables

* `CALLR_NO_TEMP_DLLS`: If `true`, then callr does not use a temporary
directory to copy the client DLL files from, in the subprocess. By
default callr copies the DLL file that drives the callr subprocess into
a temporary directory and loads it from there. This is mainly to avoid
locking a DLL file in the package library, on Windows. If this default
causes issues for you, set it to `true`, and then callr will use the DLL
file from the installed processx package. See also
https://github.com/r-lib/callr/issues/273.

## Code of Conduct

Please note that the callr project is released with a
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,19 @@ callr::rcmd("config", "CC")
This returns a list with three components: the standard output, the
standard error, and the exit (status) code of the `R CMD` command.

## Configuration

### Environment variables

* `CALLR_NO_TEMP_DLLS`: If `true`, then callr does not use a temporary
directory to copy the client DLL files from, in the subprocess. By
default callr copies the DLL file that drives the callr subprocess into
a temporary directory and loads it from there. This is mainly to avoid
locking a DLL file in the package library, on Windows. If this default
causes issues for you, set it to `true`, and then callr will use the DLL
file from the installed processx package. See also
https://github.com/r-lib/callr/issues/273.

## Code of Conduct

Please note that the callr project is released with a [Contributor Code
Expand Down
23 changes: 22 additions & 1 deletion tests/testthat/test-load-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test_that("set_stdout_file, set_setderr_file", {
c(readLines(f1), readLines(f2))
}

ret <- callr::r(do)
ret <- callr::r(do)
expect_equal(ret, c("this is output", "this is error"))
})

Expand All @@ -109,3 +109,24 @@ test_that("init function of client lib is run", {
# init function
expect_false(unclass(pxlib$.lib)$dynamicLookup)
})

test_that("CALLR_NO_TEMP_DLLS", {
skip_on_cran()
if (.Platform$OS.type != "windows") skip("Windows only")

# If not set, then it should come from the temporary location
withr::local_envvar(CALLR_NO_TEMP_DLLS = NA_character_)
dlls <- callr::r(function() ps::ps_shared_libs())$path
px <- grep("processx.*client.dll", dlls)
cr <- grep("callr.*client.dll", dlls)
expect_true(length(px) == 0)
expect_true(length(cr) >= 1)

# If set, then it should come from processx
withr::local_envvar(CALLR_NO_TEMP_DLLS = "true")
dlls <- callr::r(function() ps::ps_shared_libs())$path
px <- grep("processx.*client.dll", dlls)
cr <- grep("callr.*client.dll", dlls)
expect_true(length(px) >= 1)
expect_true(length(cr) == 0)
})

0 comments on commit 72175f7

Please sign in to comment.