mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
also search dirs one level below
This commit is contained in:
parent
b47e086f50
commit
4d237d79a7
1 changed files with 40 additions and 25 deletions
|
@ -7,6 +7,7 @@ use roc_mono::ir::OptLevel;
|
|||
use roc_utils::{cargo, clang, zig};
|
||||
use roc_utils::{get_lib_path, rustup};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::DirEntry;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{self, Child, Command};
|
||||
|
@ -946,38 +947,52 @@ fn find_used_target_sub_folder(opt_level: OptLevel, target_folder: PathBuf) -> P
|
|||
"debug"
|
||||
};
|
||||
|
||||
let mut out_folder_opt = None;
|
||||
let mut out_folder_last_change_opt = None;
|
||||
let matching_folders = find_in_folder_or_subfolders(&target_folder, out_folder_name);
|
||||
let mut matching_folders_iter = matching_folders.iter();
|
||||
|
||||
if let Ok(entries) = fs::read_dir(target_folder.clone()) {
|
||||
for entry in entries.flatten() {
|
||||
if entry.file_type().unwrap().is_dir() {
|
||||
let dir_name = entry.file_name().into_string().unwrap_or_else(|_| "".to_string());
|
||||
let mut out_folder = match matching_folders_iter.next() {
|
||||
Some(dir_entry) => dir_entry,
|
||||
None => panic!("I could not find a folder named {} in {:?}. This may be because the `cargo build` for the platform went wrong.", out_folder_name, target_folder)
|
||||
};
|
||||
|
||||
if dir_name == out_folder_name {
|
||||
let metadata = entry.metadata().unwrap();
|
||||
let last_modified = metadata.modified().unwrap();
|
||||
let mut out_folder_last_change = out_folder.metadata().unwrap().modified().unwrap();
|
||||
|
||||
if let Some(out_folder_last_change) = out_folder_last_change_opt {
|
||||
if last_modified > out_folder_last_change {
|
||||
out_folder_last_change_opt = Some(last_modified);
|
||||
out_folder_opt = Some(entry.path())
|
||||
}
|
||||
} else {
|
||||
out_folder_last_change_opt = Some(last_modified);
|
||||
out_folder_opt = Some(entry.path())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for dir_entry in matching_folders_iter {
|
||||
let last_modified = dir_entry.metadata().unwrap().modified().unwrap();
|
||||
|
||||
if last_modified > out_folder_last_change {
|
||||
out_folder_last_change = last_modified;
|
||||
out_folder = dir_entry;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(out_folder) = out_folder_opt {
|
||||
out_folder
|
||||
} else {
|
||||
internal_error!("I could not find a folder named {} in {:?}. This may be because the `cargo build` for the platform went wrong.", out_folder_name, target_folder)
|
||||
out_folder.path().canonicalize().unwrap()
|
||||
}
|
||||
|
||||
fn find_in_folder_or_subfolders(path: &PathBuf, folder_to_find: &str) -> Vec<DirEntry> {
|
||||
let mut matching_dirs = vec![];
|
||||
|
||||
if let Ok(entries) = fs::read_dir(path) {
|
||||
for entry in entries.flatten() {
|
||||
if entry.file_type().unwrap().is_dir() {
|
||||
let dir_name = entry
|
||||
.file_name()
|
||||
.into_string()
|
||||
.unwrap_or_else(|_| "".to_string());
|
||||
|
||||
if dir_name == folder_to_find {
|
||||
matching_dirs.push(entry)
|
||||
} else {
|
||||
let matched_in_sub_dir =
|
||||
find_in_folder_or_subfolders(&entry.path(), folder_to_find);
|
||||
|
||||
matching_dirs.extend(matched_in_sub_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matching_dirs
|
||||
}
|
||||
|
||||
fn get_target_str(target: &Triple) -> &str {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue