From 635ccb1af0ae7703071dda2bf058d91e2b1ee4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20P=C5=82askonka?= Date: Tue, 9 Jan 2024 13:12:35 +0100 Subject: [PATCH] Optimize wasm files in modules. Clean wasm files in modules. --- Cargo.lock | 2 +- src/actions/build.rs | 7 ++++++- src/actions/clean.rs | 20 ++++++++------------ src/actions/generate.rs | 6 ++++-- src/cli.rs | 2 +- src/project.rs | 4 ++-- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2bc9814..528a2dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,7 +231,7 @@ dependencies = [ [[package]] name = "cargo-odra" -version = "0.2.0" +version = "0.1.0" dependencies = [ "cargo-generate", "cargo_toml", diff --git a/src/actions/build.rs b/src/actions/build.rs index f0b3f53..a5d4b40 100644 --- a/src/actions/build.rs +++ b/src/actions/build.rs @@ -104,8 +104,13 @@ impl BuildAction<'_> { fn optimize_wasm_files(&self) { log::info("Optimizing wasm files..."); for contract in self.contracts() { - // TODO: Optimize wasm files in modules command::wasm_strip(&contract.name, self.project.project_root()); + if contract.module_name() != self.project.name { + command::wasm_strip( + &contract.name, + self.project.project_root().join(contract.module_name()), + ); + } } } diff --git a/src/actions/clean.rs b/src/actions/clean.rs index f31db7e..0b6c9b2 100644 --- a/src/actions/clean.rs +++ b/src/actions/clean.rs @@ -1,18 +1,14 @@ //! Module responsible for cleaning Odra projects. -use std::path::PathBuf; +use crate::{command, project::Project}; -use crate::command; +/// Removes wasm folders, and runs `cargo clean`. +pub fn clean_action(project: &Project) { + project.members.iter().for_each(|member| { + command::rm_dir(member.root.join("wasm")); + }); -/// Removes wasm folder, .builder* folders and runs `cargo clean`. -pub fn clean_action(project_root: PathBuf) { - // TODO: Clean wasm folders of modules - for folder in glob::glob(project_root.join("wasm/*").as_os_str().to_str().unwrap()) - .unwrap() - .flatten() - { - command::rm_dir(folder); - } + command::rm_dir(project.project_root().join("wasm")); - command::cargo_clean(project_root); + command::cargo_clean(project.project_root()); } diff --git a/src/actions/generate.rs b/src/actions/generate.rs index a4507e8..471ccf0 100644 --- a/src/actions/generate.rs +++ b/src/actions/generate.rs @@ -19,6 +19,7 @@ use crate::{ pub struct GenerateAction<'a> { project: &'a Project, contract_name: String, + contract_module_ident: String, module_root: PathBuf, module_name: String, template_generator: TemplateGenerator, @@ -30,7 +31,8 @@ impl<'a> GenerateAction<'a> { pub fn new(project: &'a Project, contract_name: String, module_name: Option) -> Self { GenerateAction { project, - contract_name, + contract_name: contract_name.clone(), + contract_module_ident: contract_name.to_case(Case::UpperCamel), module_root: project.module_root(module_name.clone()), module_name: project.module_name(module_name), template_generator: TemplateGenerator::new( @@ -116,7 +118,7 @@ impl GenerateAction<'_> { // Check if he file might have the module registered in another form. if lib_rs.contains(self.contract_name()) - || (lib_rs.contains(self.module_ident()) && lib_rs.contains(&self.module_ref_ident())) + || (lib_rs.contains(&self.module_ident()) && lib_rs.contains(&self.module_ref_ident())) { log::warn(format!( "src/lib.rs probably already has {} enabled. Skipping.", diff --git a/src/cli.rs b/src/cli.rs index ebe2121..18db60f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -165,7 +165,7 @@ pub fn make_action() { } OdraSubcommand::Clean(_) => { let project = Project::detect(current_dir); - clean_action(project.project_root()); + clean_action(&project); } OdraSubcommand::Update(update) => { let project = Project::detect(current_dir); diff --git a/src/project.rs b/src/project.rs index 229fcad..e3246ab 100644 --- a/src/project.rs +++ b/src/project.rs @@ -167,7 +167,7 @@ impl Project { Error::NotAnOdraProject.print_and_die(); }); let root = odra_toml_path.parent().unwrap().to_path_buf(); - let members = Self::find_members(&cargo_toml_path, &odra_toml_path); + let members = Self::members(&cargo_toml_path, &odra_toml_path); let name = match load_cargo_toml(&cargo_toml_path).package { None => { let cwd = env::current_dir().unwrap(); @@ -268,7 +268,7 @@ impl Project { } } - fn find_members(cargo_toml_path: &PathBuf, odra_toml_path: &Path) -> Vec { + pub fn members(cargo_toml_path: &PathBuf, odra_toml_path: &Path) -> Vec { Self::detect_members(cargo_toml_path, odra_toml_path) .iter() .map(|member| {