Skip to content

Commit

Permalink
Fix Onedrive PATH issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jun 6, 2024
1 parent 6d914e9 commit 995e36f
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 107 deletions.
99 changes: 54 additions & 45 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,63 +453,72 @@ build_cmdstan <- function(dir,
} else {
run_cmd <- make_cmd()
}
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path(dir = dir)
),
wsl_compatible_run(
command = run_cmd,
args = c(translation_args, paste0("-j", cores), "build"),
wd = dir,
echo_cmd = is_verbose_mode(),
echo = !quiet || is_verbose_mode(),
spinner = quiet,
error_on_status = FALSE,
stderr_callback = function(x, p) { if (quiet) message(x) },
timeout = timeout
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path(dir = dir)
),
wsl_compatible_run(
command = run_cmd,
args = c(translation_args, paste0("-j", cores), "build"),
wd = dir,
echo_cmd = is_verbose_mode(),
echo = !quiet || is_verbose_mode(),
spinner = quiet,
error_on_status = FALSE,
stderr_callback = function(x, p) { if (quiet) message(x) },
timeout = timeout
)
)
)
}

clean_cmdstan <- function(dir = cmdstan_path(),
cores = getOption("mc.cores", 2),
quiet = FALSE) {
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path(dir = dir)
),
wsl_compatible_run(
command = make_cmd(),
args = "clean-all",
wd = dir,
echo_cmd = is_verbose_mode(),
echo = !quiet || is_verbose_mode(),
spinner = quiet,
error_on_status = FALSE,
stderr_callback = function(x, p) { if (quiet) message(x) }
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path(dir = dir)
),
wsl_compatible_run(
command = make_cmd(),
args = "clean-all",
wd = dir,
echo_cmd = is_verbose_mode(),
echo = !quiet || is_verbose_mode(),
spinner = quiet,
error_on_status = FALSE,
stderr_callback = function(x, p) { if (quiet) message(x) }
)
)
)
}

