Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable control over debug builds #93

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dust2
Title: Next Generation dust
Version: 0.1.10
Version: 0.1.11
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "rich.fitzjohn@gmail.com"),
person("Imperial College of Science, Technology and Medicine",
Expand Down
18 changes: 15 additions & 3 deletions R/compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
##' anything in your personal `Makevars`
##'
##' @param debug Passed to [pkgbuild::compile_dll], this will build a
##' debug library.
##' debug library. If `NULL` is given, then we take the value from
##' `DUST_DEBUG` if set, or `FALSE` otherwise.
##'
##' @param skip_cache Logical, indicating if the cache of previously
##' compiled systems should be skipped. If `TRUE` then your system will
Expand All @@ -77,7 +78,10 @@
dust_compile <- function(filename, quiet = NULL, workdir = NULL,
linking_to = NULL, cpp_std = NULL,
compiler_options = NULL, optimisation_level = NULL,
debug = FALSE, skip_cache = FALSE) {
debug = NULL, skip_cache = FALSE) {
quiet <- dust_quiet(quiet)
debug <- dust_quiet(debug)

stop_unless_installed(dust_compile_needs())
config <- parse_metadata(filename, call = environment())
mangle <- substr(rlang::hash_file(filename), 1, 8)
Expand All @@ -94,7 +98,6 @@ dust_compile <- function(filename, quiet = NULL, workdir = NULL,
}

workdir <- dust_workdir(workdir, hash)
quiet <- dust_quiet(quiet)

## Second round of substitution in here, in order to sub in the work
## directory now that we have it:
Expand Down Expand Up @@ -306,3 +309,12 @@ dust_quiet <- function(quiet, call = parent.frame()) {
assert_scalar_logical(quiet, call = call)
}
}


dust_debug <- function(debug, call = parent.frame()) {
if (is.null(debug)) {
envvar_is_truthy("DUST_DEBUG")
} else {
assert_scalar_logical(debug, call = call)
}
}
5 changes: 3 additions & 2 deletions man/dust_compile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/testthat/test-compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,18 @@ test_that("quiet responds to envvar", {
expect_false(dust_quiet(FALSE))
})
})


test_that("debug responds to envvar", {
withr::with_envvar(c(DUST_DEBUG = NA_character_), {
expect_false(dust_debug(NULL))
expect_false(dust_debug(FALSE))
expect_true(dust_debug(TRUE))
expect_error(dust_debug(1), "Expected 'debug' to be logical")
})

withr::with_envvar(c(DUST_DEBUG = "true"), {
expect_true(dust_debug(NULL))
expect_false(dust_debug(FALSE))
})
})
4 changes: 3 additions & 1 deletion vignettes/details.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ knitr::opts_chunk$set(

If you set this environment variable, then we'll create models here, each with a name in the pattern `dust_<hash>` where `<hash>` is the hash of the generated code. This means that if your model changes we'll still recompile it.

`DUST_QUIET`: an environment variable which controls the default level of verbosity when compiling dust models. Set this to a truthy value (e.g., `TRUE`) to change the default. This can always be overridden by providing a value for the `quiet` argument to `dust_compile` and `dust_package`.
`DUST_QUIET`: an environment variable which controls the default level of verbosity when compiling dust models. Set this to a truthy value (e.g., `TRUE`) to change the default. This can always be overridden by providing a value for the `quiet` argument to [dust_compile()] and [dust_package()].

`DUST_DEBUG`: an environment variable which controls how [pkgload::compile_dll] compiles the C++ code. Set this to a truthy value (e.g., `TRUE`) to disable optimisation, which allows faster compilation at the cost of slower runtime. This can be overridden by the `debug` argument to [dust_compile()].