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

@ -12,6 +12,7 @@ use roc_load::{
LoadingProblem, Threading,
};
use roc_mono::ir::OptLevel;
use roc_packaging::cache::RocCacheDir;
use roc_reporting::report::{RenderTarget, DEFAULT_PALETTE};
use roc_target::TargetInfo;
use std::time::{Duration, Instant};
@ -67,6 +68,7 @@ pub fn build_file<'a>(
prebuilt: bool,
threading: Threading,
wasm_dev_stack_bytes: Option<u32>,
roc_cache_dir: RocCacheDir<'_>,
order: BuildOrdering,
) -> Result<BuiltFile<'a>, BuildFileError<'a>> {
let compilation_start = Instant::now();
@ -92,6 +94,7 @@ pub fn build_file<'a>(
arena,
app_module_path.clone(),
subs_by_module,
roc_cache_dir,
load_config,
);
let loaded = match load_result {
@ -464,12 +467,13 @@ fn spawn_rebuild_thread(
}
#[allow(clippy::too_many_arguments)]
pub fn check_file(
arena: &Bump,
pub fn check_file<'a>(
arena: &'a Bump,
roc_file_path: PathBuf,
emit_timings: bool,
roc_cache_dir: RocCacheDir<'_>,
threading: Threading,
) -> Result<(program::Problems, Duration), LoadingProblem> {
) -> Result<(program::Problems, Duration), LoadingProblem<'a>> {
let compilation_start = Instant::now();
// only used for generating errors. We don't do code generation, so hardcoding should be fine
@ -487,8 +491,13 @@ pub fn check_file(
threading,
exec_mode: ExecutionMode::Check,
};
let mut loaded =
roc_load::load_and_typecheck(arena, roc_file_path, subs_by_module, load_config)?;
let mut loaded = roc_load::load_and_typecheck(
arena,
roc_file_path,
subs_by_module,
roc_cache_dir,
load_config,
)?;
let buf = &mut String::with_capacity(1024);

View file

@ -11,6 +11,7 @@ use roc_build::program::{CodeGenBackend, CodeGenOptions, Problems};
use roc_error_macros::{internal_error, user_error};
use roc_load::{ExpectMetadata, LoadingProblem, Threading};
use roc_mono::ir::OptLevel;
use roc_packaging::cache::RocCacheDir;
use std::env;
use std::ffi::{CString, OsStr};
use std::io;
@ -356,6 +357,7 @@ pub fn test(_matches: &ArgMatches, _triple: Triple) -> io::Result<i32> {
pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
use roc_gen_llvm::llvm::build::LlvmBackendMode;
use roc_load::{ExecutionMode, LoadConfig};
use roc_packaging::cache;
use roc_target::TargetInfo;
let start_time = Instant::now();
@ -407,6 +409,9 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
let target = &triple;
let opt_level = opt_level;
let target_info = TargetInfo::from(target);
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
todo!("Gracefully handle not being able to find default Roc cache dir.")
});
// Step 1: compile the app and generate the .o file
let subs_by_module = Default::default();
@ -419,9 +424,14 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
threading,
exec_mode: ExecutionMode::Test,
};
let loaded =
roc_load::load_and_monomorphize(arena, path.to_path_buf(), subs_by_module, load_config)
.unwrap();
let loaded = roc_load::load_and_monomorphize(
arena,
path.to_path_buf(),
subs_by_module,
RocCacheDir::Persistent(roc_cache_dir.as_path()),
load_config,
)
.unwrap();
let mut loaded = loaded;
let mut expectations = std::mem::take(&mut loaded.expectations);
@ -487,6 +497,7 @@ pub fn build(
matches: &ArgMatches,
config: BuildConfig,
triple: Triple,
roc_cache_dir: RocCacheDir<'_>,
link_type: LinkType,
) -> io::Result<i32> {
use build::build_file;
@ -518,7 +529,7 @@ pub fn build(
let start_time = Instant::now();
// Rather than building an executable or library, we're building
// a rp1 bundle so this code can be distributed via a HTTPS
// a tarball so this code can be distributed via a HTTPS
let filename = roc_packaging::tarball::build(path)?;
let total_time = start_time.elapsed().as_millis();
let created_path = path.with_file_name(&filename);
@ -627,6 +638,7 @@ pub fn build(
prebuilt,
threading,
wasm_dev_stack_bytes,
roc_cache_dir,
build_ordering,
);

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.",