Skip to content

Commit

Permalink
rebuild project if the metadata is not present or invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
SkymanOne committed Sep 1, 2023
1 parent a8f3d95 commit 67b3620
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,9 @@ fn check_buffer_size_invoke_cargo_clean(
.parse()
.context("`INK_STATIC_BUFFER_SIZE` must have an integer value.")?;

let cargo = util::cargo_cmd(
"clean",
Vec::<&str>::new(),
crate_metadata.manifest_path.directory(),
*verbosity,
vec![],
);

if let Ok(metadata) = ContractMetadata::load(crate_metadata.metadata_path()) {
let contract_buffer_size = metadata
let extract_buffer_size = |metadata_path: PathBuf| -> Result<u64> {
let size = ContractMetadata::load(metadata_path)
.context("Metadata is not present")?
.abi
// get `spec` field
.get("spec")
Expand All @@ -407,25 +400,48 @@ fn check_buffer_size_invoke_cargo_clean(
.as_u64()
.context("`staticBufferSize` value must be an integer.")?;

if contract_buffer_size == buffer_size_value {
Ok(size)
};

let cargo = util::cargo_cmd(
"clean",
Vec::<&str>::new(),
crate_metadata.manifest_path.directory(),
*verbosity,
vec![],
);

match extract_buffer_size(crate_metadata.metadata_path()) {
Ok(contract_buffer_size) if contract_buffer_size == buffer_size_value => {
verbose_eprintln!(
verbosity,
"{} {}",
"info:".green().bold(),
"Detected a configured buffer size, but the value is already specified."
.bold()
);
return Ok(())
}
Ok(_) => {
verbose_eprintln!(
verbosity,
"{} {}",
"warning:".yellow().bold(),
"Detected a change in the configured buffer size. Rebuilding the project."
.bold()
);
invoke_cargo_and_scan_for_error(cargo)?;
}
Err(_) => {
verbose_eprintln!(
verbosity,
"{} {}",
"warning:".yellow().bold(),
"Cannot find the previous size of the static buffer. Rebuilding the project."
.bold()
);
invoke_cargo_and_scan_for_error(cargo)?;
}
}
verbose_eprintln!(
verbosity,
"{} {}",
"warning:".yellow().bold(),
"Detected a change in the configured buffer size. Rebuilding the project."
.bold()
);
invoke_cargo_and_scan_for_error(cargo)?;
}
Ok(())
}
Expand Down

0 comments on commit 67b3620

Please sign in to comment.