diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c5750d..d86c2c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. `cargo-comp #### 3.x Releases -- `3.2.x` Releases - [3.2.0](#320) +- `3.2.x` Releases - [3.2.0](#320) | [3.2.1](#321) - `3.1.x` Releases - [3.1.0](#310) - `3.0.x` Releases - [3.0.0](#300) | [3.0.1](#301) @@ -19,6 +19,16 @@ All notable changes to this project will be documented in this file. `cargo-comp --- +## [3.2.1](https://github.com/bitslab/cargo-compiler-interrupts/releases/tag/3.2.1) + +Released on 2021-08-04. + +#### Updated + +- Documentation and dependencies. +- `cargo-build-ci` + - Progress indicator is more aware of terminal size changes. + ## [3.2.0](https://github.com/bitslab/cargo-compiler-interrupts/releases/tag/3.2.0) Released on 2021-07-31. @@ -34,7 +44,7 @@ Released on 2021-07-31. - Various path-related helper functions are renamed. - `cargo-build-ci` - - Fix a race condition between integration threads and progress indicator threads when integration thread failed unexpectedly. + - Fix a race condition between integration threads and progress indicator thread when integration thread failed unexpectedly. - Failed integration can now be run again without using `cargo clean`. - `cargo-lib-ci` - Fix wrong output formatting while the progress indicator is showing. diff --git a/Cargo.toml b/Cargo.toml index f3fe44e..83b91ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license = "MIT" name = "cargo-compiler-interrupts" readme = "README.md" repository = "https://github.com/bitslab/cargo-compiler-interrupts" -version = "3.2.0" +version = "3.2.1" [dependencies] anyhow = "1.0" @@ -19,15 +19,15 @@ cargo-util = {version = "0.1.0", path = "crates/cargo-util"} cargo_metadata = "0.13" chrono = "0.4" clap = "3.0.0-beta.2" -colored = "2" +colored = "2.0" crossbeam-utils = "0.8" dirs = "3.0" faccess = "0.2" -indicatif = "0.16" +indicatif = "0.17.0-beta.1" md5 = "0.7" num_cpus = "1.13" serde = "1.0" -term_size = "1.0.0-beta.2" +terminal_size = "0.1" thiserror = "1.0" toml = "0.5" tracing = "0.1" diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs index 8d381c2..be8dd2b 100644 --- a/crates/cargo-util/src/paths.rs +++ b/crates/cargo-util/src/paths.rs @@ -164,7 +164,7 @@ pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> .with_context(|| format!("failed to write `{}`", path.display())) } -/// Equivalent to [`write`], but does not write anything if the file contents +/// Equivalent to [`write()`], but does not write anything if the file contents /// are identical to the given contents. pub fn write_if_changed, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { (|| -> Result<()> { @@ -635,7 +635,7 @@ pub fn create_dir_all_excluded_from_backups_atomic>(p: P) -> Resu let parent = path.parent().unwrap(); let base = path.file_name().unwrap(); create_dir_all(parent)?; - // We do this in two steps (first create a temporary directory and exlucde + // We do this in two steps (first create a temporary directory and exclude // it from backups, then rename it to the desired name. If we created the // directory directly where it should be and then excluded it from backups // we would risk a situation where cargo is interrupted right after the directory @@ -653,7 +653,7 @@ pub fn create_dir_all_excluded_from_backups_atomic>(p: P) -> Resu // here to create the directory directly and fs::create_dir_all() explicitly treats // the directory being created concurrently by another thread or process as success, // hence the check below to follow the existing behavior. If we get an error at - // rename() and suddently the directory (which didn't exist a moment earlier) exists + // rename() and suddenly the directory (which didn't exist a moment earlier) exists // we can infer from it it's another cargo process doing work. if let Err(e) = fs::rename(tempdir.path(), path) { if !path.exists() { diff --git a/src/error.rs b/src/error.rs index e39d6e9..cb34428 100644 --- a/src/error.rs +++ b/src/error.rs @@ -21,14 +21,22 @@ pub enum CIError { Path to the library: {0}\n\ Run `cargo lib-ci --update` to update the library if needed" )] - LibraryAlreadyInstalled(String), + LibraryAlreadyInstalled( + /// Path to the library. + String, + ), /// LLVM version between Rust and LLVM toolchain does not match. #[error( "LLVM version from Rust toolchain ({0}) does not match with the\ LLVM version from LLVM toolchain ({1})" )] - LLVMVersionNotMatch(String, String), + LLVMVersionNotMatch( + /// LLVM version from Rust toolchain. + String, + /// LLVM version from LLVM toolchain. + String, + ), /// LLVM toolchain is not installed. #[error( @@ -39,14 +47,24 @@ pub enum CIError { /// LLVM version is not supported. #[error("LLVM version {0} is not supported. Minimum supported LLVM version is {1}")] - LLVMNotSupported(String, String), + LLVMNotSupported( + /// LLVM version. + String, + /// Minimum supported LLVM version + String, + ), /// Binary is not available. #[error( "Failed to execute the binary '{0}'\n\ Available binaries: {1}" )] - BinaryNotAvailable(String, String), + BinaryNotAvailable( + /// Name of the unavailable binary. + String, + /// List of available binaries. + String, + ), /// Package does not have any available binaries. #[error("Package does not have any available binaries")] @@ -58,9 +76,15 @@ pub enum CIError { Run `cargo run-ci --bin ` to specify a binary\n\ Available binaries: {0}" )] - BinaryNotDetermine(String), + BinaryNotDetermine( + /// List of available binaries. + String, + ), /// Path is not a valid directory. #[error("Given path is not a valid directory: {0}")] - PathNotDirectory(String), + PathNotDirectory( + /// Given path. + String, + ), } diff --git a/src/ops/build.rs b/src/ops/build.rs index 6f53e90..83669c1 100644 --- a/src/ops/build.rs +++ b/src/ops/build.rs @@ -91,7 +91,7 @@ fn _exec(config: &Config, opts: &BuildOpts) -> CIResult<()> { let ar = &llvm_bins[2]; let nm = &llvm_bins[3]; - // get binary names + // get all binary-type crate names, including examples let mut crate_names = Vec::new(); let metadata = cargo_metadata()?; for package in metadata.packages { @@ -237,42 +237,32 @@ fn _exec(config: &Config, opts: &BuildOpts) -> CIResult<()> { }); } - let term_size = term_size::dimensions().unwrap_or((80, 24)); - debug!("term_size: {:?}", term_size); - - // progress bar + // total length of the process bar let len = ll_files.len() * 2 + linkers.len() + 1; - let pb = if opts.verbose == 0 { - ProgressBar::new(len as u64) - } else { - ProgressBar::hidden() - }; - pb.set_style( - ProgressStyle::default_bar() - .template(if term_size.0 > 80 { - "{prefix:>12.cyan.bold} [{bar:27}] {pos}/{len}: {wide_msg}" - } else { - "{prefix:>12.cyan.bold} {pos}/{len}: {wide_msg}" - }) - .progress_chars("=> "), - ); - pb.set_prefix("Building"); - let opts = &opts; - let config = &config; let crate_names = &crate_names; let deps_path = &deps_path; - let num_cpus = num_cpus::get(); - let ll_iter = Arc::new(Mutex::new(ll_files.iter())); let lk_iter = Arc::new(Mutex::new(linkers.iter_mut())); thread::scope(move |s| -> CIResult<()> { + // communication between the progress bar thread and integration threads let (tx, rx) = mpsc::channel::(); + // number of threads based on number of logical cores in CPU + let num_cpus = num_cpus::get(); + // handle progress bar rendering let pb_thread = s.spawn(move |_| { + // progress bar + let pb = if opts.verbose == 0 { + ProgressBar::new(len as u64) + } else { + ProgressBar::hidden() + }; + pb.set_prefix("Building"); + let mut names: Vec = Vec::new(); let mut error = false; @@ -345,9 +335,16 @@ fn _exec(config: &Config, opts: &BuildOpts) -> CIResult<()> { } } - // processing crates message - let term_size = term_size::dimensions().unwrap_or((80, 24)); + // progress bar message + let term_size = terminal_size::terminal_size() + .map(|(w, h)| (w.0.into(), h.0.into())) + .unwrap_or((80, 24)); let prefix_size = if term_size.0 > 80 { 50 } else { 20 }; + let template = if term_size.0 > 80 { + "{prefix:>12.cyan.bold} [{bar:27}] {pos}/{len}: {wide_msg}" + } else { + "{prefix:>12.cyan.bold} {pos}/{len}: {wide_msg}" + }; let mut msg = String::new(); let mut iter = names.iter(); let first = match iter.next() { @@ -365,6 +362,11 @@ fn _exec(config: &Config, opts: &BuildOpts) -> CIResult<()> { break; } } + pb.set_style( + ProgressStyle::default_bar() + .template(template) + .progress_chars("=> "), + ); pb.set_message(msg); } @@ -496,7 +498,7 @@ fn _exec(config: &Config, opts: &BuildOpts) -> CIResult<()> { let iter = Arc::clone(&lk_iter); let thread = s.spawn(move |_| -> CIResult<()> { loop { - let linker = iter.lock().expect("mutex failed").next(); + let linker = iter.lock().expect("failed to acquire lock").next(); if let Some(linker) = linker { let crate_name = Arc::new(crate_name(&linker.bin_path)); info!("linking: {}", crate_name); @@ -515,7 +517,7 @@ fn _exec(config: &Config, opts: &BuildOpts) -> CIResult<()> { if stdout.contains("__rust_alloc") { debug!("found allocator shim: {}", file); } else { - *file = util::append_suffix(&file, "ci").display().to_string(); + *file = util::path_to_string(util::append_suffix(&file, "ci")); } } let deps_rlib_files = linker @@ -651,10 +653,12 @@ fn handle_output>( // take last few output lines to not polluting the terminal let mut desc = proc_err.desc.lines().rev().take(10).collect::>(); desc.reverse(); + out.push("(truncated)"); out.append(&mut desc); let msg = if debug { - // set log file name let desc = &proc_err.desc; + + // set log file name let digest = md5::compute(desc.as_bytes()); let date = chrono::Local::now().format("%y%m%dT%H%M%S").to_string(); let mut path = util::config_path()?;