-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathwith-debug.R
More file actions
89 lines (78 loc) · 1.86 KB
/
with-debug.R
File metadata and controls
89 lines (78 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#' Temporarily set debugging compilation flags.
#'
#' @param code to execute.
#' @param CFLAGS flags for compiling C code
#' @param CXXFLAGS flags for compiling C++ code
#' @param FFLAGS flags for compiling Fortran code.
#' @param FCFLAGS flags for Fortran 9x code.
#' @inheritParams compiler_flags
#' @family debugging flags
#' @export
#' @examples
#' flags <- names(compiler_flags(TRUE))
#' with_debug(Sys.getenv(flags))
#' \dontrun{
#' install("mypkg")
#' with_debug(install("mypkg"))
#' }
with_debug <- function(
code,
CFLAGS = NULL,
CXXFLAGS = NULL,
FFLAGS = NULL,
FCFLAGS = NULL,
debug = TRUE
) {
defaults <- compiler_flags(debug = debug)
flags <- c(
CFLAGS = CFLAGS,
CXXFLAGS = CXXFLAGS,
FFLAGS = FFLAGS,
FCFLAGS = FCFLAGS
)
flags <- unlist(utils::modifyList(as.list(defaults), as.list(flags)))
withr_with_makevars(flags, code)
}
#' Tools for testing pkgbuild
#'
#' `with_compiler` temporarily disables code compilation by setting
#' `CC`, `CXX`, makevars to `test`. `without_cache`
#' resets the cache before and after running `code`.
#'
#' @param code Code to execute with broken compilers
#' @export
without_compiler <- function(code) {
flags <- c(
CC = "test",
CXX = "test",
CXX11 = "test",
FC = "test"
)
if (is_windows()) {
without_cache({
cache_set("rtools_path", "")
withr_with_makevars(flags, code)
})
} else {
without_cache({
withr_with_makevars(flags, code)
})
}
}
#' @export
#' @rdname without_compiler
without_cache <- function(code) {
cache_reset()
on.exit(cache_reset())
code
}
#' @export
#' @rdname without_compiler
without_latex <- function(code) {
withr_with_options(list(PKGBUILD_TEST_FIXTURE_HAS_LATEX = FALSE), code)
}
#' @export
#' @rdname without_compiler
with_latex <- function(code) {
withr_with_options(list(PKGBUILD_TEST_FIXTURE_HAS_LATEX = TRUE), code)
}