diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index b4703e935d7..83c7270350f 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -564,7 +564,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { arena, path.to_path_buf(), opt_main_path.cloned(), - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), load_config, ); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 97adb89a0a4..b20962af5e3 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -49,7 +49,7 @@ fn main() -> io::Result<()> { BuildConfig::BuildAndRunIfNoErrors, Triple::host().into(), None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), LinkType::Executable, ) } else { @@ -64,7 +64,7 @@ fn main() -> io::Result<()> { BuildConfig::BuildAndRun, Triple::host().into(), None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), LinkType::Executable, ) } else { @@ -90,7 +90,7 @@ fn main() -> io::Result<()> { BuildConfig::BuildAndRunIfNoErrors, Triple::host().into(), None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), LinkType::Executable, ) } else { @@ -127,7 +127,7 @@ fn main() -> io::Result<()> { let function_kind = FunctionKind::from_env(); roc_linker::generate_stub_lib( input_path, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), target, function_kind, ); @@ -199,7 +199,7 @@ fn main() -> io::Result<()> { BuildConfig::BuildOnly, target, out_path, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), link_type, )?) } @@ -222,7 +222,7 @@ fn main() -> io::Result<()> { roc_file_path.to_owned(), opt_main_path.cloned(), emit_timings, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), threading, ) { Ok((problems, total_time)) => { diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index 0b6881e42af..2d3fd6e307c 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -784,7 +784,7 @@ impl<'a> State<'a> { number_of_workers: usize, exec_mode: ExecutionMode, ) -> Self { - let cache_dir = roc_packaging::cache::roc_cache_dir(); + let cache_dir = roc_packaging::cache::roc_cache_packages_dir(); let dependencies = Dependencies::new(exec_mode.goal_phase()); Self { diff --git a/crates/docs/src/lib.rs b/crates/docs/src/lib.rs index 2ff8341d562..603651e8af7 100644 --- a/crates/docs/src/lib.rs +++ b/crates/docs/src/lib.rs @@ -483,7 +483,7 @@ pub fn load_module_for_docs(filename: PathBuf) -> LoadedModule { &arena, filename, None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), load_config, ) { Ok(loaded) => loaded, diff --git a/crates/glue/src/load.rs b/crates/glue/src/load.rs index 00b580c0dcc..0ae5f9c5e1c 100644 --- a/crates/glue/src/load.rs +++ b/crates/glue/src/load.rs @@ -88,7 +88,7 @@ pub fn generate( linking_strategy, true, None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), load_config, Some(dylib_dir.path()), ), @@ -414,7 +414,7 @@ pub fn load_types( arena, full_file_path, None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), LoadConfig { target, function_kind, diff --git a/crates/language_server/src/analysis.rs b/crates/language_server/src/analysis.rs index 96523075ec2..6c8ae3e2eeb 100644 --- a/crates/language_server/src/analysis.rs +++ b/crates/language_server/src/analysis.rs @@ -114,7 +114,7 @@ pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec { roc_target::Target::LinuxX64, roc_load::FunctionKind::LambdaSet, roc_reporting::report::RenderTarget::LanguageServer, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), roc_reporting::report::DEFAULT_PALETTE, ); diff --git a/crates/language_server/src/convert.rs b/crates/language_server/src/convert.rs index 8833791c51f..c546847299c 100644 --- a/crates/language_server/src/convert.rs +++ b/crates/language_server/src/convert.rs @@ -160,7 +160,7 @@ pub(crate) mod diag { LoadingProblem::CouldNotFindCacheDir => { format!( "Could not find Roc cache directory {}", - roc_packaging::cache::roc_cache_dir().display() + roc_packaging::cache::roc_cache_packages_dir().display() ) } LoadingProblem::UnrecognizedPackageShorthand { shorthand, .. } => { diff --git a/crates/packaging/src/cache.rs b/crates/packaging/src/cache.rs index 4efa78ba1ba..6040328d6aa 100644 --- a/crates/packaging/src/cache.rs +++ b/crates/packaging/src/cache.rs @@ -207,7 +207,7 @@ const ROC_CACHE_DIR_NAME: &str = "roc"; /// This looks up environment variables, so it should ideally be called once and then cached! /// -/// Returns a path of the form cache_dir_path.join(ROC_CACHE_DIR_NAME).join("packages") +/// Returns a path of the form cache_dir_path.join(ROC_CACHE_DIR_NAME) /// where cache_dir_path is: /// - The XDG_CACHE_HOME environment varaible, if it's set. /// - Otherwise, ~/.cache on UNIX and %APPDATA% on Windows. @@ -222,14 +222,10 @@ const ROC_CACHE_DIR_NAME: &str = "roc"; pub fn roc_cache_dir() -> PathBuf { use std::{env, process}; - const PACKAGES_DIR_NAME: &str = "packages"; - // Respect XDG, if the system appears to be using it. // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html match env::var_os("XDG_CACHE_HOME") { - Some(xdg_cache_home) => Path::new(&xdg_cache_home) - .join(ROC_CACHE_DIR_NAME) - .join(PACKAGES_DIR_NAME), + Some(xdg_cache_home) => Path::new(&xdg_cache_home).join(ROC_CACHE_DIR_NAME), None => { #[cfg(windows)] { @@ -239,9 +235,7 @@ pub fn roc_cache_dir() -> PathBuf { // https://learn.microsoft.com/en-us/windows/deployment/usmt/usmt-recognized-environment-variables env::var_os("APPDATA").or_else(|| env::var_os("CSIDL_APPDATA")) { - Path::new(&appdata) - .join(ROC_CACHE_DIR_NAME) - .join(PACKAGES_DIR_NAME) + Path::new(&appdata).join(ROC_CACHE_DIR_NAME) } else { eprintln!("roc needs either the %APPDATA% or else the %XDG_CACHE_HOME% environment variables set. Please set one of these environment variables and re-run roc!"); process::exit(1); @@ -252,10 +246,7 @@ pub fn roc_cache_dir() -> PathBuf { { // e.g. $HOME/.cache/roc if let Some(home) = env::var_os("HOME") { - Path::new(&home) - .join(".cache") - .join(ROC_CACHE_DIR_NAME) - .join(PACKAGES_DIR_NAME) + Path::new(&home).join(".cache").join(ROC_CACHE_DIR_NAME) } else { eprintln!("roc needs either the $HOME or else the $XDG_CACHE_HOME environment variables set. Please set one of these environment variables and re-run roc!"); process::exit(1); @@ -271,3 +262,9 @@ pub fn roc_cache_dir() -> PathBuf { pub fn roc_cache_dir() -> PathBuf { PathBuf::from(".cache").join(ROC_CACHE_DIR_NAME) } + +/// Returns a path of the form roc_cache_dir().join("packages") +pub fn roc_cache_packages_dir() -> PathBuf { + const PACKAGES_DIR_NAME: &str = "packages"; + roc_cache_dir().join(PACKAGES_DIR_NAME) +} diff --git a/crates/repl_eval/src/gen.rs b/crates/repl_eval/src/gen.rs index 6731d167f00..f4523832557 100644 --- a/crates/repl_eval/src/gen.rs +++ b/crates/repl_eval/src/gen.rs @@ -61,7 +61,7 @@ pub fn compile_to_mono<'a, 'i, I: Iterator>( module_src, src_dir, None, - RocCacheDir::Persistent(cache::roc_cache_dir().as_path()), + RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()), LoadConfig { target, function_kind: FunctionKind::LambdaSet,