diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index ac5d1922ea4..a4a6e5ac823 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -34,7 +34,7 @@ heapsize = "0.3.0" heapsize_derive = {version = "0.1", optional = true} html5ever-atoms = {version = "0.2", optional = true} lazy_static = "0.2" -log = "0.3.5" +log = "0.3" matches = "0.1" nsstring_vendor = {path = "gecko_bindings/nsstring_vendor", optional = true} num-integer = "0.1.32" @@ -60,6 +60,7 @@ kernel32-sys = "0.2" [build-dependencies] lazy_static = "0.2" +log = "0.3" bindgen = { version = "0.22", optional = true } regex = {version = "0.2", optional = true} walkdir = "1.0" diff --git a/components/style/build.rs b/components/style/build.rs index de9a1dffa0f..5ecaf902c2b 100644 --- a/components/style/build.rs +++ b/components/style/build.rs @@ -8,6 +8,8 @@ extern crate lazy_static; #[cfg(feature = "bindgen")] extern crate bindgen; #[cfg(feature = "bindgen")] +extern crate log; +#[cfg(feature = "bindgen")] extern crate regex; extern crate walkdir; diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index d3f894b519e..a217c6fe033 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -517,6 +517,49 @@ mod bindings { write_binding_file(builder, structs_file(build_type), &fixups); } + pub fn setup_logging() { + use log; + use std::fs; + + struct BuildLogger { + file: Option>, + filter: String, + } + + impl log::Log for BuildLogger { + fn enabled(&self, meta: &log::LogMetadata) -> bool { + self.file.is_some() && meta.target().contains(&self.filter) + } + + fn log(&self, record: &log::LogRecord) { + if !self.enabled(record.metadata()) { + return; + } + + let mut file = self.file.as_ref().unwrap().lock().unwrap(); + let _ = + writeln!(file, "{} - {} - {} @ {}:{}", + record.level(), + record.target(), + record.args(), + record.location().file(), + record.location().line()); + } + } + + log::set_logger(|log_level| { + log_level.set(log::LogLevelFilter::Debug); + Box::new(BuildLogger { + file: env::var("STYLO_BUILD_LOG").ok().and_then(|path| { + fs::File::create(path).ok().map(Mutex::new) + }), + filter: env::var("STYLO_BUILD_FILTER").ok() + .unwrap_or_else(|| "bindgen".to_owned()), + }) + }) + .expect("Failed to set logger."); + } + pub fn generate_bindings() { let mut builder = Builder::get_initial_builder(BuildType::Release) .disable_name_namespacing() @@ -711,6 +754,8 @@ mod bindings { static ref BINDINGS_PATH: PathBuf = Path::new(file!()).parent().unwrap().join("gecko_bindings"); } + pub fn setup_logging() {} + pub fn generate_structs(build_type: BuildType) { let file = structs_file(build_type); let source = BINDINGS_PATH.join(file); @@ -731,6 +776,7 @@ pub fn generate() { use std::thread; println!("cargo:rerun-if-changed=build_gecko.rs"); fs::create_dir_all(&*OUTDIR_PATH).unwrap(); + bindings::setup_logging(); let threads = vec![ thread::spawn(|| bindings::generate_structs(BuildType::Debug)), thread::spawn(|| bindings::generate_structs(BuildType::Release)),