Skip to content

Commit

Permalink
remove logging feature
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Jan 12, 2021
1 parent 3899b89 commit e0f69ae
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 105 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions derive_builder/CHANGELOG.md
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion derive_builder/Cargo.toml
Expand Up @@ -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"]

Expand Down
1 change: 0 additions & 1 deletion derive_builder/README.md
Expand Up @@ -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].

Expand Down
10 changes: 0 additions & 10 deletions derive_builder/src/lib.rs
Expand Up @@ -528,16 +528,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)
Expand Down
4 changes: 0 additions & 4 deletions derive_builder_core/Cargo.toml
Expand Up @@ -16,7 +16,6 @@ readme = "README.md"
build = "build/mod.rs"

[features]
logging = ["env_logger"]
clippy = []
skeptic_tests = ["skeptic"]

Expand All @@ -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"
66 changes: 27 additions & 39 deletions 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());

Expand Down Expand Up @@ -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<Vec<String>, Box<dyn Error>> {
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::<String>::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")
}
3 changes: 0 additions & 3 deletions derive_builder_core/src/build_method.rs
Expand Up @@ -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)
Expand All @@ -98,8 +97,6 @@ impl<'a> ToTokens for BuildMethod<'a> {
})
}
))
} else {
trace!("Skipping build method.");
}
}
}
Expand Down
14 changes: 3 additions & 11 deletions derive_builder_core/src/builder.rs
Expand Up @@ -140,7 +140,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();
Expand Down Expand Up @@ -174,11 +173,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)]));

Expand Down Expand Up @@ -236,7 +230,7 @@ impl<'a> ToTokens for Builder<'a> {
#(#functions)*
#deprecation_notes
}

impl #impl_generics ::derive_builder::export::core::default::Default for #builder_ident #ty_generics #where_clause {
fn default() -> Self {
Self {
Expand All @@ -245,8 +239,6 @@ impl<'a> ToTokens for Builder<'a> {
}
}
));
} else {
trace!("Skipping builder `{}`.", self.ident);
}
}
}
Expand Down Expand Up @@ -400,7 +392,7 @@ mod tests {
unimplemented!()
}
}

impl ::derive_builder::export::core::default::Default for FooBuilder {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -761,7 +753,7 @@ mod tests {
unimplemented!()
}
}

impl ::derive_builder::export::core::default::Default for FooBuilder {
fn default() -> Self {
Self {
Expand Down
7 changes: 1 addition & 6 deletions derive_builder_core/src/builder_field.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -79,7 +74,7 @@ impl<'a> BuilderField<'a> {
/// Emits a struct field initializer that initializes the field to `Default::default`.
pub fn default_initializer_tokens(&self) -> TokenStream {
let ident = self.field_ident;
quote!{ #ident : ::derive_builder::export::core::default::Default::default(), }
quote! { #ident : ::derive_builder::export::core::default::Default::default(), }
}
}

Expand Down
2 changes: 0 additions & 2 deletions derive_builder_core/src/initializer.rs
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions derive_builder_core/src/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
5 changes: 0 additions & 5 deletions derive_builder_core/src/setter.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions derive_builder_macro/Cargo.toml
Expand Up @@ -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" }
13 changes: 0 additions & 13 deletions derive_builder_macro/src/lib.rs
Expand Up @@ -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()
}

0 comments on commit e0f69ae

Please sign in to comment.