From 75f893223a8468a3e623821d2be776f640bd9fac Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Arcos Date: Wed, 18 Oct 2023 14:16:46 +0200 Subject: [PATCH] Remove emojis (#376) * style: Remove emojis * docs: Update changelog --- CHANGELOG.md | 1 + src/env.rs | 16 +++++-------- src/error.rs | 45 ++++++++++++------------------------ src/lib.rs | 7 +----- src/main.rs | 16 ++++--------- src/targets.rs | 6 ++--- src/toolchain/gcc.rs | 8 +++---- src/toolchain/llvm.rs | 8 +++---- src/toolchain/mod.rs | 54 ++++++++++++------------------------------- src/toolchain/rust.rs | 41 ++++++++++---------------------- 10 files changed, 64 insertions(+), 138 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1277926..e701a7f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Update GCC version to 13.2 (#373) +- Update logging format and log messages (#375, #376) ### Removed diff --git a/src/env.rs b/src/env.rs index d57d5750..9b17d915 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,6 +1,6 @@ //! Environment variables set up and export file support. -use crate::{emoji, error::Error}; +use crate::error::Error; use directories::BaseDirs; use log::info; #[cfg(windows)] @@ -71,7 +71,7 @@ pub fn get_export_file(export_file: Option) -> Result { /// Creates the export file with the necessary environment variables. pub fn create_export_file(export_file: &PathBuf, exports: &[String]) -> Result<(), Error> { - info!("{} Creating export file", emoji::WRENCH); + info!("Creating export file"); let mut file = File::create(export_file)?; for e in exports.iter() { #[cfg(windows)] @@ -89,25 +89,21 @@ pub fn export_environment(export_file: &Path) -> Result<(), Error> { if cfg!(windows) { set_environment_variable("PATH", &env::var("PATH").unwrap())?; warn!( - "{} Your environments variables have been updated! Shell may need to be restarted for changes to be effective", - emoji::INFO + "Your environments variables have been updated! Shell may need to be restarted for changes to be effective" ); warn!( - "{} A file was created at '{}' showing the injected environment variables", - emoji::INFO, + "A file was created at '{}' showing the injected environment variables", export_file.display() ); } #[cfg(unix)] if cfg!(unix) { println!( - "\n\t{} To get started, you need to set up some environment variables by running: '. {}'", - emoji::INFO, + "\n\tTo get started, you need to set up some environment variables by running: '. {}'", export_file.display() ); println!( - "\t{} This step must be done every time you open a new terminal.\n\t See other methods for setting the environment in https://esp-rs.github.io/book/installation/riscv-and-xtensa.html#3-set-up-the-environment-variables", - emoji::WARN + "\tThis step must be done every time you open a new terminal.\n\t See other methods for setting the environment in https://esp-rs.github.io/book/installation/riscv-and-xtensa.html#3-set-up-the-environment-variables", ); } Ok(()) diff --git a/src/error.rs b/src/error.rs index 657fb356..d3452070 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,87 +1,72 @@ //! Custom error implementations. -use crate::emoji; - #[derive(Debug, miette::Diagnostic, thiserror::Error)] pub enum Error { #[diagnostic(code(espup::toolchain::create_directory))] - #[error("{} Creating directory '{0}' failed", emoji::ERROR)] + #[error("Creating directory '{0}' failed")] CreateDirectory(String), #[diagnostic(code(espup::toolchain::rust::query_github))] - #[error("{} Failed to query GitHub API", emoji::ERROR)] + #[error("Failed to query GitHub API")] GithubQuery, #[diagnostic(code(espup::toolchain::rust::install_riscv_target))] - #[error( - "{} Failed to Install RISC-V targets for '{0}' toolchain", - emoji::ERROR - )] + #[error("Failed to Install RISC-V targets for '{0}' toolchain")] InstallRiscvTarget(String), #[diagnostic(code(espup::ivalid_destination))] #[error( - "{} Invalid export file destination: '{0}'. Please, use an absolute or releative path (including the file and its extension)", - emoji::ERROR - )] + "Invalid export file destination: '{0}'. Please, use an absolute or releative path (including the file and its extension)")] InvalidDestination(String), #[diagnostic(code(espup::toolchain::rust::invalid_version))] #[error( - "{} Invalid toolchain version '{0}'. Verify that the format is correct: '...' or '..', and that the release exists in https://github.com/esp-rs/rust-build/releases", - emoji::ERROR - )] + "Invalid toolchain version '{0}'. Verify that the format is correct: '...' or '..', and that the release exists in https://github.com/esp-rs/rust-build/releases")] InvalidVersion(String), #[error(transparent)] IoError(#[from] std::io::Error), #[diagnostic(code(espup::toolchain::rust::missing_rust))] - #[error( - "{} Rust is not installed. Please, install Rust via rustup: https://rustup.rs/", - emoji::ERROR - )] + #[error("Rust is not installed. Please, install Rust via rustup: https://rustup.rs/")] MissingRust, #[diagnostic(code(espup::remove_directory))] - #[error("{} Failed to remove '{0}'", emoji::ERROR)] + #[error("Failed to remove '{0}'")] RemoveDirectory(String), #[error(transparent)] RewquestError(#[from] reqwest::Error), #[diagnostic(code(espup::toolchain::rust::rustup_detection_error))] - #[error("{} Error detecting rustup: {0}", emoji::ERROR)] + #[error("Error detecting rustup: {0}")] RustupDetection(String), #[diagnostic(code(espup::toolchain::rust::serialize_json))] - #[error("{} Failed to serialize json from string", emoji::ERROR)] + #[error("Failed to serialize json from string")] SerializeJson, #[diagnostic(code(espup::toolchain::rust::uninstall_riscv_target))] - #[error("{} Failed to uninstall RISC-V target", emoji::ERROR)] + #[error("Failed to uninstall RISC-V target")] UninstallRiscvTarget, #[diagnostic(code(espup::toolchain::unsupported_file_extension))] - #[error("{} Unsuported file extension: '{0}'", emoji::ERROR)] + #[error("Unsuported file extension: '{0}'")] UnsuportedFileExtension(String), #[diagnostic(code(espup::host_triple::unsupported_host_triple))] - #[error("{} Host triple '{0}' is not supported", emoji::ERROR)] + #[error("Host triple '{0}' is not supported")] UnsupportedHostTriple(String), #[diagnostic(code(espup::targets::unsupported_target))] - #[error("{} Target '{0}' is not supported", emoji::ERROR)] + #[error("Target '{0}' is not supported")] UnsupportedTarget(String), #[diagnostic(code(espup::toolchain::rust::rust))] - #[error("{} Failed to install 'rust' component of Xtensa Rust", emoji::ERROR)] + #[error("Failed to install 'rust' component of Xtensa Rust")] XtensaRust, #[diagnostic(code(espup::toolchain::rust::rust_src))] - #[error( - "{} Failed to install 'rust-src' component of Xtensa Rust", - emoji::ERROR - )] + #[error("Failed to install 'rust-src' component of Xtensa Rust")] XtensaRustSrc, } diff --git a/src/lib.rs b/src/lib.rs index 45c3f572..b8b92cc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ pub mod cli; -pub mod emoji; pub mod env; pub mod error; pub mod host_triple; @@ -27,7 +26,6 @@ pub mod logging { } pub mod update { - use crate::emoji; use log::warn; use std::time::Duration; use update_informer::{registry, Check}; @@ -40,10 +38,7 @@ pub mod update { update_informer::new(registry::Crates, name, version).interval(Duration::ZERO); if let Some(version) = informer.check_version().ok().flatten() { - warn!( - "{} A new version of {name} ('{version}') is available", - emoji::WARN - ); + warn!("A new version of {name} ('{version}') is available"); } } } diff --git a/src/main.rs b/src/main.rs index 6557d989..ba5b2618 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use clap::{CommandFactory, Parser}; use espup::env::set_environment_variable; use espup::{ cli::{CompletionsOpts, InstallOpts, UninstallOpts}, - emoji, error::Error, logging::initialize_logger, toolchain::{ @@ -41,11 +40,7 @@ async fn completions(args: CompletionsOpts) -> Result<()> { initialize_logger(&args.log_level); check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); - info!( - "{} Generating completions for {} shell", - emoji::DISC, - args.shell - ); + info!("Generating completions for {} shell", args.shell); clap_complete::generate( args.shell, @@ -54,7 +49,7 @@ async fn completions(args: CompletionsOpts) -> Result<()> { &mut std::io::stdout(), ); - info!("{} Completions successfully generated!", emoji::CHECK); + info!("Completions successfully generated!"); Ok(()) } @@ -73,7 +68,7 @@ async fn uninstall(args: UninstallOpts) -> Result<()> { initialize_logger(&args.log_level); check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); - info!("{} Uninstalling the Espressif Rust ecosystem", emoji::DISC); + info!("Uninstalling the Espressif Rust ecosystem"); let install_path = get_rustup_home().join("toolchains").join(args.name); Llvm::uninstall(&install_path)?; @@ -81,8 +76,7 @@ async fn uninstall(args: UninstallOpts) -> Result<()> { uninstall_gcc_toolchains(&install_path)?; info!( - "{} Deleting the Xtensa Rust toolchain located in '{}'", - emoji::DISC, + "Deleting the Xtensa Rust toolchain located in '{}'", &install_path.display() ); remove_dir_all(&install_path) @@ -91,7 +85,7 @@ async fn uninstall(args: UninstallOpts) -> Result<()> { #[cfg(windows)] set_environment_variable("PATH", &env::var("PATH").unwrap())?; - info!("{} Uninstallation successfully completed!", emoji::CHECK); + info!("Uninstallation successfully completed!"); Ok(()) } diff --git a/src/targets.rs b/src/targets.rs index 7bdf0c36..a971e33c 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -1,6 +1,6 @@ //! ESP32 chip variants support. -use crate::{emoji, error::Error}; +use crate::error::Error; use log::debug; use miette::Result; use std::{collections::HashSet, str::FromStr}; @@ -39,7 +39,7 @@ impl Target { /// Returns a vector of Chips from a comma or space separated string. pub fn parse_targets(targets_str: &str) -> Result, Error> { - debug!("{} Parsing targets: {}", emoji::DEBUG, targets_str); + debug!("Parsing targets: {}", targets_str); let targets_str = targets_str.to_lowercase(); let targets_str = targets_str.trim(); @@ -57,7 +57,7 @@ pub fn parse_targets(targets_str: &str) -> Result, Error> { targets }; - debug!("{} Parsed targets: {:?}", emoji::DEBUG, targets); + debug!("Parsed targets: {:?}", targets); Ok(targets) } diff --git a/src/toolchain/gcc.rs b/src/toolchain/gcc.rs index 6893ec99..53130c44 100644 --- a/src/toolchain/gcc.rs +++ b/src/toolchain/gcc.rs @@ -1,7 +1,6 @@ //! GCC Toolchain source and installation tools. use crate::{ - emoji, error::Error, host_triple::HostTriple, toolchain::{download_file, Installable}, @@ -53,11 +52,10 @@ impl Gcc { impl Installable for Gcc { async fn install(&self) -> Result, Error> { let extension = get_artifact_extension(&self.host_triple); - debug!("{} GCC path: {}", emoji::DEBUG, self.path.display()); + debug!("GCC path: {}", self.path.display()); if self.path.exists() { warn!( - "{} Previous installation of GCC exists in: '{}'. Reusing this installation", - emoji::WARN, + "Previous installation of GCC exists in: '{}'. Reusing this installation", &self.path.display() ); } else { @@ -128,7 +126,7 @@ fn get_artifact_extension(host_triple: &HostTriple) -> &str { /// Checks if the toolchain is pressent, if present uninstalls it. pub fn uninstall_gcc_toolchains(toolchain_path: &Path) -> Result<(), Error> { - info!("{} Uninstalling GCC", emoji::WRENCH); + info!("Uninstalling GCC"); let gcc_toolchains = vec![XTENSA_GCC, RISCV_GCC]; diff --git a/src/toolchain/llvm.rs b/src/toolchain/llvm.rs index 2ff7d225..7998c6e5 100644 --- a/src/toolchain/llvm.rs +++ b/src/toolchain/llvm.rs @@ -3,7 +3,6 @@ #[cfg(windows)] use crate::env::{delete_environment_variable, set_environment_variable}; use crate::{ - emoji, error::Error, host_triple::HostTriple, toolchain::{download_file, rust::RE_EXTENDED_SEMANTIC_VERSION, Installable}, @@ -119,7 +118,7 @@ impl Llvm { /// Uninstall LLVM toolchain. pub fn uninstall(toolchain_path: &Path) -> Result<(), Error> { - info!("{} Uninstalling Xtensa LLVM", emoji::WRENCH); + info!("Uninstalling Xtensa LLVM"); let llvm_path = toolchain_path.join(CLANG_NAME); if llvm_path.exists() { #[cfg(windows)] @@ -151,12 +150,11 @@ impl Installable for Llvm { if Path::new(&self.path).exists() { warn!( - "{} Previous installation of LLVM exists in: '{}'. Reusing this installation", - emoji::WARN, + "Previous installation of LLVM exists in: '{}'. Reusing this installation", self.path.to_str().unwrap() ); } else { - info!("{} Installing Xtensa LLVM", emoji::WRENCH); + info!("Installing Xtensa LLVM"); download_file( self.repository_url.clone(), "idf_tool_xtensa_elf_clang.tar.xz", diff --git a/src/toolchain/mod.rs b/src/toolchain/mod.rs index 090a97a8..efc1f2b6 100644 --- a/src/toolchain/mod.rs +++ b/src/toolchain/mod.rs @@ -2,7 +2,6 @@ use crate::{ cli::InstallOpts, - emoji, env::{create_export_file, export_environment, get_export_file}, error::Error, host_triple::get_host_triple, @@ -59,26 +58,16 @@ pub async fn download_file( let file_path = format!("{output_directory}/{file_name}"); if Path::new(&file_path).exists() { warn!( - "{} File '{}' already exists, deleting it before download", - emoji::WARN, + "File '{}' already exists, deleting it before download", file_path ); remove_file(&file_path)?; } else if !Path::new(&output_directory).exists() { - info!( - "{} Creating directory: '{}'", - emoji::WRENCH, - output_directory - ); + info!("Creating directory: '{}'", output_directory); create_dir_all(output_directory) .map_err(|_| Error::CreateDirectory(output_directory.to_string()))?; } - info!( - "{} Downloading file '{}' from '{}'", - emoji::DOWNLOAD, - &file_path, - url - ); + info!("Downloading file '{}' from '{}'", &file_path, url); let resp = reqwest::get(&url).await?; let bytes = resp.bytes().await?; if uncompress { @@ -112,11 +101,7 @@ pub async fn download_file( } } "gz" => { - info!( - "{} Extracting tar.gz file to '{}'", - emoji::WRENCH, - output_directory - ); + info!("Extracting tar.gz file to '{}'", output_directory); let bytes = bytes.to_vec(); let tarfile = GzDecoder::new(bytes.as_slice()); @@ -124,11 +109,7 @@ pub async fn download_file( archive.unpack(output_directory)?; } "xz" => { - info!( - "{} Extracting tar.xz file to '{}'", - emoji::WRENCH, - output_directory - ); + info!("Extracting tar.xz file to '{}'", output_directory); let bytes = bytes.to_vec(); let tarfile = XzDecoder::new(bytes.as_slice()); let mut archive = Archive::new(tarfile); @@ -139,7 +120,7 @@ pub async fn download_file( } } } else { - info!("{} Creating file: '{}'", emoji::WRENCH, file_path); + info!("Creating file: '{}'", file_path); let mut out = File::create(&file_path)?; out.write_all(&bytes)?; } @@ -149,8 +130,8 @@ pub async fn download_file( /// Installs or updates the Espressif Rust ecosystem. pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> { match install_mode { - InstallMode::Install => info!("{} Installing the Espressif Rust ecosystem", emoji::DISC), - InstallMode::Update => info!("{} Updating the Espressif Rust ecosystem", emoji::DISC), + InstallMode::Install => info!("Installing the Espressif Rust ecosystem"), + InstallMode::Update => info!("Updating the Espressif Rust ecosystem"), } let export_file = get_export_file(args.export_file)?; let mut exports: Vec = Vec::new(); @@ -186,7 +167,7 @@ pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> }; debug!( - "{} Arguments: + "Arguments: - Export file: {:?} - Host triple: {} - LLVM Toolchain: {:?} @@ -196,7 +177,6 @@ pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> - Targets: {:?} - Toolchain path: {:?} - Toolchain version: {:?}", - emoji::INFO, &export_file, host_triple, &llvm, @@ -251,11 +231,7 @@ pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> let res = Retry::spawn(retry_strategy, || async { let res = app.install().await; if res.is_err() { - warn!( - "{} Installation for '{}' failed, retrying", - emoji::WARN, - app.name() - ); + warn!("Installation for '{}' failed, retrying", app.name()); } res }) @@ -272,8 +248,8 @@ pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> create_export_file(&export_file, &exports)?; match install_mode { - InstallMode::Install => info!("{} Installation successfully completed!", emoji::CHECK), - InstallMode::Update => info!("{} Update successfully completed!", emoji::CHECK), + InstallMode::Install => info!("Installation successfully completed!"), + InstallMode::Update => info!("Update successfully completed!"), } export_environment(&export_file)?; Ok(()) @@ -281,7 +257,7 @@ pub async fn install(args: InstallOpts, install_mode: InstallMode) -> Result<()> /// Queries the GitHub API and returns the JSON response. pub fn github_query(url: &str) -> Result { - info!("{} Querying GitHub API: '{}'", emoji::INFO, url); + info!("Querying GitHub API: '{}'", url); let mut headers = header::HeaderMap::new(); headers.insert(header::USER_AGENT, "espup".parse().unwrap()); headers.insert( @@ -290,7 +266,7 @@ pub fn github_query(url: &str) -> Result { ); headers.insert("X-GitHub-Api-Version", "2022-11-28".parse().unwrap()); if let Some(token) = env::var_os("GITHUB_TOKEN") { - debug!("{} Auth header added", emoji::DEBUG); + debug!("Auth header added"); headers.insert( "Authorization", format!("Bearer {}", token.to_string_lossy()) @@ -306,7 +282,7 @@ pub fn github_query(url: &str) -> Result { if res.contains( "https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting", ) { - warn!("{} GitHub rate limit exceeded", emoji::WARN); + warn!("GitHub rate limit exceeded"); return Err(Error::GithubQuery); } let json: serde_json::Value = diff --git a/src/toolchain/rust.rs b/src/toolchain/rust.rs index 8ca67c99..c556cd61 100644 --- a/src/toolchain/rust.rs +++ b/src/toolchain/rust.rs @@ -1,7 +1,6 @@ //! Xtensa Rust Toolchain source and installation tools. use crate::{ - emoji, error::Error, host_triple::HostTriple, toolchain::{ @@ -76,7 +75,7 @@ impl XtensaRust { version.retain(|c| c != 'v' && c != '"'); Self::parse_version(&version)?; - debug!("{} Latest Xtensa Rust version: {}", emoji::DEBUG, version); + debug!("Latest Xtensa Rust version: {}", version); Ok(version) } @@ -115,7 +114,7 @@ impl XtensaRust { /// Parses the version of the Xtensa toolchain. pub fn parse_version(arg: &str) -> Result { - debug!("{} Parsing Xtensa Rust version: {}", emoji::DEBUG, arg); + debug!("Parsing Xtensa Rust version: {}", arg); let re_extended = Regex::new(RE_EXTENDED_SEMANTIC_VERSION).unwrap(); let re_semver = Regex::new(RE_SEMANTIC_VERSION).unwrap(); let json = github_query(XTENSA_RUST_API_URL)?; @@ -159,7 +158,7 @@ impl XtensaRust { /// Removes the Xtensa Rust toolchain. pub fn uninstall(toolchain_path: &Path) -> Result<(), Error> { - info!("{} Uninstalling Xtensa Rust toolchain", emoji::WRENCH); + info!("Uninstalling Xtensa Rust toolchain"); let dir = read_dir(toolchain_path)?; for entry in dir { let entry_path = entry.unwrap().path(); @@ -200,34 +199,26 @@ impl Installable for XtensaRust { let output = String::from_utf8_lossy(&rustc_version.stdout); if rustc_version.status.success() && output.contains(&self.version) { warn!( - "{} Previous installation of Xtensa Rust {} exists in: '{}'. Reusing this installation", - emoji::WARN, + "Previous installation of Xtensa Rust {} exists in: '{}'. Reusing this installation", &self.version, &self.toolchain_destination.display() ); return Ok(vec![]); } else { if !rustc_version.status.success() { - warn!( - "{} Failed to detect version of Xtensa Rust, reinstalling it", - emoji::WARN - ); + warn!("Failed to detect version of Xtensa Rust, reinstalling it"); } Self::uninstall(&self.toolchain_destination)?; } } - info!( - "{} Installing Xtensa Rust {} toolchain", - emoji::WRENCH, - self.version - ); + info!("Installing Xtensa Rust {} toolchain", self.version); #[cfg(unix)] if cfg!(unix) { let path = get_rustup_home().join("tmp"); if !path.exists() { - info!("{} Creating directory: '{}'", emoji::WRENCH, path.display()); + info!("Creating directory: '{}'", path.display()); create_dir_all(&path) .map_err(|_| Error::CreateDirectory(path.display().to_string()))?; } @@ -243,10 +234,7 @@ impl Installable for XtensaRust { ) .await?; - info!( - "{} Installing 'rust' component for Xtensa Rust toolchain", - emoji::WRENCH - ); + info!("Installing 'rust' component for Xtensa Rust toolchain"); if !Command::new("/usr/bin/env") .arg("bash") @@ -278,10 +266,7 @@ impl Installable for XtensaRust { false, ) .await?; - info!( - "{} Installing 'rust-src' component for Xtensa Rust toolchain", - emoji::WRENCH - ); + info!("Installing 'rust-src' component for Xtensa Rust toolchain"); if !Command::new("/usr/bin/env") .arg("bash") .arg(format!("{}/rust-src-nightly/install.sh", tmp_dir_path)) @@ -338,7 +323,7 @@ impl RiscVTarget { /// Uninstalls the RISC-V target. pub fn uninstall(nightly_version: &str) -> Result<(), Error> { - info!("{} Uninstalling RISC-V target", emoji::WRENCH); + info!("Uninstalling RISC-V target"); if !Command::new("rustup") .args([ @@ -363,9 +348,7 @@ impl RiscVTarget { impl Installable for RiscVTarget { async fn install(&self) -> Result, Error> { info!( - "{} Installing RISC-V Rust targets ('riscv32imc-unknown-none-elf' and 'riscv32imac-unknown-none-elf') for '{}' toolchain", - emoji::WRENCH, - &self.nightly_version + "Installing RISC-V Rust targets ('riscv32imc-unknown-none-elf' and 'riscv32imac-unknown-none-elf') for '{}' toolchain", &self.nightly_version ); if !Command::new("rustup") @@ -431,7 +414,7 @@ pub fn get_rustup_home() -> PathBuf { /// Checks if rustup is installed. pub async fn check_rust_installation() -> Result<(), Error> { - info!("{} Checking Rust installation", emoji::WRENCH); + info!("Checking Rust installation"); if let Err(e) = Command::new("rustup") .arg("--version")