From 90f213acbd87eda1059ee95cb517dadc2a0fa82d Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Fri, 18 Sep 2020 22:48:03 +0200 Subject: [PATCH] remove logging feature --- .travis.yml | 4 -- derive_builder/CHANGELOG.md | 1 + derive_builder/Cargo.toml | 1 - derive_builder/README.md | 1 - derive_builder/src/lib.rs | 10 ---- derive_builder_core/Cargo.toml | 4 -- derive_builder_core/build/skeptic.rs | 66 ++++++++++-------------- derive_builder_core/src/build_method.rs | 3 -- derive_builder_core/src/builder.rs | 8 --- derive_builder_core/src/builder_field.rs | 5 -- derive_builder_core/src/initializer.rs | 2 - derive_builder_core/src/lib.rs | 4 -- derive_builder_core/src/setter.rs | 5 -- derive_builder_macro/Cargo.toml | 2 - derive_builder_macro/src/lib.rs | 13 ----- 15 files changed, 28 insertions(+), 101 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03143e11..8479ee2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,12 +17,8 @@ env: matrix: - JOB=test CARGO_DEFAULT_FEATURES="" CARGO_FEATURES="" - JOB=test CARGO_DEFAULT_FEATURES="" CARGO_FEATURES="skeptic_tests" - - JOB=test CARGO_DEFAULT_FEATURES="" CARGO_FEATURES="logging" - - JOB=test CARGO_DEFAULT_FEATURES="" CARGO_FEATURES="skeptic_tests logging" - JOB=test CARGO_DEFAULT_FEATURES="--no-default-features" CARGO_FEATURES="" - JOB=test CARGO_DEFAULT_FEATURES="--no-default-features" CARGO_FEATURES="skeptic_tests" - - JOB=test CARGO_DEFAULT_FEATURES="--no-default-features" CARGO_FEATURES="logging" - - JOB=test CARGO_DEFAULT_FEATURES="--no-default-features" CARGO_FEATURES="skeptic_tests logging" - JOB=test CARGO_DEFAULT_FEATURES="" CARGO_FEATURES="clippy" global: - RUST_BACKTRACE=1 diff --git a/derive_builder/CHANGELOG.md b/derive_builder/CHANGELOG.md index 5130e319..92fd24ec 100644 --- a/derive_builder/CHANGELOG.md +++ b/derive_builder/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - Requires Rust 1.40.0 or newer (was 1.37.0) #169 +- Logging feature is removed. ## [0.9.0] - 2019-11-07 - Add `setter(custom)` to allow implementing a custom setter #154 diff --git a/derive_builder/Cargo.toml b/derive_builder/Cargo.toml index 795bd15f..259a8674 100644 --- a/derive_builder/Cargo.toml +++ b/derive_builder/Cargo.toml @@ -22,7 +22,6 @@ travis-ci = { repository = "colin-kiegel/rust-derive-builder" } [features] default = ["std"] std = [] -logging = ["derive_builder_macro/logging", "derive_builder_core/logging"] skeptic_tests = ["skeptic", "derive_builder_macro/skeptic_tests", "derive_builder_core/skeptic_tests"] clippy = ["derive_builder_macro/clippy", "derive_builder_core/clippy"] diff --git a/derive_builder/README.md b/derive_builder/README.md index cc455b4e..8d5924fd 100644 --- a/derive_builder/README.md +++ b/derive_builder/README.md @@ -98,7 +98,6 @@ with [cargo-edit](https://github.com/killercup/cargo-edit): * **Build method suppression**: You can use `#[builder(build_fn(skip))]` to disable auto-implementation of the build method and provide your own. * **Builder derivations**: You can use `#[builder(derive(Trait1, Trait2, ...))]` to have the builder derive additonal traits. All builders derive `Default` and `Clone`, so you should not declare those in this attribute. * **no_std support**: Just add `#[builder(no_std)]` to your struct and add `#![feature(alloc)] extern crate alloc` to your crate. The latter requires the _nightly_ toolchain. -* **Logging**: If anything works unexpectedly you can enable detailed logs in two steps. First, add `features = ["logging"]` to the `derive_builder` dependency in `Cargo.toml`. Second, set this environment variable before calling cargo `RUST_LOG=derive_builder=trace`. For more information and examples please take a look at our [documentation][doc]. diff --git a/derive_builder/src/lib.rs b/derive_builder/src/lib.rs index a8f8b8fe..a1cf9111 100644 --- a/derive_builder/src/lib.rs +++ b/derive_builder/src/lib.rs @@ -525,16 +525,6 @@ //! dependency would occur. To break it you could try to depend on the //! [`derive_builder_core`] crate instead. //! -//! ## Debugging Info -//! -//! If you experience any problems during compilation, you can enable additional debug output in -//! two steps: -//! -//! 1. Add `features = ["logging"]` to the `derive_builder` dependency in `Cargo.toml`. -//! 2. Set this environment variable before calling cargo or rustc `RUST_LOG=derive_builder=trace`. -//! -//! Example: `env RUST_LOG=derive_builder=trace cargo test`. -//! //! ## Report Issues and Ideas //! //! [Open an issue on GitHub](https://github.com/colin-kiegel/rust-derive-builder/issues) diff --git a/derive_builder_core/Cargo.toml b/derive_builder_core/Cargo.toml index ad0edb09..209db1ca 100644 --- a/derive_builder_core/Cargo.toml +++ b/derive_builder_core/Cargo.toml @@ -16,7 +16,6 @@ readme = "README.md" build = "build/mod.rs" [features] -logging = ["env_logger"] clippy = [] skeptic_tests = ["skeptic"] @@ -28,12 +27,9 @@ darling = "0.10.2" proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0", features = ["full", "extra-traits"] } -log = "0.4" [dev-dependencies] pretty_assertions = "0.6" [build-dependencies] skeptic = { version = "0.13", optional = true } -env_logger = { version = "0.5", optional = true } -log = "0.4" diff --git a/derive_builder_core/build/skeptic.rs b/derive_builder_core/build/skeptic.rs index 78dd425e..d99cb25c 100644 --- a/derive_builder_core/build/skeptic.rs +++ b/derive_builder_core/build/skeptic.rs @@ -1,14 +1,6 @@ -#[macro_use] -extern crate log; -#[cfg(feature = "logging")] -extern crate env_logger; extern crate skeptic; fn main() { - println!("INFO: Run with `RUST_LOG=build_script_build=trace` for debug information."); - #[cfg(feature = "logging")] - env_logger::init(); - let mut files = generate_doc_tpl_tests().unwrap(); files.push("README.md".to_string()); @@ -46,67 +38,63 @@ fn main() {{ "###; use std::error::Error; -use std::path::PathBuf; +use std::path::Path; use std::env; -use std::fs::{File, DirBuilder}; -use std::ffi::OsStr; -use std::io::{Write, Read}; +use std::fs::{File, DirBuilder, read_to_string}; +use std::io::Write; const DOC_TPL_DIR: &'static str = "src/doc_tpl/"; const DOC_TPL_OUT_DIR: &'static str = "doc_tpl/"; fn generate_doc_tpl_tests() -> Result, Box> { - trace!("Generating doc template tests"); - let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); - let mut tpl_dir = root_dir; - tpl_dir.push(DOC_TPL_DIR); - let mut out_dir = PathBuf::from(env::var("OUT_DIR")?); - out_dir.push(DOC_TPL_OUT_DIR); + let tpl_dir = Path::new(&env::var("CARGO_MANIFEST_DIR")?).join(DOC_TPL_DIR); + let out_dir = Path::new(&env::var("OUT_DIR")?).join(DOC_TPL_OUT_DIR); if !out_dir.is_dir() { - trace!("Create out dir {:?}", out_dir); DirBuilder::new().create(&out_dir)?; } - let docs = tpl_dir.read_dir().expect(&format!("Could not open {}", tpl_dir.display())); + let docs = tpl_dir.read_dir() + .map_err(|e| format!("Could not open {}: {}.", tpl_dir.display(), e))?; let mut files = Vec::::new(); for doc in docs { - let path: PathBuf = doc?.path(); + let path = doc?.path(); + + if !is_markdown(&path) { + continue; + } let filename = match path.file_name() { - Some(filename) if path.extension() == Some(&OsStr::new("md")) => filename, - _ => { - trace!("Skipping dir entry {:?}", path.display()); - continue; - } + Some(filename) => filename, + None => continue, }; - trace!("Create tests for {:?}", path.display()); - let mut reader = File::open(&path)?; + let tpl = read_to_string(&path) + .map_err(|e| format!("Cannot read file {}: {}.", path.display(), e))?; println!("cargo:rerun-if-changed={}", path.display()); - let mut out_file = out_dir.clone(); - out_file.push(filename); - - trace!("Will write into {:?}", out_file.display()); + let out_file = out_dir.join(filename); - let mut out = File::create(&out_file)?; + let mut out = File::create(&out_file) + .map_err(|e| format!("Cannot create file {}: {}.", out_file.display(), e))?; out.write_all(DOC_TPL_HEADER.as_bytes())?; - let mut tpl = String::new(); - reader.read_to_string(&mut tpl)?; let tpl = tpl.replace("{struct_name}", "Foo") .replace("{builder_name}", "FooBuilder") .replace("{field_name}", "default"); out.write_all(tpl.as_ref())?; - trace!("{:?}", - &[&out_file.to_str().expect("Path must not be empty")]); - - files.push(out_file.to_str().expect("Path must not be empty").to_string()); + files.push(out_file.to_str() + .ok_or_else(|| "Path must not be empty")? + .to_string() + ); } Ok(files) } + +fn is_markdown(path: &Path) -> bool { + path.extension().map_or(false, |extension| extension == "md") +} diff --git a/derive_builder_core/src/build_method.rs b/derive_builder_core/src/build_method.rs index b4f4cf9a..d9507054 100644 --- a/derive_builder_core/src/build_method.rs +++ b/derive_builder_core/src/build_method.rs @@ -85,7 +85,6 @@ impl<'a> ToTokens for BuildMethod<'a> { let error_ty = &self.error_ty; if self.enabled { - trace!("Deriving build method `{}`.", self.ident); tokens.append_all(quote!( #doc_comment #vis fn #ident(#self_param) @@ -98,8 +97,6 @@ impl<'a> ToTokens for BuildMethod<'a> { }) } )) - } else { - trace!("Skipping build method."); } } } diff --git a/derive_builder_core/src/builder.rs b/derive_builder_core/src/builder.rs index bd05a045..d520ebec 100644 --- a/derive_builder_core/src/builder.rs +++ b/derive_builder_core/src/builder.rs @@ -127,7 +127,6 @@ pub struct Builder<'a> { impl<'a> ToTokens for Builder<'a> { fn to_tokens(&self, tokens: &mut TokenStream) { if self.enabled { - trace!("Deriving builder `{}`.", self.ident); let builder_vis = &self.visibility; let builder_ident = &self.ident; let bounded_generics = self.compute_impl_bounds(); @@ -159,11 +158,6 @@ impl<'a> ToTokens for Builder<'a> { let builder_doc_comment = &self.doc_comment; let deprecation_notes = &self.deprecation_notes.as_item(); - debug!( - "ty_generics={:?}, where_clause={:?}, struct_generics={:?}", - ty_generics, where_clause, struct_generics - ); - #[cfg(not(feature = "clippy"))] tokens.append_all(quote!(#[allow(clippy::all)])); @@ -222,8 +216,6 @@ impl<'a> ToTokens for Builder<'a> { #deprecation_notes } )); - } else { - trace!("Skipping builder `{}`.", self.ident); } } } diff --git a/derive_builder_core/src/builder_field.rs b/derive_builder_core/src/builder_field.rs index 9884923f..9dc76048 100644 --- a/derive_builder_core/src/builder_field.rs +++ b/derive_builder_core/src/builder_field.rs @@ -50,7 +50,6 @@ pub struct BuilderField<'a> { impl<'a> ToTokens for BuilderField<'a> { fn to_tokens(&self, tokens: &mut TokenStream) { if self.field_enabled { - trace!("Deriving builder field for `{}`.", self.field_ident); let vis = &self.field_visibility; let ident = self.field_ident; let ty = self.field_type; @@ -60,10 +59,6 @@ impl<'a> ToTokens for BuilderField<'a> { #(#attrs)* #vis #ident: ::derive_builder::export::core::option::Option<#ty>, )); } else { - trace!( - "Skipping builder field for `{}`, fallback to PhantomData.", - self.field_ident - ); let ident = self.field_ident; let ty = self.field_type; let attrs = self.attrs; diff --git a/derive_builder_core/src/initializer.rs b/derive_builder_core/src/initializer.rs index 40a95fa0..08e341bd 100644 --- a/derive_builder_core/src/initializer.rs +++ b/derive_builder_core/src/initializer.rs @@ -52,8 +52,6 @@ pub struct Initializer<'a> { impl<'a> ToTokens for Initializer<'a> { fn to_tokens(&self, tokens: &mut TokenStream) { - trace!("Deriving initializer for `{}`.", self.field_ident); - let struct_field = &self.field_ident; if self.field_enabled { diff --git a/derive_builder_core/src/lib.rs b/derive_builder_core/src/lib.rs index 4aa9b4c6..09daeb6f 100644 --- a/derive_builder_core/src/lib.rs +++ b/derive_builder_core/src/lib.rs @@ -34,8 +34,6 @@ extern crate proc_macro2; extern crate syn; #[macro_use] extern crate quote; -#[macro_use] -extern crate log; #[cfg(test)] #[macro_use] extern crate pretty_assertions; @@ -66,8 +64,6 @@ const DEFAULT_STRUCT_NAME: &str = "__default"; /// Derive a builder for a struct pub fn builder_for_struct(ast: syn::DeriveInput) -> proc_macro2::TokenStream { - debug!("Deriving Builder for `{}`.", ast.ident); - let opts = match macro_options::Options::from_derive_input(&ast) { Ok(val) => val, Err(err) => { diff --git a/derive_builder_core/src/setter.rs b/derive_builder_core/src/setter.rs index 2471cd0c..31995fb3 100644 --- a/derive_builder_core/src/setter.rs +++ b/derive_builder_core/src/setter.rs @@ -67,7 +67,6 @@ pub struct Setter<'a> { impl<'a> ToTokens for Setter<'a> { fn to_tokens(&self, tokens: &mut TokenStream) { if self.setter_enabled { - trace!("Deriving setter for `{}`.", self.field_ident); let field_type = self.field_type; let pattern = self.pattern; let vis = &self.visibility; @@ -153,11 +152,7 @@ impl<'a> ToTokens for Setter<'a> { new.#field_ident = ::derive_builder::export::core::option::Option::Some(converted); Ok(new) })); - } else { - trace!("Skipping try_setter for `{}`.", self.field_ident); } - } else { - trace!("Skipping setter for `{}`.", self.field_ident); } } } diff --git a/derive_builder_macro/Cargo.toml b/derive_builder_macro/Cargo.toml index 49a6aa14..96fa39b3 100644 --- a/derive_builder_macro/Cargo.toml +++ b/derive_builder_macro/Cargo.toml @@ -22,11 +22,9 @@ travis-ci = { repository = "colin-kiegel/rust-derive-builder" } proc-macro = true [features] -logging = ["env_logger"] clippy = ["derive_builder_core/clippy"] skeptic_tests = ["derive_builder_core/skeptic_tests"] [dependencies] syn = { version = "1", features = ["full", "extra-traits"] } -env_logger = { version = "0.5", optional = true } derive_builder_core = { version = "=0.10.0-alpha", path = "../derive_builder_core" } diff --git a/derive_builder_macro/src/lib.rs b/derive_builder_macro/src/lib.rs index 48c53d75..946d108e 100644 --- a/derive_builder_macro/src/lib.rs +++ b/derive_builder_macro/src/lib.rs @@ -7,25 +7,12 @@ extern crate proc_macro; #[macro_use] extern crate syn; extern crate derive_builder_core; -#[cfg(feature = "logging")] -extern crate env_logger; use proc_macro::TokenStream; -#[cfg(feature = "logging")] -use std::sync::Once; - -#[cfg(feature = "logging")] -static INIT_LOGGER: Once = Once::new(); #[doc(hidden)] #[proc_macro_derive(Builder, attributes(builder))] pub fn derive(input: TokenStream) -> TokenStream { - #[cfg(feature = "logging")] - INIT_LOGGER.call_once(|| { - env_logger::init(); - }); - let ast = parse_macro_input!(input as syn::DeriveInput); - derive_builder_core::builder_for_struct(ast).into() }