diff --git a/Cargo.lock b/Cargo.lock index 8a6ee4eb6a..67e2b849f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10481,6 +10481,7 @@ dependencies = [ "colored", "const_format", "futures", + "infra_utils", "mempool_test_utils", "papyrus_config", "papyrus_proc_macros", diff --git a/crates/infra_utils/src/path.rs b/crates/infra_utils/src/path.rs index 7605971f8a..43786651c1 100644 --- a/crates/infra_utils/src/path.rs +++ b/crates/infra_utils/src/path.rs @@ -1 +1,14 @@ -// TODO(Arni): Move the function get_absolute_path to this file. +use std::env; +use std::path::PathBuf; + +// TODO(Tsabary/ Arni): consolidate with other get_absolute_path functions. +/// Returns the absolute path from the project root. +pub fn get_absolute_path(relative_path: &str) -> PathBuf { + let base_dir = env::var("CARGO_MANIFEST_DIR") + // Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`. + // Ascend two directories ("../..") to get to the project root. + .map(|dir| PathBuf::from(dir).join("../..")) + // If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory + .unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory")); + base_dir.join(relative_path) +} diff --git a/crates/starknet_sequencer_node/Cargo.toml b/crates/starknet_sequencer_node/Cargo.toml index 316d7b77e7..5a91961ff4 100644 --- a/crates/starknet_sequencer_node/Cargo.toml +++ b/crates/starknet_sequencer_node/Cargo.toml @@ -16,6 +16,7 @@ anyhow.workspace = true clap.workspace = true const_format.workspace = true futures.workspace = true +infra_utils.workspace = true papyrus_config.workspace = true papyrus_proc_macros = { workspace = true, optional = true } rstest.workspace = true diff --git a/crates/starknet_sequencer_node/src/config/node_config.rs b/crates/starknet_sequencer_node/src/config/node_config.rs index 32dfe68cb6..3b25b4c2d9 100644 --- a/crates/starknet_sequencer_node/src/config/node_config.rs +++ b/crates/starknet_sequencer_node/src/config/node_config.rs @@ -5,6 +5,7 @@ use std::sync::LazyLock; use std::vec::Vec; use clap::Command; +use infra_utils::path::get_absolute_path; use papyrus_config::dumping::{ append_sub_config_name, generate_struct_pointer, @@ -28,7 +29,6 @@ use starknet_sierra_compile::config::SierraToCasmCompilationConfig; use validator::Validate; use crate::config::component_config::ComponentConfig; -use crate::utils::get_absolute_path; use crate::version::VERSION_FULL; // The path of the default configuration file, provided as part of the crate. diff --git a/crates/starknet_sequencer_node/src/utils.rs b/crates/starknet_sequencer_node/src/utils.rs index 0b84c07c85..990ca27d90 100644 --- a/crates/starknet_sequencer_node/src/utils.rs +++ b/crates/starknet_sequencer_node/src/utils.rs @@ -1,6 +1,3 @@ -use std::env; -use std::path::PathBuf; - use crate::clients::{create_node_clients, SequencerNodeClients}; use crate::communication::create_node_channels; use crate::components::create_node_components; @@ -17,15 +14,3 @@ pub fn create_node_modules( (clients, servers) } - -// TODO(Tsabary): consolidate with other get_absolute_path functions. -/// Returns the absolute path from the project root. -pub fn get_absolute_path(relative_path: &str) -> PathBuf { - let base_dir = env::var("CARGO_MANIFEST_DIR") - // Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`. - // Ascend two directories ("../..") to get to the project root. - .map(|dir| PathBuf::from(dir).join("../..")) - // If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory - .unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory")); - base_dir.join(relative_path) -}