Skip to content

Commit

Permalink
Hopefully resolving the WSLv1 failures
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmodrak committed Aug 15, 2023
1 parent 8c51b53 commit 2a642f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
17 changes: 10 additions & 7 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -508,32 +508,35 @@ compile <- function(quiet = TRUE,
if (isTRUE(cpp_options$stan_opencl)) {
stanc_options[["use-opencl"]] <- TRUE
}
# Note that unlike cpp_options["USER_HEADER"], the user_header variable is deliberately
# not transformed with wsl_safe_path() as that breaks the check below on WSLv1
if (!is.null(user_header)) {
user_header <- wsl_safe_path(absolute_path(user_header))
cpp_options[["USER_HEADER"]] <- user_header
cpp_options[["USER_HEADER"]] <- wsl_safe_path(absolute_path(user_header))
stanc_options[["allow-undefined"]] <- TRUE
private$using_user_header_ <- TRUE
}
if (!is.null(cpp_options[["USER_HEADER"]])) {
user_header <- cpp_options[["USER_HEADER"]]
cpp_options[["USER_HEADER"]] <- wsl_safe_path(absolute_path(cpp_options[["USER_HEADER"]]))
private$using_user_header_ <- TRUE
user_header <- cpp_options[["USER_HEADER"]]
}
if (!is.null(cpp_options[["user_header"]])) {
user_header <- cpp_options[["user_header"]]
cpp_options[["user_header"]] <- wsl_safe_path(absolute_path(cpp_options[["user_header"]]))
private$using_user_header_ <- TRUE
user_header <- cpp_options[["user_header"]]
}
if (is.null(stanc_options[["name"]])) {
stanc_options[["name"]] <- paste0(self$model_name(), "_model")
}

user_header <- absolute_path(user_header) # As mentioned above, just absolute, not wsl_safe_path()
if(!is.null(user_header)) {
if(!file.exists(user_header)) {
stop(paste0("User header file '", user_header, "' does not exist"))
}
}

if (is.null(stanc_options[["name"]])) {
stanc_options[["name"]] <- paste0(self$model_name(), "_model")
}

# compile if:
# - the user forced compilation,
# - the executable does not exist
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ wsl_safe_path <- function(path = NULL, revert = FALSE) {
if (os_is_wsl() && !isTRUE(path_already_safe) && !is.na(path)) {
base_file <- basename(path)
path <- dirname(path)
abs_path <- repair_path(path)
abs_path <- repair_path(utils::shortPathName(path))
drive_letter <- tolower(strtrim(abs_path, 1))
path <- gsub(paste0(drive_letter, ":"),
paste0("/mnt/", drive_letter),
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-model-compile.R
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ test_that("cmdstan_model works with user_header", {
}
}"
cat(hpp, file = tmpfile, sep = "\n")
warning(paste0("tmpfile test: ", tmpfile))
mod <- cmdstan_model(
stan_file = testing_stan_file("bernoulli_external"),
user_header = tmpfile
Expand Down

0 comments on commit 2a642f4

Please sign in to comment.