Skip to content

Commit 273c6ff

Browse files
committed
Treat indirect ifdef names as uncached
Finding: [P2] Track env vars behind indirect ifdef names — /Users/tomasz/github/t-kalinowski/quickr/R/aaa-utils.R:799-800 Resolution: indirect ifdef and ifndef names now match the dynamic-input detector, so probes guarded by those conditionals bypass successful-result caching. Added a regression test for direct FC assignments behind an indirect ifdef name.
1 parent 972ff96 commit 273c6ff

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

R/aaa-utils.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,14 @@ quickr_text_has_makevars_uncached_function <- function(text) {
768768
substitution_pattern <- "\\$\\([A-Za-z_][A-Za-z0-9_.-]*:[^)]*\\)|\\$\\{[A-Za-z_][A-Za-z0-9_.-]*:[^}]*\\}"
769769
shell_assignment_pattern <- "^[[:space:]]*(?:(?:export|override|private)[[:space:]]+)*[A-Za-z_][A-Za-z0-9_.-]*[[:space:]]*!="
770770
indirect_ref_pattern <- "\\$[({][^)}]*\\$[({]"
771+
indirect_conditional_pattern <- "^[[:space:]]*(?:else[[:space:]]+)?ifn?def[[:space:]]+\\$[({]"
771772
any(grepl(
772773
paste(
773774
function_pattern,
774775
substitution_pattern,
775776
shell_assignment_pattern,
776777
indirect_ref_pattern,
778+
indirect_conditional_pattern,
777779
sep = "|"
778780
),
779781
text,

tests/testthat/test-compiler-cache.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,46 @@ test_that("quickr_cached_r_cmd_config_value expands ifdef variable names", {
11571157
expect_equal(calls, 2L)
11581158
})
11591159

1160+
test_that("quickr_cached_r_cmd_config_value retries direct assignments behind indirect ifdef names", {
1161+
cache <- new.env(parent = emptyenv())
1162+
makevars <- withr::local_tempfile()
1163+
writeLines(
1164+
c(
1165+
"FLAG_NAME = USE_A",
1166+
"ifdef $(FLAG_NAME)",
1167+
"FC=gfortran",
1168+
"else",
1169+
"FC=flang",
1170+
"endif"
1171+
),
1172+
makevars
1173+
)
1174+
calls <- 0L
1175+
local_mocked_bindings(
1176+
quickr_r_cmd_config_probe = function(name) {
1177+
calls <<- calls + 1L
1178+
list(value = paste0("value-", calls), ok = TRUE)
1179+
},
1180+
.package = "quickr"
1181+
)
1182+
withr::local_envvar(c(
1183+
R_MAKEVARS_USER = makevars,
1184+
USE_A = "1"
1185+
))
1186+
1187+
expect_identical(
1188+
quickr_cached_r_cmd_config_value("FC", cache = cache),
1189+
"value-1"
1190+
)
1191+
1192+
withr::local_envvar(USE_A = NA)
1193+
expect_identical(
1194+
quickr_cached_r_cmd_config_value("FC", cache = cache),
1195+
"value-2"
1196+
)
1197+
expect_equal(calls, 2L)
1198+
})
1199+
11601200
test_that("quickr_cached_r_cmd_config_value retries Makevars with wildcard assignments", {
11611201
cache <- new.env(parent = emptyenv())
11621202
root <- withr::local_tempdir()

0 commit comments

Comments
 (0)