mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Make roc_cache_dir() panic if it can't find $HOME
This commit is contained in:
parent
4987fe1656
commit
7d2fa63dca
7 changed files with 31 additions and 61 deletions
|
@ -409,9 +409,6 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||||
let target = &triple;
|
let target = &triple;
|
||||||
let opt_level = opt_level;
|
let opt_level = opt_level;
|
||||||
let target_info = TargetInfo::from(target);
|
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
|
// Step 1: compile the app and generate the .o file
|
||||||
let subs_by_module = Default::default();
|
let subs_by_module = Default::default();
|
||||||
|
@ -428,7 +425,7 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
||||||
arena,
|
arena,
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
subs_by_module,
|
subs_by_module,
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
load_config,
|
load_config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -34,15 +34,11 @@ fn main() -> io::Result<()> {
|
||||||
let exit_code = match matches.subcommand() {
|
let exit_code = match matches.subcommand() {
|
||||||
None => {
|
None => {
|
||||||
if matches.is_present(ROC_FILE) {
|
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(
|
build(
|
||||||
&matches,
|
&matches,
|
||||||
BuildConfig::BuildAndRunIfNoErrors,
|
BuildConfig::BuildAndRunIfNoErrors,
|
||||||
Triple::host(),
|
Triple::host(),
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
LinkType::Executable,
|
LinkType::Executable,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,15 +49,11 @@ fn main() -> io::Result<()> {
|
||||||
}
|
}
|
||||||
Some((CMD_RUN, matches)) => {
|
Some((CMD_RUN, matches)) => {
|
||||||
if matches.is_present(ROC_FILE) {
|
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(
|
build(
|
||||||
matches,
|
matches,
|
||||||
BuildConfig::BuildAndRun,
|
BuildConfig::BuildAndRun,
|
||||||
Triple::host(),
|
Triple::host(),
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
LinkType::Executable,
|
LinkType::Executable,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,15 +73,11 @@ fn main() -> io::Result<()> {
|
||||||
}
|
}
|
||||||
Some((CMD_DEV, matches)) => {
|
Some((CMD_DEV, matches)) => {
|
||||||
if matches.is_present(ROC_FILE) {
|
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(
|
build(
|
||||||
matches,
|
matches,
|
||||||
BuildConfig::BuildAndRunIfNoErrors,
|
BuildConfig::BuildAndRunIfNoErrors,
|
||||||
Triple::host(),
|
Triple::host(),
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
LinkType::Executable,
|
LinkType::Executable,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,21 +101,14 @@ fn main() -> io::Result<()> {
|
||||||
Some((CMD_GEN_STUB_LIB, matches)) => {
|
Some((CMD_GEN_STUB_LIB, matches)) => {
|
||||||
let input_path = Path::new(matches.value_of_os(ROC_FILE).unwrap());
|
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 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(
|
roc_linker::generate_stub_lib(
|
||||||
input_path,
|
input_path,
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
&target.to_triple(),
|
&target.to_triple(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Some((CMD_BUILD, matches)) => {
|
Some((CMD_BUILD, matches)) => {
|
||||||
let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default();
|
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 (
|
let link_type = match (
|
||||||
matches.is_present(FLAG_LIB),
|
matches.is_present(FLAG_LIB),
|
||||||
matches.is_present(FLAG_NO_LINK),
|
matches.is_present(FLAG_NO_LINK),
|
||||||
|
@ -142,7 +123,7 @@ fn main() -> io::Result<()> {
|
||||||
matches,
|
matches,
|
||||||
BuildConfig::BuildOnly,
|
BuildConfig::BuildOnly,
|
||||||
target.to_triple(),
|
target.to_triple(),
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
link_type,
|
link_type,
|
||||||
)?)
|
)?)
|
||||||
}
|
}
|
||||||
|
@ -152,9 +133,6 @@ fn main() -> io::Result<()> {
|
||||||
let emit_timings = matches.is_present(FLAG_TIME);
|
let emit_timings = matches.is_present(FLAG_TIME);
|
||||||
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
||||||
let roc_file_path = PathBuf::from(filename);
|
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
|
let threading = match matches
|
||||||
.value_of(roc_cli::FLAG_MAX_THREADS)
|
.value_of(roc_cli::FLAG_MAX_THREADS)
|
||||||
.and_then(|s| s.parse::<usize>().ok())
|
.and_then(|s| s.parse::<usize>().ok())
|
||||||
|
@ -169,7 +147,7 @@ fn main() -> io::Result<()> {
|
||||||
&arena,
|
&arena,
|
||||||
roc_file_path,
|
roc_file_path,
|
||||||
emit_timings,
|
emit_timings,
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
threading,
|
threading,
|
||||||
) {
|
) {
|
||||||
Ok((problems, total_time)) => {
|
Ok((problems, total_time)) => {
|
||||||
|
|
|
@ -453,9 +453,6 @@ fn render_sidebar<'a, I: Iterator<Item = (&'a ModuleDocumentation, Vec<String>)>
|
||||||
|
|
||||||
pub fn load_modules_for_files(filenames: Vec<PathBuf>) -> Vec<LoadedModule> {
|
pub fn load_modules_for_files(filenames: Vec<PathBuf>) -> Vec<LoadedModule> {
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
|
|
||||||
todo!("Gracefully handle not being able to find default Roc cache dir.")
|
|
||||||
});
|
|
||||||
let mut modules = Vec::with_capacity(filenames.len());
|
let mut modules = Vec::with_capacity(filenames.len());
|
||||||
|
|
||||||
for filename in filenames {
|
for filename in filenames {
|
||||||
|
@ -470,7 +467,7 @@ pub fn load_modules_for_files(filenames: Vec<PathBuf>) -> Vec<LoadedModule> {
|
||||||
&arena,
|
&arena,
|
||||||
filename,
|
filename,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
load_config,
|
load_config,
|
||||||
) {
|
) {
|
||||||
Ok(loaded) => modules.push(loaded),
|
Ok(loaded) => modules.push(loaded),
|
||||||
|
|
|
@ -128,13 +128,9 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box<dyn Err
|
||||||
println!("Loading file {:?}...", file_path_str);
|
println!("Loading file {:?}...", file_path_str);
|
||||||
|
|
||||||
let file_path = Path::new(&file_path_str);
|
let file_path = Path::new(&file_path_str);
|
||||||
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
|
|
||||||
todo!("Gracefully handle not being able to find default Roc cache dir.")
|
|
||||||
});
|
|
||||||
|
|
||||||
let loaded_module = load_module(
|
let loaded_module = load_module(
|
||||||
file_path,
|
file_path,
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
Threading::AllAvailable,
|
Threading::AllAvailable,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,6 @@ pub fn load_types(
|
||||||
ignore_errors: IgnoreErrors,
|
ignore_errors: IgnoreErrors,
|
||||||
) -> Result<Vec<(Types, TargetInfo)>, io::Error> {
|
) -> Result<Vec<(Types, TargetInfo)>, io::Error> {
|
||||||
let target_info = (&Triple::host()).into();
|
let target_info = (&Triple::host()).into();
|
||||||
let roc_cache_dir = cache::roc_cache_dir().unwrap_or_else(|| {
|
|
||||||
todo!("Gracefully handle not being able to find default Roc cache dir.")
|
|
||||||
});
|
|
||||||
let arena = &Bump::new();
|
let arena = &Bump::new();
|
||||||
let subs_by_module = Default::default();
|
let subs_by_module = Default::default();
|
||||||
let LoadedModule {
|
let LoadedModule {
|
||||||
|
@ -100,7 +97,7 @@ pub fn load_types(
|
||||||
arena,
|
arena,
|
||||||
full_file_path,
|
full_file_path,
|
||||||
subs_by_module,
|
subs_by_module,
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
LoadConfig {
|
LoadConfig {
|
||||||
target_info,
|
target_info,
|
||||||
render: RenderTarget::Generic,
|
render: RenderTarget::Generic,
|
||||||
|
|
|
@ -107,30 +107,38 @@ const ROC_VERSION: &str = include_str!("../../../version.txt");
|
||||||
///
|
///
|
||||||
/// Returns None if XDG_CACHE_HOME is not set, and also we can't determine the home directory
|
/// Returns None if XDG_CACHE_HOME is not set, and also we can't determine the home directory
|
||||||
/// (or if %APPDATA% is missing on Windows) on this system.
|
/// (or if %APPDATA% is missing on Windows) on this system.
|
||||||
pub fn roc_cache_dir() -> Option<PathBuf> {
|
pub fn roc_cache_dir() -> PathBuf {
|
||||||
// Respect XDG, if the system appears to be using it.
|
// Respect XDG, if the system appears to be using it.
|
||||||
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||||
match env::var_os("XDG_CACHE_HOME") {
|
match env::var_os("XDG_CACHE_HOME") {
|
||||||
Some(xdg_cache_home) => Some(
|
Some(xdg_cache_home) => Path::new(&xdg_cache_home)
|
||||||
Path::new(&xdg_cache_home)
|
.join(ROC_CACHE_DIR_NAME)
|
||||||
.join(ROC_CACHE_DIR_NAME)
|
.join(ROC_VERSION),
|
||||||
.join(ROC_VERSION),
|
|
||||||
),
|
|
||||||
None => {
|
None => {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
// e.g. %APPDATA%\\Roc
|
// e.g. %APPDATA%\\Roc
|
||||||
Some(Path::new(&env::var_os("APPDATA")?).join(ROC_CACHE_DIR_NAME))
|
if let Some(appdata) =
|
||||||
|
// CSIDL_APPDATA is the same as APPDATA, according to:
|
||||||
|
// 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)
|
||||||
|
} 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!");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
// e.g. $HOME/.cache/roc
|
// e.g. $HOME/.cache/roc
|
||||||
Some(
|
if let Some(home) = env::var_os("HOME") {
|
||||||
Path::new(&env::var_os("HOME")?)
|
Path::new(&home).join(".cache").join(ROC_CACHE_DIR_NAME)
|
||||||
.join(".cache")
|
} else {
|
||||||
.join(ROC_CACHE_DIR_NAME),
|
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!");
|
||||||
)
|
std::process::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,16 +54,13 @@ pub fn compile_to_mono<'a, 'i, I: Iterator<Item = &'i str>>(
|
||||||
let src_dir = PathBuf::from("fake/test/path");
|
let src_dir = PathBuf::from("fake/test/path");
|
||||||
let (bytes_before_expr, module_src) = promote_expr_to_module(arena, defs, expr);
|
let (bytes_before_expr, module_src) = promote_expr_to_module(arena, defs, expr);
|
||||||
let exposed_types = Default::default();
|
let exposed_types = Default::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 loaded = roc_load::load_and_monomorphize_from_str(
|
let loaded = roc_load::load_and_monomorphize_from_str(
|
||||||
arena,
|
arena,
|
||||||
filename,
|
filename,
|
||||||
module_src,
|
module_src,
|
||||||
src_dir,
|
src_dir,
|
||||||
exposed_types,
|
exposed_types,
|
||||||
RocCacheDir::Persistent(roc_cache_dir.as_path()),
|
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
|
||||||
LoadConfig {
|
LoadConfig {
|
||||||
target_info,
|
target_info,
|
||||||
render: roc_reporting::report::RenderTarget::ColorTerminal,
|
render: roc_reporting::report::RenderTarget::ColorTerminal,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue