Skip to content

Commit

Permalink
[fix]: delete formating from the src code
Browse files Browse the repository at this point in the history
Signed-off-by: Asem-Abdelhady <[email protected]>
  • Loading branch information
Asem-Abdelhady committed Nov 30, 2023
1 parent 2c8e8ac commit 60fb174
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
1 change: 0 additions & 1 deletion cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ fn extract_git_hash() -> Result<()> {
/// Apply `cargo check` to the smartcontract.
fn check_default_executor() -> Result<()> {
iroha_wasm_builder::Builder::new(DEFAULT_EXECUTOR_PATH)
.format()
.check()
}
1 change: 0 additions & 1 deletion client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ fn main() -> Result<()> {

fn check_all_smartcontracts() -> Result<()> {
iroha_wasm_builder::Builder::new(TEST_SMARTCONTRACTS_DIR)
.format()
.check()
}
6 changes: 0 additions & 6 deletions tools/wasm_builder_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ enum Cli {
Build {
#[command(flatten)]
common: CommonArgs,
/// Enable smartcontract formatting using `cargo fmt`.
// TODO: why it is a part of `build` in wasm_builder?
#[arg(long)]
format: bool,
/// Optimize WASM output.
#[arg(long)]
optimize: bool,
Expand All @@ -48,12 +44,10 @@ fn main() -> color_eyre::Result<()> {
}
Cli::Build {
common: CommonArgs { path },
format,
optimize,
outfile,
} => {
let builder = Builder::new(&path).show_output();
let builder = if format { builder.format() } else { builder };

let output = {
// not showing the spinner here, cargo does a progress bar for us
Expand Down
43 changes: 2 additions & 41 deletions wasm_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const TOOLCHAIN: &str = "+nightly-2023-06-25";
/// fn main() -> Result<()> {
/// let bytes = Builder::new("relative/path/to/smartcontract/")
/// .out_dir("path/to/out/dir") // Optional: Set output directory
/// .format() // Optional: Enable smartcontract formatting
/// .build()? // Run build
/// .optimize()? // Optimize WASM output
/// .into_bytes()?; // Get resulting WASM bytes
Expand All @@ -44,8 +43,6 @@ pub struct Builder<'path, 'out_dir> {
path: &'path Path,
/// Build output directory
out_dir: Option<&'out_dir Path>,
/// Flag to enable smartcontract formatting
format: bool,
/// Flag controlling whether to show output of the build process
show_output: bool,
}
Expand All @@ -61,7 +58,6 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
Self {
path: relative_path.as_ref(),
out_dir: None,
format: false,
show_output: false,
}
}
Expand All @@ -79,14 +75,6 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
self
}

/// Enable smartcontract formatting using `cargo fmt`.
///
/// Disabled by default.
pub fn format(mut self) -> Self {
self.format = true;
self
}

/// Enable showing output of the build process.
///
/// Disabled by default.
Expand All @@ -99,7 +87,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
///
/// # Errors
///
/// Can fail due to multiple reasons like invalid path, failed formatting, failed build, etc.
/// Can fail due to multiple reasons like invalid path, failed build, etc.
pub fn check(self) -> Result<()> {
self.into_internal()?.check()
}
Expand All @@ -108,8 +96,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
///
/// # Errors
///
/// Can fail due to multiple reasons like invalid path, failed formatting,
/// failed build, etc.
/// Can fail due to multiple reasons like invalid path, failed build, etc.
///
/// Will also return error if ran on workspace and not on the concrete package.
pub fn build(self) -> Result<Output> {
Expand All @@ -126,7 +113,6 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
|| -> Result<_> { Ok(Cow::Owned(Self::default_out_dir()?)) },
|out_dir| Ok(Cow::Borrowed(out_dir)),
)?,
format: self.format,
show_output: self.show_output,
})
}
Expand Down Expand Up @@ -180,14 +166,11 @@ mod internal {
pub struct Builder<'out_dir> {
pub absolute_path: PathBuf,
pub out_dir: Cow<'out_dir, Path>,
pub format: bool,
pub show_output: bool,
}

impl Builder<'_> {
pub fn check(self) -> Result<()> {
self.maybe_format()?;

self.check_smartcontract().wrap_err_with(|| {
format!(
"Failed to check the smartcontract at path: {}",
Expand All @@ -197,8 +180,6 @@ mod internal {
}

pub fn build(self) -> Result<Output> {
self.maybe_format()?;

let absolute_path = self.absolute_path.clone();
self.build_smartcontract().wrap_err_with(|| {
format!(
Expand All @@ -208,18 +189,6 @@ mod internal {
})
}

fn maybe_format(&self) -> Result<()> {
if self.format {
self.format_smartcontract().wrap_err_with(|| {
format!(
"Failed to format the smartcontract at path: {}",
self.absolute_path.display()
)
})?;
}
Ok(())
}

fn build_options() -> impl Iterator<Item = &'static str> {
[
"--release",
Expand All @@ -235,14 +204,6 @@ mod internal {
.into_iter()
}

fn format_smartcontract(&self) -> Result<()> {
check_command(
self.show_output,
cargo_command().current_dir(&self.absolute_path).arg("fmt"),
"cargo fmt",
)
}

fn get_base_command(&self, cmd: &'static str) -> std::process::Command {
let mut command = cargo_command();
command
Expand Down

0 comments on commit 60fb174

Please sign in to comment.