Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore forge-std artifacts in build --sizes #7414

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,16 @@ impl ProjectCompiler {
}

let mut size_report = SizeReport { contracts: BTreeMap::new() };
let artifacts: BTreeMap<_, _> = output.artifacts().collect();

let artifacts: BTreeMap<_, _> = output
.artifact_ids()
.filter(|(id, _)| {
// filter out forge-std specific contracts
!id.source.to_string_lossy().contains("/forge-std/src/")
})
.map(|(id, artifact)| (id.name, artifact))
.collect();

for (name, artifact) in artifacts {
let size = deployed_contract_size(artifact).unwrap_or_default();

Expand Down Expand Up @@ -381,6 +390,7 @@ impl Display for SizeReport {
Cell::new("Margin (kB)").add_attribute(Attribute::Bold).fg(Color::Blue),
]);

// filters out non dev contracts (Test or Script)
let contracts = self.contracts.iter().filter(|(_, c)| !c.is_dev_contract && c.size > 0);
for (name, contract) in contracts {
let margin = CONTRACT_SIZE_LIMIT as isize - contract.size as isize;
Expand Down
9 changes: 9 additions & 0 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ forgetest_init!(exact_build_output, |prj, cmd| {
let stdout = cmd.stdout_lossy();
assert!(stdout.contains("Compiling"), "\n{stdout}");
});

// tests build output is as expected
forgetest_init!(build_sizes_no_forge_std, |prj, cmd| {
cmd.args(["build", "--sizes"]);
let stdout = cmd.stdout_lossy();
assert!(!stdout.contains("console"), "\n{stdout}");
assert!(!stdout.contains("std"), "\n{stdout}");
assert!(stdout.contains("Counter"), "\n{stdout}");
});
Loading