Provide roc_cache_dir everywhere

This commit is contained in:
Richard Feldman 2022-11-20 17:03:17 -05:00
parent 13bed30411
commit 721841fa1f
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
41 changed files with 303 additions and 114 deletions

View file

@ -10,6 +10,7 @@ use roc_cli::{
use roc_docs::generate_docs_html;
use roc_error_macros::user_error;
use roc_load::{LoadingProblem, Threading};
use roc_packaging::cache::{self, RocCacheDir};
use std::fs::{self, FileType};
use std::io;
use std::path::{Path, PathBuf};
@ -33,10 +34,15 @@ fn main() -> io::Result<()> {
let exit_code = match matches.subcommand() {
None => {
if matches.is_present(ROC_FILE) {
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
build(
&matches,
BuildConfig::BuildAndRunIfNoErrors,
Triple::host(),
RocCacheDir::Persistent(roc_cache_dir.as_path()),
LinkType::Executable,
)
} else {
@ -47,10 +53,15 @@ fn main() -> io::Result<()> {
}
Some((CMD_RUN, matches)) => {
if matches.is_present(ROC_FILE) {
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
build(
matches,
BuildConfig::BuildAndRun,
Triple::host(),
RocCacheDir::Persistent(roc_cache_dir.as_path()),
LinkType::Executable,
)
} else {
@ -70,10 +81,15 @@ fn main() -> io::Result<()> {
}
Some((CMD_DEV, matches)) => {
if matches.is_present(ROC_FILE) {
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
build(
matches,
BuildConfig::BuildAndRunIfNoErrors,
Triple::host(),
RocCacheDir::Persistent(roc_cache_dir.as_path()),
LinkType::Executable,
)
} else {
@ -97,12 +113,21 @@ fn main() -> io::Result<()> {
Some((CMD_GEN_STUB_LIB, matches)) => {
let input_path = Path::new(matches.value_of_os(ROC_FILE).unwrap());
let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default();
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
roc_linker::generate_stub_lib(input_path, &target.to_triple())
roc_linker::generate_stub_lib(
input_path,
RocCacheDir::Persistent(roc_cache_dir.as_path()),
&target.to_triple(),
)
}
Some((CMD_BUILD, matches)) => {
let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default();
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
let link_type = match (
matches.is_present(FLAG_LIB),
matches.is_present(FLAG_NO_LINK),
@ -117,6 +142,7 @@ fn main() -> io::Result<()> {
matches,
BuildConfig::BuildOnly,
target.to_triple(),
RocCacheDir::Persistent(roc_cache_dir.as_path()),
link_type,
)?)
}
@ -126,6 +152,9 @@ fn main() -> io::Result<()> {
let emit_timings = matches.is_present(FLAG_TIME);
let filename = matches.value_of_os(ROC_FILE).unwrap();
let roc_file_path = PathBuf::from(filename);
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
let threading = match matches
.value_of(roc_cli::FLAG_MAX_THREADS)
.and_then(|s| s.parse::<usize>().ok())
@ -136,7 +165,13 @@ fn main() -> io::Result<()> {
Some(n) => Threading::AtMost(n),
};
match check_file(&arena, roc_file_path, emit_timings, threading) {
match check_file(
&arena,
roc_file_path,
emit_timings,
RocCacheDir::Persistent(roc_cache_dir.as_path()),
threading,
) {
Ok((problems, total_time)) => {
println!(
"\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.",