From 7fc8dac94979fedccb76ca57775d41af0355816e Mon Sep 17 00:00:00 2001 From: lambda-0x <0xlambda@protonmail.com> Date: Wed, 12 Jun 2024 16:54:16 +0530 Subject: [PATCH] clean old manifest times during build to remove unused manifets --- bin/sozo/src/commands/build.rs | 15 +++++++++++++++ bin/sozo/src/commands/clean.rs | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/sozo/src/commands/build.rs b/bin/sozo/src/commands/build.rs index dd0fd329f9..14faaf5eb8 100644 --- a/bin/sozo/src/commands/build.rs +++ b/bin/sozo/src/commands/build.rs @@ -1,6 +1,7 @@ use anyhow::{Context, Result}; use clap::Args; use dojo_bindgen::{BuiltinPlugins, PluginManager}; +use dojo_lang::compiler::MANIFESTS_DIR; use dojo_lang::scarb_internal::compile_workspace; use dojo_world::metadata::dojo_metadata_from_workspace; use prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE; @@ -10,6 +11,8 @@ use scarb::ops::{CompileOpts, FeaturesOpts, FeaturesSelector}; use sozo_ops::statistics::{get_contract_statistics_for_dir, ContractStatistics}; use tracing::trace; +use crate::commands::clean::CleanArgs; + const BYTECODE_SIZE_LABEL: &str = "Bytecode size [in felts]\n(Sierra, Casm)"; const CONTRACT_CLASS_SIZE_LABEL: &str = "Contract Class size [in bytes]\n(Sierra, Casm)"; @@ -40,6 +43,18 @@ pub struct BuildArgs { impl BuildArgs { pub fn run(self, config: &Config) -> Result<()> { + let ws = scarb::ops::read_workspace(config.manifest_path(), config)?; + + let profile_name = + ws.current_profile().expect("Scarb profile is expected at this point.").to_string(); + + // Manifest path is always a file, we can unwrap safely to get the + // parent folder. + let manifest_dir = ws.manifest_path().parent().unwrap().to_path_buf(); + + let profile_dir = manifest_dir.join(MANIFESTS_DIR).join(profile_name); + CleanArgs::clean_manifests(&profile_dir)?; + let features_opts = FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; diff --git a/bin/sozo/src/commands/clean.rs b/bin/sozo/src/commands/clean.rs index 0efd2c029d..9374a79c9a 100644 --- a/bin/sozo/src/commands/clean.rs +++ b/bin/sozo/src/commands/clean.rs @@ -21,7 +21,7 @@ impl CleanArgs { /// # Arguments /// /// * `profile_dir` - The directory where the profile files are located. - pub fn clean_manifests(&self, profile_dir: &Utf8PathBuf) -> Result<()> { + pub fn clean_manifests(profile_dir: &Utf8PathBuf) -> Result<()> { trace!(?profile_dir, "Cleaning manifests."); let dirs = vec![profile_dir.join(BASE_DIR), profile_dir.join(ABIS_DIR).join(BASE_DIR)]; @@ -51,7 +51,7 @@ impl CleanArgs { // By default, this command cleans the build manifests and scarb artifacts. trace!("Cleaning Scarb artifacts and build manifests."); scarb::ops::clean(config)?; - self.clean_manifests(&profile_dir)?; + Self::clean_manifests(&profile_dir)?; if self.all && profile_dir.exists() { trace!(?profile_dir, "Removing entire profile directory.");