Skip to content

Commit

Permalink
Build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Oct 18, 2024
1 parent 0d3901a commit 35ba29d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/lib/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions src/lib/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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() {
Expand All @@ -808,10 +812,8 @@ pub(crate) fn get_project_root_for_path(directory: &PathBuf) -> Option<String> {
}

pub(crate) fn get_project_root() -> Option<String> {
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) {
Expand Down

0 comments on commit 35ba29d

Please sign in to comment.