From 35ba29dc2c53dbff585e1d4865af249823c13669 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Fri, 18 Oct 2024 04:53:43 +0000 Subject: [PATCH] Build fix --- src/lib/descriptor/mod.rs | 14 +++++++------- src/lib/environment/mod.rs | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/lib/descriptor/mod.rs b/src/lib/descriptor/mod.rs index 927751e7..08f05118 100755 --- a/src/lib/descriptor/mod.rs +++ b/src/lib/descriptor/mod.rs @@ -328,13 +328,13 @@ fn load_external_descriptor( ); let descriptor_dir = match relative_to { - RelativeTo::Makefile => base_path, + RelativeTo::Makefile => base_path.to_string(), RelativeTo::CrateRoot => { let project_root = environment::get_project_root_for_path(&PathBuf::from(base_path)); debug!("project root: {:#?}", &project_root); match project_root { - Some(crate_dir) => &crate_dir.clone(), - None => base_path, + Some(crate_dir) => crate_dir.clone(), + None => base_path.to_string(), } } RelativeTo::WorkspaceRoot => { @@ -347,15 +347,15 @@ fn load_external_descriptor( let workspace_root = environment::get_project_root_for_path(&crate_parent_path); debug!("workspace root: {:#?}", &workspace_root); match workspace_root { - Some(workspace_dir) => &workspace_dir.clone(), - None => &crate_dir.clone(), + Some(workspace_dir) => workspace_dir.clone(), + None => crate_dir.clone(), } } - None => base_path, + None => base_path.to_string(), } } }; - let file_path = Path::new(descriptor_dir).join(file_name); + let file_path = Path::new(&descriptor_dir).join(file_name); if file_path.exists() && file_path.is_file() { let file_path_string: String = FromPath::from_path(&file_path); diff --git a/src/lib/environment/mod.rs b/src/lib/environment/mod.rs index 8628dfc1..d296cfc4 100644 --- a/src/lib/environment/mod.rs +++ b/src/lib/environment/mod.rs @@ -779,17 +779,21 @@ fn load_env_file_with_base_directory( } } +fn current_dir_or(fallback: &PathBuf) -> PathBuf { + match env::current_dir() { + Ok(value) => value.clone(), + _ => fallback.clone(), + } +} + pub(crate) fn get_project_root_for_path(directory: &PathBuf) -> Option { let from_dir = if directory.to_str().unwrap_or(".") == "." { - match env::current_dir() { - Ok(value) => &value.clone(), - _ => directory, - } + current_dir_or(directory) } else { - directory + directory.to_path_buf() }; - debug!("Looking for project root from directory: {:?}", from_dir); - let file_path = Path::new(from_dir).join("Cargo.toml"); + debug!("Looking for project root from directory: {:?}", &from_dir); + let file_path = Path::new(&from_dir).join("Cargo.toml"); if file_path.exists() { match from_dir.to_str() { @@ -808,10 +812,8 @@ pub(crate) fn get_project_root_for_path(directory: &PathBuf) -> Option { } pub(crate) fn get_project_root() -> Option { - match env::current_dir() { - Ok(directory) => get_project_root_for_path(&directory), - _ => None, - } + let directory = PathBuf::from("."); + get_project_root_for_path(&directory) } fn expand_env_for_script_runner_arguments(task: &mut Task) {