Skip to content

Commit 72175f7

Browse files
committed
Add CALLR_NO_TEMP_DLLS env var
Closes #273.
1 parent 3109ec3 commit 72175f7

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

R/load-client.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ load_client_lib <- function(sofile = NULL, pxdir = NULL) {
2727
# install path since that library might be shared (e.g. in tests)
2828
need_cleanup <- TRUE
2929

30-
if (is.null(sofile)) {
30+
if (is.null(sofile) || Sys.getenv("CALLR_NO_TEMP_DLLS", "false") == "true") {
3131
sofile <- sofile_in_processx()
3232
lib <- dyn.load(sofile)
3333
need_cleanup <- FALSE

README.Rmd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ callr::rcmd("config", "CC")
227227

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

230+
## Configuration
231+
232+
### Environment variables
233+
234+
* `CALLR_NO_TEMP_DLLS`: If `true`, then callr does not use a temporary
235+
directory to copy the client DLL files from, in the subprocess. By
236+
default callr copies the DLL file that drives the callr subprocess into
237+
a temporary directory and loads it from there. This is mainly to avoid
238+
locking a DLL file in the package library, on Windows. If this default
239+
causes issues for you, set it to `true`, and then callr will use the DLL
240+
file from the installed processx package. See also
241+
https://github.com/r-lib/callr/issues/273.
242+
230243
## Code of Conduct
231244

232245
Please note that the callr project is released with a

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ callr::rcmd("config", "CC")
346346
This returns a list with three components: the standard output, the
347347
standard error, and the exit (status) code of the `R CMD` command.
348348

349+
## Configuration
350+
351+
### Environment variables
352+
353+
* `CALLR_NO_TEMP_DLLS`: If `true`, then callr does not use a temporary
354+
directory to copy the client DLL files from, in the subprocess. By
355+
default callr copies the DLL file that drives the callr subprocess into
356+
a temporary directory and loads it from there. This is mainly to avoid
357+
locking a DLL file in the package library, on Windows. If this default
358+
causes issues for you, set it to `true`, and then callr will use the DLL
359+
file from the installed processx package. See also
360+
https://github.com/r-lib/callr/issues/273.
361+
349362
## Code of Conduct
350363

351364
Please note that the callr project is released with a [Contributor Code

tests/testthat/test-load-client.R

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test_that("set_stdout_file, set_setderr_file", {
8989
c(readLines(f1), readLines(f2))
9090
}
9191

92-
ret <- callr::r(do)
92+
ret <- callr::r(do)
9393
expect_equal(ret, c("this is output", "this is error"))
9494
})
9595

@@ -109,3 +109,24 @@ test_that("init function of client lib is run", {
109109
# init function
110110
expect_false(unclass(pxlib$.lib)$dynamicLookup)
111111
})
112+
113+
test_that("CALLR_NO_TEMP_DLLS", {
114+
skip_on_cran()
115+
if (.Platform$OS.type != "windows") skip("Windows only")
116+
117+
# If not set, then it should come from the temporary location
118+
withr::local_envvar(CALLR_NO_TEMP_DLLS = NA_character_)
119+
dlls <- callr::r(function() ps::ps_shared_libs())$path
120+
px <- grep("processx.*client.dll", dlls)
121+
cr <- grep("callr.*client.dll", dlls)
122+
expect_true(length(px) == 0)
123+
expect_true(length(cr) >= 1)
124+
125+
# If set, then it should come from processx
126+
withr::local_envvar(CALLR_NO_TEMP_DLLS = "true")
127+
dlls <- callr::r(function() ps::ps_shared_libs())$path
128+
px <- grep("processx.*client.dll", dlls)
129+
cr <- grep("callr.*client.dll", dlls)
130+
expect_true(length(px) >= 1)
131+
expect_true(length(cr) == 0)
132+
})

0 commit comments

Comments
 (0)