mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +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 {
|
match header_type {
|
||||||
Module { .. } | Builtin { .. } | Hosted { .. } => {
|
Module { .. } | Builtin { .. } | Hosted { .. } => {
|
||||||
let main_path = opt_main_path.or_else(|| loop {
|
let main_path =
|
||||||
match src_dir.join("main.roc").canonicalize() {
|
opt_main_path.or_else(|| find_main_roc_recursively(&mut src_dir));
|
||||||
Ok(path) => break Some(path),
|
|
||||||
Err(_) => {
|
|
||||||
if !src_dir.pop() {
|
|
||||||
break None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let cache_dir = roc_cache_dir.as_persistent_path();
|
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) => {
|
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>(
|
fn load_packages_from_main<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
src_dir: PathBuf,
|
src_dir: PathBuf,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue