internal: make it easier to isolate IO

This commit is contained in:
Aleksey Kladov 2021-07-17 16:43:33 +03:00
parent a2f83c956e
commit 9318c643f1
8 changed files with 58 additions and 35 deletions

View file

@ -24,7 +24,7 @@ mod rustc_cfg;
mod build_data;
use std::{
fs::{read_dir, ReadDir},
fs::{self, read_dir, ReadDir},
io,
process::Command,
};
@ -54,10 +54,10 @@ pub enum ProjectManifest {
impl ProjectManifest {
pub fn from_manifest_file(path: AbsPathBuf) -> Result<ProjectManifest> {
if path.ends_with("rust-project.json") {
if path.file_name().unwrap_or_default() == "rust-project.json" {
return Ok(ProjectManifest::ProjectJson(path));
}
if path.ends_with("Cargo.toml") {
if path.file_name().unwrap_or_default() == "Cargo.toml" {
return Ok(ProjectManifest::CargoToml(path));
}
bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display())
@ -91,7 +91,7 @@ impl ProjectManifest {
}
fn find_in_parent_dirs(path: &AbsPath, target_file_name: &str) -> Option<AbsPathBuf> {
if path.ends_with(target_file_name) {
if path.file_name().unwrap_or_default() == target_file_name {
return Some(path.to_path_buf());
}
@ -99,7 +99,7 @@ impl ProjectManifest {
while let Some(path) = curr {
let candidate = path.join(target_file_name);
if candidate.exists() {
if fs::metadata(&candidate).is_ok() {
return Some(candidate);
}
curr = path.parent();