Skip to content

Commit 995e36f

Browse files
committed
Fix Onedrive PATH issues
1 parent 6d914e9 commit 995e36f

5 files changed

Lines changed: 124 additions & 107 deletions

File tree

R/install.R

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -453,63 +453,72 @@ build_cmdstan <- function(dir,
453453
} else {
454454
run_cmd <- make_cmd()
455455
}
456-
withr::with_path(
457-
c(
458-
toolchain_PATH_env_var(),
459-
tbb_path(dir = dir)
460-
),
461-
wsl_compatible_run(
462-
command = run_cmd,
463-
args = c(translation_args, paste0("-j", cores), "build"),
464-
wd = dir,
465-
echo_cmd = is_verbose_mode(),
466-
echo = !quiet || is_verbose_mode(),
467-
spinner = quiet,
468-
error_on_status = FALSE,
469-
stderr_callback = function(x, p) { if (quiet) message(x) },
470-
timeout = timeout
456+
withr::with_envvar(
457+
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
458+
withr::with_path(
459+
c(
460+
toolchain_PATH_env_var(),
461+
tbb_path(dir = dir)
462+
),
463+
wsl_compatible_run(
464+
command = run_cmd,
465+
args = c(translation_args, paste0("-j", cores), "build"),
466+
wd = dir,
467+
echo_cmd = is_verbose_mode(),
468+
echo = !quiet || is_verbose_mode(),
469+
spinner = quiet,
470+
error_on_status = FALSE,
471+
stderr_callback = function(x, p) { if (quiet) message(x) },
472+
timeout = timeout
473+
)
471474
)
472475
)
473476
}
474477

475478
clean_cmdstan <- function(dir = cmdstan_path(),
476479
cores = getOption("mc.cores", 2),
477480
quiet = FALSE) {
478-
withr::with_path(
479-
c(
480-
toolchain_PATH_env_var(),
481-
tbb_path(dir = dir)
482-
),
483-
wsl_compatible_run(
484-
command = make_cmd(),
485-
args = "clean-all",
486-
wd = dir,
487-
echo_cmd = is_verbose_mode(),
488-
echo = !quiet || is_verbose_mode(),
489-
spinner = quiet,
490-
error_on_status = FALSE,
491-
stderr_callback = function(x, p) { if (quiet) message(x) }
481+
withr::with_envvar(
482+
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
483+
withr::with_path(
484+
c(
485+
toolchain_PATH_env_var(),
486+
tbb_path(dir = dir)
487+
),
488+
wsl_compatible_run(
489+
command = make_cmd(),
490+
args = "clean-all",
491+
wd = dir,
492+
echo_cmd = is_verbose_mode(),
493+
echo = !quiet || is_verbose_mode(),
494+
spinner = quiet,
495+
error_on_status = FALSE,
496+
stderr_callback = function(x, p) { if (quiet) message(x) }
497+
)
492498
)
493499
)
494500
}
495501

496502
build_example <- function(dir, cores, quiet, timeout) {
497-
withr::with_path(
498-
c(
499-
toolchain_PATH_env_var(),
500-
tbb_path(dir = dir)
501-
),
502-
wsl_compatible_run(
503-
command = make_cmd(),
504-
args = c(paste0("-j", cores),
505-
cmdstan_ext(file.path("examples", "bernoulli", "bernoulli"))),
506-
wd = dir,
507-
echo_cmd = is_verbose_mode(),
508-
echo = !quiet || is_verbose_mode(),
509-
spinner = quiet,
510-
error_on_status = FALSE,
511-
stderr_callback = function(x, p) { if (quiet) message(x) },
512-
timeout = timeout
503+
withr::with_envvar(
504+
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
505+
withr::with_path(
506+
c(
507+
toolchain_PATH_env_var(),
508+
tbb_path(dir = dir)
509+
),
510+
wsl_compatible_run(
511+
command = make_cmd(),
512+
args = c(paste0("-j", cores),
513+
cmdstan_ext(file.path("examples", "bernoulli", "bernoulli"))),
514+
wd = dir,
515+
echo_cmd = is_verbose_mode(),
516+
echo = !quiet || is_verbose_mode(),
517+
spinner = quiet,
518+
error_on_status = FALSE,
519+
stderr_callback = function(x, p) { if (quiet) message(x) },
520+
timeout = timeout
521+
)
513522
)
514523
)
515524
}

R/model.R

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -664,54 +664,57 @@ compile <- function(quiet = TRUE,
664664
if (compile_standalone) {
665665
expose_stan_functions(self$functions, !quiet)
666666
}
667-
668-
withr::with_path(
669-
c(
670-
toolchain_PATH_env_var(),
671-
tbb_path()
672-
),
673-
run_log <- wsl_compatible_run(
674-
command = make_cmd(),
675-
args = c(wsl_safe_path(repair_path(tmp_exe)),
676-
cpp_options_to_compile_flags(cpp_options),
677-
stancflags_val),
678-
wd = cmdstan_path(),
679-
echo = !quiet || is_verbose_mode(),
680-
echo_cmd = is_verbose_mode(),
681-
spinner = quiet && rlang::is_interactive() && !identical(Sys.getenv("IN_PKGDOWN"), "true"),
682-
stderr_callback = function(x, p) {
683-
if (!startsWith(x, paste0(make_cmd(), ": *** No rule to make target"))) {
684-
message(x)
685-
}
686-
if (grepl("PCH file", x) || grepl("precompiled header", x) || grepl(".hpp.gch", x) ) {
687-
warning(
688-
"CmdStan's precompiled header (PCH) files may need to be rebuilt.\n",
689-
"If your model failed to compile please run rebuild_cmdstan().\n",
690-
"If the issue persists please open a bug report.",
691-
call. = FALSE
692-
)
693-
}
694-
if (grepl("No space left on device", x) || grepl("error in backend: IO failure on output stream", x)) {
695-
warning(
696-
"The C++ compiler ran out of disk space and was unable to build the executables for your model!\n",
697-
"See the above error for more details.",
698-
call. = FALSE
699-
)
700-
}
701-
if (os_is_macos()) {
702-
if (R.version$arch == "aarch64"
703-
&& grepl("but the current translation unit is being compiled for target", x)) {
667+
668+
withr::with_envvar(
669+
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
670+
withr::with_path(
671+
c(
672+
toolchain_PATH_env_var(),
673+
tbb_path()
674+
),
675+
run_log <- wsl_compatible_run(
676+
command = make_cmd(),
677+
args = c(wsl_safe_path(repair_path(tmp_exe)),
678+
cpp_options_to_compile_flags(cpp_options),
679+
stancflags_val),
680+
wd = cmdstan_path(),
681+
echo = !quiet || is_verbose_mode(),
682+
echo_cmd = is_verbose_mode(),
683+
spinner = quiet && rlang::is_interactive() && !identical(Sys.getenv("IN_PKGDOWN"), "true"),
684+
stderr_callback = function(x, p) {
685+
if (!startsWith(x, paste0(make_cmd(), ": *** No rule to make target"))) {
686+
message(x)
687+
}
688+
if (grepl("PCH file", x) || grepl("precompiled header", x) || grepl(".hpp.gch", x) ) {
704689
warning(
705-
"The C++ compiler has errored due to incompatibility between the x86 and ",
706-
"Apple Silicon architectures.\n",
707-
"If you are running R inside an IDE (RStudio, VSCode, ...), ",
708-
"make sure the IDE is a native Apple Silicon app.\n",
690+
"CmdStan's precompiled header (PCH) files may need to be rebuilt.\n",
691+
"If your model failed to compile please run rebuild_cmdstan().\n",
692+
"If the issue persists please open a bug report.",
709693
call. = FALSE
710694
)
711695
}
712-
}
713-
},
714-
error_on_status = FALSE
696+
if (grepl("No space left on device", x) || grepl("error in backend: IO failure on output stream", x)) {
697+
warning(
698+
"The C++ compiler ran out of disk space and was unable to build the executables for your model!\n",
699+
"See the above error for more details.",
700+
call. = FALSE
701+
)
702+
}
703+
if (os_is_macos()) {
704+
if (R.version$arch == "aarch64"
705+
&& grepl("but the current translation unit is being compiled for target", x)) {
706+
warning(
707+
"The C++ compiler has errored due to incompatibility between the x86 and ",
708+
"Apple Silicon architectures.\n",
709+
"If you are running R inside an IDE (RStudio, VSCode, ...), ",
710+
"make sure the IDE is a native Apple Silicon app.\n",
711+
call. = FALSE
712+
)
713+
}
714+
}
715+
},
716+
error_on_status = FALSE
717+
)
715718
)
716719
)
717720
if (is.na(run_log$status) || run_log$status != 0) {

R/path.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ reset_cmdstan_version <- function() {
250250
if (win_home != "") {
251251
home <- win_home
252252
}
253-
home <- file.path(home, "Documents")
254253
}
255254
home
256255
}

R/run.R

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,21 @@ CmdStanRun <- R6::R6Class(
410410
check_target_exe <- function(exe) {
411411
exe_path <- file.path(cmdstan_path(), exe)
412412
if (!file.exists(exe_path)) {
413-
withr::with_path(
414-
c(
415-
toolchain_PATH_env_var(),
416-
tbb_path()
417-
),
418-
run_log <- wsl_compatible_run(
419-
command = make_cmd(),
420-
args = exe,
421-
wd = cmdstan_path(),
422-
echo_cmd = TRUE,
423-
echo = TRUE,
424-
error_on_status = TRUE
413+
withr::with_envvar(
414+
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
415+
withr::with_path(
416+
c(
417+
toolchain_PATH_env_var(),
418+
tbb_path()
419+
),
420+
run_log <- wsl_compatible_run(
421+
command = make_cmd(),
422+
args = exe,
423+
wd = cmdstan_path(),
424+
echo_cmd = TRUE,
425+
echo = TRUE,
426+
error_on_status = TRUE
427+
)
425428
)
426429
)
427430
}

R/utils.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,14 @@ assert_file_exists <- checkmate::makeAssertionFunction(check_file_exists)
692692
# Model methods & expose_functions helpers ------------------------------------------------------
693693
get_cmdstan_flags <- function(flag_name) {
694694
cmdstan_path <- cmdstanr::cmdstan_path()
695-
flags <- wsl_compatible_run(
696-
command = "make",
697-
args = c("-s", paste0("print-", flag_name)),
698-
wd = cmdstan_path
699-
)$stdout
695+
withr::with_envvar(
696+
c("HOME" = utils::shortPathName(Sys.getenv("HOME"))),
697+
flags <- wsl_compatible_run(
698+
command = "make",
699+
args = c("-s", paste0("print-", flag_name)),
700+
wd = cmdstan_path
701+
)$stdout
702+
)
700703

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

0 commit comments

Comments
 (0)