From e9d42d0eabaa23f3bdb411634e01ef9402f4c6f6 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Thu, 14 Nov 2024 17:29:18 +0200 Subject: [PATCH] chore(infra): move get_absolute_path function to infra_utils --- Cargo.lock | 1 + crates/infra_utils/src/path.rs | 15 ++++++++++++++- crates/starknet_sequencer_node/Cargo.toml | 1 + .../src/config/node_config.rs | 2 +- crates/starknet_sequencer_node/src/utils.rs | 15 --------------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 594ba06c01e..133a5598ff0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10482,6 +10482,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 7605971f8a5..43786651c1f 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 316d7b77e77..5a91961ff40 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 32dfe68cb6f..3b25b4c2d98 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 0b84c07c858..990ca27d90f 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) -}