build_example <- function(dir, cores, quiet, timeout) {
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path(dir = dir)
),
wsl_compatible_run(
command = make_cmd(),
args = c(paste0("-j", cores),
cmdstan_ext(file.path("examples", "bernoulli", "bernoulli"))),
wd = dir,
echo_cmd = is_verbose_mode(),
echo = !quiet || is_verbose_mode(),
spinner = quiet,
error_on_status = FALSE,
stderr_callback = function(x, p) { if (quiet) message(x) },
timeout = timeout
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path(dir = dir)
),
wsl_compatible_run(
command = make_cmd(),
args = c(paste0("-j", cores),
cmdstan_ext(file.path("examples", "bernoulli", "bernoulli"))),
wd = dir,
echo_cmd = is_verbose_mode(),
echo = !quiet || is_verbose_mode(),
spinner = quiet,
error_on_status = FALSE,
stderr_callback = function(x, p) { if (quiet) message(x) },
timeout = timeout
)
)
)
}
Expand Down
91 changes: 47 additions & 44 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -664,54 +664,57 @@ compile <- function(quiet = TRUE,
if (compile_standalone) {
expose_stan_functions(self$functions, !quiet)
}

withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path()
),
run_log <- wsl_compatible_run(
command = make_cmd(),
args = c(wsl_safe_path(repair_path(tmp_exe)),
cpp_options_to_compile_flags(cpp_options),
stancflags_val),
wd = cmdstan_path(),
echo = !quiet || is_verbose_mode(),
echo_cmd = is_verbose_mode(),
spinner = quiet && rlang::is_interactive() && !identical(Sys.getenv("IN_PKGDOWN"), "true"),
stderr_callback = function(x, p) {
if (!startsWith(x, paste0(make_cmd(), ": *** No rule to make target"))) {
message(x)
}
if (grepl("PCH file", x) || grepl("precompiled header", x) || grepl(".hpp.gch", x) ) {
warning(
"CmdStan's precompiled header (PCH) files may need to be rebuilt.\n",
"If your model failed to compile please run rebuild_cmdstan().\n",
"If the issue persists please open a bug report.",
call. = FALSE
)
}
if (grepl("No space left on device", x) || grepl("error in backend: IO failure on output stream", x)) {
warning(
"The C++ compiler ran out of disk space and was unable to build the executables for your model!\n",
"See the above error for more details.",
call. = FALSE
)
}
if (os_is_macos()) {
if (R.version$arch == "aarch64"
&& grepl("but the current translation unit is being compiled for target", x)) {

withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path()
),
run_log <- wsl_compatible_run(
command = make_cmd(),
args = c(wsl_safe_path(repair_path(tmp_exe)),
cpp_options_to_compile_flags(cpp_options),
stancflags_val),
wd = cmdstan_path(),
echo = !quiet || is_verbose_mode(),
echo_cmd = is_verbose_mode(),
spinner = quiet && rlang::is_interactive() && !identical(Sys.getenv("IN_PKGDOWN"), "true"),
stderr_callback = function(x, p) {
if (!startsWith(x, paste0(make_cmd(), ": *** No rule to make target"))) {
message(x)
}
if (grepl("PCH file", x) || grepl("precompiled header", x) || grepl(".hpp.gch", x) ) {
warning(
"The C++ compiler has errored due to incompatibility between the x86 and ",
"Apple Silicon architectures.\n",
"If you are running R inside an IDE (RStudio, VSCode, ...), ",
"make sure the IDE is a native Apple Silicon app.\n",
"CmdStan's precompiled header (PCH) files may need to be rebuilt.\n",
"If your model failed to compile please run rebuild_cmdstan().\n",
"If the issue persists please open a bug report.",
call. = FALSE
)
}
}
},
error_on_status = FALSE
if (grepl("No space left on device", x) || grepl("error in backend: IO failure on output stream", x)) {
warning(
"The C++ compiler ran out of disk space and was unable to build the executables for your model!\n",
"See the above error for more details.",
call. = FALSE
)
}
if (os_is_macos()) {
if (R.version$arch == "aarch64"
&& grepl("but the current translation unit is being compiled for target", x)) {
warning(
"The C++ compiler has errored due to incompatibility between the x86 and ",
"Apple Silicon architectures.\n",
"If you are running R inside an IDE (RStudio, VSCode, ...), ",
"make sure the IDE is a native Apple Silicon app.\n",
call. = FALSE
)
}
}
},
error_on_status = FALSE
)
)
)
if (is.na(run_log$status) || run_log$status != 0) {
Expand Down
1 change: 0 additions & 1 deletion R/path.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ reset_cmdstan_version <- function() {
if (win_home != "") {
home <- win_home
}
home <- file.path(home, "Documents")
}
home
}
27 changes: 15 additions & 12 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,21 @@ CmdStanRun <- R6::R6Class(
check_target_exe <- function(exe) {
exe_path <- file.path(cmdstan_path(), exe)
if (!file.exists(exe_path)) {
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path()
),
run_log <- wsl_compatible_run(
command = make_cmd(),
args = exe,
wd = cmdstan_path(),
echo_cmd = TRUE,
echo = TRUE,
error_on_status = TRUE
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
withr::with_path(
c(
toolchain_PATH_env_var(),
tbb_path()
),
run_log <- wsl_compatible_run(
command = make_cmd(),
args = exe,
wd = cmdstan_path(),
echo_cmd = TRUE,
echo = TRUE,
error_on_status = TRUE
)
)
)
}
Expand Down
13 changes: 8 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,14 @@ assert_file_exists <- checkmate::makeAssertionFunction(check_file_exists)
# Model methods & expose_functions helpers ------------------------------------------------------
get_cmdstan_flags <- function(flag_name) {
cmdstan_path <- cmdstanr::cmdstan_path()
flags <- wsl_compatible_run(
command = "make",
args = c("-s", paste0("print-", flag_name)),
wd = cmdstan_path
)$stdout
withr::with_envvar(
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
flags <- wsl_compatible_run(
command = "make",
args = c("-s", paste0("print-", flag_name)),
wd = cmdstan_path
)$stdout
)

flags <- gsub("\n", "", flags, fixed = TRUE)

Expand Down

0 comments on commit 995e36f

Please sign in to comment.