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

Display build progress with --output-json, print to stderr #1211

Merged
merged 5 commits into from
Jul 12, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Dry-run result output improvements [1123](https://github.com/paritytech/cargo-contract/pull/1123)
- Display build progress with --output-json, print to stderr [1211](https://github.com/paritytech/cargo-contract/pull/1211)

### Fixed
- Configure tty output correctly - [#1209]((https://github.com/paritytech/cargo-contract/pull/1209))
Expand Down
15 changes: 7 additions & 8 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ fn exec_cargo_for_onchain_target(

// newer rustc versions might emit unsupported instructions
if rustc_version::version_meta()?.semver >= Version::new(1, 70, 0) {
maybe_println!(
verbosity,
eprintln!(
"{} {}",
"warning:".yellow().bold(),
"You are using a rustc version that might emit unsupported wasm instructions. Build using a version lower than 1.70.0 to make sure your contract will deploy."
Expand Down Expand Up @@ -334,7 +333,7 @@ fn exec_cargo_for_onchain_target(
};

if unstable_flags.original_manifest {
maybe_println!(
verbose_eprintln!(
verbosity,
"{} {}",
"warning:".yellow().bold(),
Expand Down Expand Up @@ -606,7 +605,7 @@ fn post_process_wasm(
if !skip_wasm_validation {
validate_wasm::validate_import_section(&module)?;
} else {
maybe_println!(
verbose_eprintln!(
verbosity,
" {}",
"Skipping wasm validation! Contract code may be invalid."
Expand Down Expand Up @@ -718,7 +717,7 @@ pub fn execute(args: ExecuteArgs) -> Result<BuildResult> {
let total_steps = build_artifact.steps();
if lint {
steps.set_total_steps(total_steps + 1);
maybe_println!(
verbose_eprintln!(
verbosity,
" {} {}",
format!("{steps}").bold(),
Expand All @@ -738,7 +737,7 @@ pub fn execute(args: ExecuteArgs) -> Result<BuildResult> {
let mut build_steps = BuildSteps::new();
let pre_fingerprint = Fingerprint::new(&crate_metadata)?;

maybe_println!(
verbose_eprintln!(
verbosity,
" {} {}",
format!("{build_steps}").bold(),
Expand Down Expand Up @@ -808,7 +807,7 @@ pub fn execute(args: ExecuteArgs) -> Result<BuildResult> {

maybe_lint(&mut build_steps)?;

maybe_println!(
verbose_eprintln!(
verbosity,
" {} {}",
format!("{build_steps}").bold(),
Expand Down Expand Up @@ -873,7 +872,7 @@ pub fn execute(args: ExecuteArgs) -> Result<BuildResult> {
let mut build_steps = BuildSteps::new();
maybe_lint(&mut build_steps)?;

maybe_println!(
verbose_eprintln!(
verbosity,
" {} {}",
format!("{build_steps}").bold(),
Expand Down
6 changes: 3 additions & 3 deletions crates/build/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use crate::{
code_hash,
crate_metadata::CrateMetadata,
maybe_println,
util,
verbose_eprintln,
workspace::{
ManifestPath,
Workspace,
Expand Down Expand Up @@ -128,7 +128,7 @@ pub(crate) fn execute(
} = extended_metadata(crate_metadata, final_contract_wasm, build_info)?;

let generate_metadata = |manifest_path: &ManifestPath| -> Result<()> {
maybe_println!(
verbose_eprintln!(
verbosity,
" {} {}",
format!("{build_steps}").bold(),
Expand Down Expand Up @@ -169,7 +169,7 @@ pub(crate) fn execute(
build_steps.increment_current();
}

maybe_println!(
verbose_eprintln!(
verbosity,
" {} {}",
format!("{build_steps}").bold(),
Expand Down
7 changes: 4 additions & 3 deletions crates/build/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ pub fn decode_hex(input: &str) -> Result<Vec<u8>, hex::FromHexError> {
hex::decode(input.trim_start_matches("0x"))
}

/// Prints to stdout if `verbosity.is_verbose()` is `true`.
/// Prints to stderr if `verbosity.is_verbose()` is `true`.
/// Like `cargo`, we use stderr for verbose output.
#[macro_export]
macro_rules! maybe_println {
macro_rules! verbose_eprintln {
($verbosity:expr, $($msg:tt)*) => {
if $verbosity.is_verbose() {
::std::println!($($msg)*);
::std::eprintln!($($msg)*);
}
};
}
Expand Down
7 changes: 1 addition & 6 deletions crates/cargo-contract/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl BuildCommand {
let manifest_path = ManifestPath::try_from(self.manifest_path.as_ref())?;
let unstable_flags: UnstableFlags =
TryFrom::<&UnstableOptions>::try_from(&self.unstable_options)?;
let mut verbosity = TryFrom::<&VerbosityFlags>::try_from(&self.verbosity)?;
let verbosity = TryFrom::<&VerbosityFlags>::try_from(&self.verbosity)?;

let build_mode = match self.build_release {
true => BuildMode::Release,
Expand All @@ -145,11 +145,6 @@ impl BuildCommand {
false => OutputType::HumanReadable,
};

// We want to ensure that the only thing in `STDOUT` is our JSON formatted string.
if matches!(output_type, OutputType::Json) {
verbosity = Verbosity::Quiet;
}

let args = ExecuteArgs {
manifest_path,
verbosity,
Expand Down