From 4582f67891b88744d905faaf39f9caf72247faeb Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Mon, 27 Feb 2023 07:46:03 +1000 Subject: [PATCH] feat(forc-pkg): Improve workspace build summary (#4188) *This PR is based on #4187 - will rebase to master once it lands.* --- ## Description Previously when building a large workspace, the build would often end followed by a bunch of lines saying "Bytecode size is ..." or "Bytecode hash is ...", without any indication of which workspace member the information was associated with. This changes the behaviour to first output a "Finished" line, followed by build output summary info clearly separated by the workspace member. Closes #3779. Here's an example of building our `examples/` workspace previously: ![Screenshot from 2023-02-26 21-48-18](https://user-images.githubusercontent.com/4587373/221406514-b4ee406b-7804-40e7-8710-a2febc902032.png) And here's the output with this PR: ![Screenshot from 2023-02-26 21-49-14](https://user-images.githubusercontent.com/4587373/221406525-b709749d-22ba-4677-ad39-8eec15c5392d.png) ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --- forc-pkg/src/pkg.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index 6236e6d5745..13b6cecc9db 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -434,7 +434,7 @@ impl BuiltPackage { } } - info!(" Bytecode size is {} bytes.", self.bytecode.len()); + info!(" Bytecode size: {} bytes", self.bytecode.len()); // Additional ops required depending on the program type match self.tree_type { TreeType::Contract => { @@ -458,7 +458,7 @@ impl BuiltPackage { let root_file_name = format!("{}{}", &pkg_name, SWAY_BIN_ROOT_SUFFIX); let root_path = output_dir.join(root_file_name); fs::write(root_path, &root)?; - info!(" Predicate root: {}", root); + info!(" Predicate root: {}", root); } TreeType::Script => { // hash the bytecode for scripts and store the result in a file in the output directory @@ -466,7 +466,7 @@ impl BuiltPackage { let hash_file_name = format!("{}{}", &pkg_name, SWAY_BIN_HASH_SUFFIX); let hash_path = output_dir.join(hash_file_name); fs::write(hash_path, &bytecode_hash)?; - info!(" Script bytecode hash: {}", bytecode_hash); + info!(" Bytecode hash: {}", bytecode_hash); } _ => (), } @@ -1971,6 +1971,7 @@ pub fn build_with_options(build_options: BuildOpts) -> Result { // Build it! let mut built_workspace = HashMap::new(); + let build_start = std::time::Instant::now(); let built_packages = build( &build_plan, *build_target, @@ -1979,7 +1980,11 @@ pub fn build_with_options(build_options: BuildOpts) -> Result { const_inject_map, )?; let output_dir = pkg.output_directory.as_ref().map(PathBuf::from); + + let finished = ansi_term::Colour::Green.bold().paint("Finished"); + info!(" {finished} {profile_name} in {:?}", build_start.elapsed()); for (node_ix, built_package) in built_packages.into_iter() { + print_pkg_summary_header(&built_package); let pinned = &graph[node_ix]; let pkg_manifest = manifest_map .get(&pinned.id()) @@ -2009,6 +2014,18 @@ pub fn build_with_options(build_options: BuildOpts) -> Result { } } +fn print_pkg_summary_header(built_pkg: &BuiltPackage) { + let prog_ty_str = forc_util::program_type_str(&built_pkg.tree_type); + // The ansi_term formatters ignore the `std::fmt` right-align + // formatter, so we manually calculate the padding to align the program + // type and name around the 10th column ourselves. + let padded_ty_str = format!("{prog_ty_str:>10}"); + let padding = &padded_ty_str[..padded_ty_str.len() - prog_ty_str.len()]; + let ty_ansi = ansi_term::Colour::Green.bold().paint(prog_ty_str); + let name_ansi = ansi_term::Style::new().bold().paint(&built_pkg.pkg_name); + info!("{padding}{ty_ansi} {name_ansi}"); +} + /// Returns the ContractId of a built_package contract with specified `salt`. pub fn contract_id(built_package: &BuiltPackage, salt: &fuel_tx::Salt) -> ContractId { // Construct the contract ID