mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Use module's parent dir if main roc file is not found
This commit is contained in:
parent
2da7ea394b
commit
f5e08cb917
1 changed files with 20 additions and 11 deletions
|
@ -1145,16 +1145,8 @@ impl<'a> LoadStart<'a> {
|
|||
|
||||
match header_type {
|
||||
Module { .. } | Builtin { .. } | Hosted { .. } => {
|
||||
let main_path = opt_main_path.or_else(|| loop {
|
||||
match src_dir.join("main.roc").canonicalize() {
|
||||
Ok(path) => break Some(path),
|
||||
Err(_) => {
|
||||
if !src_dir.pop() {
|
||||
break None;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
let main_path =
|
||||
opt_main_path.or_else(|| find_main_roc_recursively(&mut src_dir));
|
||||
|
||||
let cache_dir = roc_cache_dir.as_persistent_path();
|
||||
|
||||
|
@ -1180,7 +1172,7 @@ impl<'a> LoadStart<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
header_output
|
||||
adjust_header_paths(header_output, &mut src_dir)
|
||||
}
|
||||
|
||||
Err(problem) => {
|
||||
|
@ -1257,6 +1249,23 @@ impl<'a> LoadStart<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_main_roc_recursively(src_dir: &mut PathBuf) -> Option<PathBuf> {
|
||||
let original_src_dir = src_dir.clone();
|
||||
|
||||
loop {
|
||||
match src_dir.join("main.roc").canonicalize() {
|
||||
Ok(main_roc) => break Some(main_roc),
|
||||
Err(_) => {
|
||||
if !src_dir.pop() {
|
||||
// reached the root, no main.roc found
|
||||
*src_dir = original_src_dir;
|
||||
break None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_packages_from_main<'a>(
|
||||
arena: &'a Bump,
|
||||
src_dir: PathBuf,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue