diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bee638..b530159 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.2.0] - 2024-09-17 +## [Unreleased] + +#### Fixed + +- Fixed project inference to work with upcoming `snforge` `0.34.0` ## [0.2.0] - 2024-09-17 diff --git a/crates/cairo-coverage/src/main.rs b/crates/cairo-coverage/src/main.rs index e1267bc..a6dadf6 100644 --- a/crates/cairo-coverage/src/main.rs +++ b/crates/cairo-coverage/src/main.rs @@ -64,9 +64,7 @@ fn get_project_path( } else { find_user_project_path(source_sierra_path).context(indoc! { r"Inference of project path failed. - Please provide the project path explicitly using the --project-path flag. - If you are using snforge, it is not possible to use cairo-coverage flags. - You need to run cairo-coverage directly." + Please provide the project path explicitly using the --project-path flag." }) } } @@ -79,25 +77,19 @@ fn find_user_project_path(source_sierra_path: &Utf8PathBuf) -> Result { - source_sierra_path - .parent() - .filter(|parent| parent.file_name() == Some(SNFORGE_SIERRA_DIR)) - .and_then(|parent| parent.parent()) - .map(Utf8PathBuf::from) + navigate_and_check(source_sierra_path, &["target", "dev"]) + .or_else(|| navigate_and_check(source_sierra_path, &[SNFORGE_SIERRA_DIR])) .context(format!( - "Source sierra path should be in the format: /{SNFORGE_SIERRA_DIR}/.sierra.json, got: {source_sierra_path}" + "Source sierra path should be in one of the formats: \ + /{SNFORGE_SIERRA_DIR}/.sierra.json \ + or /target/dev/.sierra.json, got: {source_sierra_path}" )) } Some("contract_class") => { - source_sierra_path - .parent() - .filter(|parent| parent.file_name() == Some("dev")) - .and_then(|parent| parent.parent()) - .filter(|parent| parent.file_name() == Some("target")) - .and_then(|parent| parent.parent()) - .map(Utf8PathBuf::from) + navigate_and_check(source_sierra_path, &["target", "dev"]) .context(format!( - "Source sierra path should be in the format: /target/dev/.contract_class.json, got: {source_sierra_path}" + "Source sierra path should be in the format: \ + /target/dev/.contract_class.json, got: {source_sierra_path}" )) } _ => bail!( @@ -105,3 +97,16 @@ fn find_user_project_path(source_sierra_path: &Utf8PathBuf) -> Result Option { + folders + .iter() + .rev() + .try_fold(path.parent()?, |current, &folder| { + current + .file_name() + .filter(|name| *name == folder) + .map(|_| current.parent())? + }) + .map(Utf8PathBuf::from) +}