-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sozo] Detect and manage manifests and artifacts discrepancies (#1672)
feat: detect and manage manifests and artifacts discrepancies `sozo` uses several file types (previously generated by `sozo build` and `sozo migrate`) as input for migration. All of these files may be corrupt or may have discrepancies due to an older format version. This PR introduces a new `sozo clean` command to clean the project of these files. `sozo clean --manifest-abis` cleans only manifest and ABI files. `sozo clean --artifacts` cleans only artifacts. When an anomaly is detected in a file, the user is informed of the problem and advised to run `sozo clean` to clean up the project.
- Loading branch information
Showing
6 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::fs; | ||
|
||
use anyhow::Result; | ||
use camino::Utf8PathBuf; | ||
use clap::Args; | ||
use dojo_lang::compiler::{ABIS_DIR, MANIFESTS_DIR}; | ||
use scarb::core::Config; | ||
|
||
#[derive(Debug, Args)] | ||
pub struct CleanArgs { | ||
#[arg(short, long)] | ||
#[arg(help = "Remove manifests and abis only.")] | ||
#[arg(long_help = "Remove manifests and abis only.")] | ||
pub manifests_abis: bool, | ||
|
||
#[arg(short, long)] | ||
#[arg(help = "Remove artifacts only.")] | ||
#[arg(long_help = "Remove artifacts only.")] | ||
pub artifacts: bool, | ||
} | ||
|
||
impl CleanArgs { | ||
pub fn clean_manifests_abis(&self, root_dir: &Utf8PathBuf) -> Result<()> { | ||
let manifest_dir = root_dir.join(MANIFESTS_DIR); | ||
let abis_dir = root_dir.join(ABIS_DIR); | ||
|
||
if manifest_dir.exists() { | ||
fs::remove_dir_all(manifest_dir)?; | ||
} | ||
|
||
if abis_dir.exists() { | ||
fs::remove_dir_all(abis_dir)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn run(self, config: &Config) -> Result<()> { | ||
let ws = scarb::ops::read_workspace(config.manifest_path(), config)?; | ||
|
||
let clean_manifests_abis = self.manifests_abis || !self.artifacts; | ||
let clean_artifacts = self.artifacts || !self.manifests_abis; | ||
|
||
if clean_manifests_abis { | ||
let manifest_dir = ws.manifest_path().parent().unwrap().to_path_buf(); | ||
self.clean_manifests_abis(&manifest_dir)?; | ||
} | ||
|
||
if clean_artifacts { | ||
scarb::ops::clean(config)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters