Skip to content

Commit

Permalink
Optimize wasm files in modules.
Browse files Browse the repository at this point in the history
Clean wasm files in modules.
  • Loading branch information
kubaplas committed Jan 9, 2024
1 parent 08054c9 commit 635ccb1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/actions/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
);
}
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/actions/clean.rs
Original file line number Diff line number Diff line change
@@ -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());
}
6 changes: 4 additions & 2 deletions src/actions/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,7 +31,8 @@ impl<'a> GenerateAction<'a> {
pub fn new(project: &'a Project, contract_name: String, module_name: Option<String>) -> 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(
Expand Down Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -268,7 +268,7 @@ impl Project {
}
}

fn find_members(cargo_toml_path: &PathBuf, odra_toml_path: &Path) -> Vec<Member> {
pub fn members(cargo_toml_path: &PathBuf, odra_toml_path: &Path) -> Vec<Member> {
Self::detect_members(cargo_toml_path, odra_toml_path)
.iter()
.map(|member| {
Expand Down

0 comments on commit 635ccb1

Please sign in to comment.