diff --git a/Cargo.lock b/Cargo.lock index f3152ba4ca8..c993f8e6a05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2142,7 +2142,6 @@ dependencies = [ "color-eyre", "const_format", "dirs 4.0.0", - "fm", "hex", "iter-extended", "marlin_arkworks_backend", diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index 11e1f7090cd..49fac9b0178 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -7,12 +7,10 @@ mod file_reader; pub use file_map::{File, FileId, FileMap}; -pub mod util; use std::{ collections::HashMap, path::{Path, PathBuf}, }; -pub use util::*; pub const FILE_EXTENSION: &str = "nr"; diff --git a/crates/fm/src/util.rs b/crates/fm/src/util.rs deleted file mode 100644 index f63ef9b3dc2..00000000000 --- a/crates/fm/src/util.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::fs::ReadDir; -use std::path::{Path, PathBuf}; - -// XXX: These public files are only used in Nargo - -// Looks for file named `file_name` in path -pub fn find_file>(path: P, file_name: &str, extension: &str) -> Option { - let entries = list_files_and_folders_in(path)?; - - let mut file_name = file_name.to_owned(); - file_name.push('.'); - file_name.push_str(extension); - - find_artifact(entries, &file_name) -} -// Looks for directory named `dir_name` in path -pub fn find_dir>(path: P, dir_name: &str) -> Option { - let entries = list_files_and_folders_in(path)?; - find_artifact(entries, dir_name) -} - -// There is no distinction between files and folders -fn find_artifact(entries: ReadDir, artifact_name: &str) -> Option { - let mut entry: Vec<_> = entries - .into_iter() - .flatten() - .filter(|entry| entry.file_name().to_str() == Some(artifact_name)) - .collect(); - - Some(entry.pop()?.path()) -} - -fn list_files_and_folders_in>(path: P) -> Option { - std::fs::read_dir(path).ok() -} diff --git a/crates/nargo/Cargo.toml b/crates/nargo/Cargo.toml index 3cdaf585cf4..99b1044974d 100644 --- a/crates/nargo/Cargo.toml +++ b/crates/nargo/Cargo.toml @@ -20,7 +20,6 @@ iter-extended.workspace = true noirc_driver.workspace = true noirc_frontend.workspace = true noirc_abi.workspace = true -fm.workspace = true acvm.workspace = true cfg-if.workspace = true toml.workspace = true diff --git a/crates/nargo/src/lib.rs b/crates/nargo/src/lib.rs index d9dda910632..e201b1a662d 100644 --- a/crates/nargo/src/lib.rs +++ b/crates/nargo/src/lib.rs @@ -6,7 +6,10 @@ use color_eyre as _; use noirc_frontend::graph::CrateType; -use std::path::{Path, PathBuf}; +use std::{ + fs::ReadDir, + path::{Path, PathBuf}, +}; use crate::errors::CliError; // Nargo is the package manager for Noir @@ -32,7 +35,7 @@ mod toml; /// However, it should only do this after checking the current path /// This allows the use of workspace settings in the future. fn find_package_config(current_path: &Path) -> Result { - match fm::find_file(current_path, "Nargo", "toml") { + match find_file(current_path, "Nargo", "toml") { Some(p) => Ok(p), None => Err(CliError::Generic(format!( "cannot find a Nargo.toml in {}", @@ -44,7 +47,7 @@ fn find_package_config(current_path: &Path) -> Result { fn lib_or_bin(current_path: &Path) -> Result<(PathBuf, CrateType), CliError> { // A library has a lib.nr and a binary has a main.nr // You cannot have both. - let src_path = match fm::find_dir(current_path, "src") { + let src_path = match find_dir(current_path, "src") { Some(path) => path, None => { return Err(CliError::Generic(format!( @@ -53,8 +56,8 @@ fn lib_or_bin(current_path: &Path) -> Result<(PathBuf, CrateType), CliError> { ))) } }; - let lib_nr_path = fm::find_file(&src_path, "lib", "nr"); - let bin_nr_path = fm::find_file(&src_path, "main", "nr"); + let lib_nr_path = find_file(&src_path, "lib", "nr"); + let bin_nr_path = find_file(&src_path, "main", "nr"); match (lib_nr_path, bin_nr_path) { (Some(_), Some(_)) => Err(CliError::Generic( "package cannot contain both a `lib.nr` and a `main.nr`".to_owned(), @@ -66,3 +69,31 @@ fn lib_or_bin(current_path: &Path) -> Result<(PathBuf, CrateType), CliError> { )), } } + +// Looks for file named `file_name` in path +fn find_file>(path: P, file_name: &str, extension: &str) -> Option { + let entries = list_files_and_folders_in(path)?; + let file_name = format!("{file_name}.{extension}"); + + find_artifact(entries, &file_name) +} + +// Looks for directory named `dir_name` in path +fn find_dir>(path: P, dir_name: &str) -> Option { + let entries = list_files_and_folders_in(path)?; + find_artifact(entries, dir_name) +} + +// There is no distinction between files and folders +fn find_artifact(entries: ReadDir, artifact_name: &str) -> Option { + let entry = entries + .into_iter() + .flatten() + .find(|entry| entry.file_name().to_str() == Some(artifact_name))?; + + Some(entry.path()) +} + +fn list_files_and_folders_in>(path: P) -> Option { + std::fs::read_dir(path).ok() +} diff --git a/crates/nargo/src/workspace.rs b/crates/nargo/src/workspace.rs index d5491914337..0954b4eb143 100644 --- a/crates/nargo/src/workspace.rs +++ b/crates/nargo/src/workspace.rs @@ -1,4 +1,4 @@ // We will say that a cargo unit must contain either a binary or a library -// Then we use workspace to allow more than one. In the future, do not allow there to be +// Then we use workspace to allow more than one. In the future, do not allow there to be // both a binary and a library. // - library will be default