Skip to content

Commit c08867e

Browse files
committed
Treat computed make refs as uncached
Finding: [P2] Treat computed Make variable names as uncached — /Users/tomasz/github/t-kalinowski/quickr/R/aaa-utils.R:752-752 Resolution: computed variable names with nested make references are now treated as dynamic inputs and bypass successful-probe caching. Added a regression test for FC resolved through a ROOT suffix variable.
1 parent 886c9d1 commit c08867e

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

R/aaa-utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ quickr_text_has_makevars_uncached_function <- function(text) {
749749
function_pattern <- "\\$\\([A-Za-z_][A-Za-z0-9_.-]*[[:space:]]|\\$\\{[A-Za-z_][A-Za-z0-9_.-]*[[:space:]]"
750750
substitution_pattern <- "\\$\\([A-Za-z_][A-Za-z0-9_.-]*:[^)]*\\)|\\$\\{[A-Za-z_][A-Za-z0-9_.-]*:[^}]*\\}"
751751
shell_assignment_pattern <- "^[[:space:]]*(?:(?:export|override|private)[[:space:]]+)*[A-Za-z_][A-Za-z0-9_.-]*[[:space:]]*!="
752-
indirect_ref_pattern <- "\\$[({]\\$[({]"
752+
indirect_ref_pattern <- "\\$[({][^)}]*\\$[({]"
753753
any(grepl(
754754
paste(
755755
function_pattern,

tests/testthat/test-compiler-cache.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,42 @@ test_that("quickr_cached_r_cmd_config_value retries Makevars with indirect refs"
12111211
expect_equal(calls, 2L)
12121212
})
12131213

1214+
test_that("quickr_cached_r_cmd_config_value retries Makevars with computed refs", {
1215+
cache <- new.env(parent = emptyenv())
1216+
makevars <- withr::local_tempfile()
1217+
writeLines(
1218+
c(
1219+
"SUFFIX = A",
1220+
"FC = $(ROOT_$(SUFFIX))"
1221+
),
1222+
makevars
1223+
)
1224+
calls <- 0L
1225+
local_mocked_bindings(
1226+
quickr_r_cmd_config_probe = function(name) {
1227+
calls <<- calls + 1L
1228+
list(value = paste0("value-", calls), ok = TRUE)
1229+
},
1230+
.package = "quickr"
1231+
)
1232+
withr::local_envvar(c(
1233+
ROOT_A = "gfortran",
1234+
R_MAKEVARS_USER = makevars
1235+
))
1236+
1237+
expect_identical(
1238+
quickr_cached_r_cmd_config_value("FC", cache = cache),
1239+
"value-1"
1240+
)
1241+
1242+
withr::local_envvar(ROOT_A = "flang")
1243+
expect_identical(
1244+
quickr_cached_r_cmd_config_value("FC", cache = cache),
1245+
"value-2"
1246+
)
1247+
expect_equal(calls, 2L)
1248+
})
1249+
12141250
test_that("quickr_cached_r_cmd_config_value keys on MAKEFILES content", {
12151251
cache <- new.env(parent = emptyenv())
12161252
makefile <- withr::local_tempfile()

0 commit comments

Comments
 (0)