style: Remove the ability to build Gecko without the bindgen feature.

This is not used for anything, as far as I can tell.

Differential Revision: https://phabricator.services.mozilla.com/D38584
This commit is contained in:
Emilio Cobos Álvarez 2019-07-18 23:39:14 +00:00
parent 137044a3db
commit 66eae2fc81
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
3 changed files with 369 additions and 422 deletions

View file

@ -16,8 +16,7 @@ path = "lib.rs"
doctest = false doctest = false
[features] [features]
gecko = ["style_traits/gecko", "fallible/known_system_malloc"] gecko = ["style_traits/gecko", "fallible/known_system_malloc", "bindgen", "regex", "toml"]
use_bindgen = ["bindgen", "regex", "toml"]
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever", servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union", "cssparser/serde", "encoding_rs", "malloc_size_of/servo", "arrayvec/use_union",
"servo_url", "string_cache", "crossbeam-channel", "to_shmem/servo", "servo_arc/servo"] "servo_url", "string_cache", "crossbeam-channel", "to_shmem/servo", "servo_arc/servo"]

View file

@ -4,13 +4,13 @@
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[cfg(feature = "bindgen")] #[cfg(feature = "gecko")]
extern crate bindgen; extern crate bindgen;
#[cfg(feature = "bindgen")] #[cfg(feature = "gecko")]
extern crate log; extern crate log;
#[cfg(feature = "bindgen")] #[cfg(feature = "gecko")]
extern crate regex; extern crate regex;
#[cfg(feature = "bindgen")] #[cfg(feature = "gecko")]
extern crate toml; extern crate toml;
extern crate walkdir; extern crate walkdir;

View file

@ -2,38 +2,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
mod common { use super::PYTHON;
use std::env; use bindgen::{Builder, CodegenConfig};
use std::path::PathBuf; use regex::Regex;
use std::cmp;
use std::collections::HashSet;
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::{exit, Command};
use std::slice;
use std::sync::Mutex;
use std::time::SystemTime;
use toml;
use toml::value::Table;
lazy_static! { lazy_static! {
pub static ref OUTDIR_PATH: PathBuf = static ref OUTDIR_PATH: PathBuf = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("gecko");
PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("gecko");
}
} }
#[cfg(feature = "bindgen")] const STRUCTS_FILE: &'static str = "structs.rs";
mod bindings {
use super::super::PYTHON;
use super::common::*;
use bindgen::{Builder, CodegenConfig};
use regex::Regex;
use std::cmp;
use std::collections::HashSet;
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::{exit, Command};
use std::slice;
use std::sync::Mutex;
use std::time::SystemTime;
use toml;
use toml::value::Table;
const STRUCTS_FILE: &'static str = "structs.rs"; fn read_config(path: &PathBuf) -> Table {
fn read_config(path: &PathBuf) -> Table {
println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
update_last_modified(&path); update_last_modified(&path);
@ -46,9 +37,9 @@ mod bindings {
Ok(result) => result, Ok(result) => result,
Err(e) => panic!("Failed to parse config file: {}", e), Err(e) => panic!("Failed to parse config file: {}", e),
} }
} }
lazy_static! { lazy_static! {
static ref CONFIG: Table = { static ref CONFIG: Table = {
// Load Gecko's binding generator config from the source tree. // Load Gecko's binding generator config from the source tree.
let path = PathBuf::from(env::var_os("MOZ_SRC").unwrap()) let path = PathBuf::from(env::var_os("MOZ_SRC").unwrap())
@ -77,19 +68,19 @@ mod bindings {
static ref LAST_MODIFIED: Mutex<SystemTime> = static ref LAST_MODIFIED: Mutex<SystemTime> =
Mutex::new(get_modified_time(&env::current_exe().unwrap()) Mutex::new(get_modified_time(&env::current_exe().unwrap())
.expect("Failed to get modified time of executable")); .expect("Failed to get modified time of executable"));
} }
fn get_modified_time(file: &Path) -> Option<SystemTime> { fn get_modified_time(file: &Path) -> Option<SystemTime> {
file.metadata().and_then(|m| m.modified()).ok() file.metadata().and_then(|m| m.modified()).ok()
} }
fn update_last_modified(file: &Path) { fn update_last_modified(file: &Path) {
let modified = get_modified_time(file).expect("Couldn't get file modification time"); let modified = get_modified_time(file).expect("Couldn't get file modification time");
let mut last_modified = LAST_MODIFIED.lock().unwrap(); let mut last_modified = LAST_MODIFIED.lock().unwrap();
*last_modified = cmp::max(modified, *last_modified); *last_modified = cmp::max(modified, *last_modified);
} }
fn search_include(name: &str) -> Option<PathBuf> { fn search_include(name: &str) -> Option<PathBuf> {
for path in SEARCH_PATHS.iter() { for path in SEARCH_PATHS.iter() {
let file = path.join(name); let file = path.join(name);
if file.is_file() { if file.is_file() {
@ -98,9 +89,9 @@ mod bindings {
} }
} }
None None
} }
fn add_headers_recursively(path: PathBuf, added_paths: &mut HashSet<PathBuf>) { fn add_headers_recursively(path: PathBuf, added_paths: &mut HashSet<PathBuf>) {
if added_paths.contains(&path) { if added_paths.contains(&path) {
return; return;
} }
@ -114,22 +105,22 @@ mod bindings {
add_headers_recursively(path, added_paths); add_headers_recursively(path, added_paths);
} }
} }
} }
fn add_include(name: &str) -> String { fn add_include(name: &str) -> String {
let mut added_paths = ADDED_PATHS.lock().unwrap(); let mut added_paths = ADDED_PATHS.lock().unwrap();
let file = search_include(name).expect("Include not found!"); let file = search_include(name).expect("Include not found!");
let result = String::from(file.to_str().unwrap()); let result = String::from(file.to_str().unwrap());
add_headers_recursively(file, &mut *added_paths); add_headers_recursively(file, &mut *added_paths);
result result
} }
trait BuilderExt { trait BuilderExt {
fn get_initial_builder() -> Builder; fn get_initial_builder() -> Builder;
fn include<T: Into<String>>(self, file: T) -> Builder; fn include<T: Into<String>>(self, file: T) -> Builder;
} }
impl BuilderExt for Builder { impl BuilderExt for Builder {
fn get_initial_builder() -> Builder { fn get_initial_builder() -> Builder {
use bindgen::RustTarget; use bindgen::RustTarget;
@ -177,14 +168,14 @@ mod bindings {
fn include<T: Into<String>>(self, file: T) -> Builder { fn include<T: Into<String>>(self, file: T) -> Builder {
self.clang_arg("-include").clang_arg(file) self.clang_arg("-include").clang_arg(file)
} }
} }
struct Fixup { struct Fixup {
pat: String, pat: String,
rep: String, rep: String,
} }
fn write_binding_file(builder: Builder, file: &str, fixups: &[Fixup]) { fn write_binding_file(builder: Builder, file: &str, fixups: &[Fixup]) {
let out_file = OUTDIR_PATH.join(file); let out_file = OUTDIR_PATH.join(file);
if let Some(modified) = get_modified_time(&out_file) { if let Some(modified) = get_modified_time(&out_file) {
// Don't generate the file if nothing it depends on was modified. // Don't generate the file if nothing it depends on was modified.
@ -217,14 +208,14 @@ mod bindings {
.unwrap() .unwrap()
.write_all(&bytes) .write_all(&bytes)
.expect("Unable to write output"); .expect("Unable to write output");
} }
struct BuilderWithConfig<'a> { struct BuilderWithConfig<'a> {
builder: Builder, builder: Builder,
config: &'a Table, config: &'a Table,
used_keys: HashSet<&'static str>, used_keys: HashSet<&'static str>,
} }
impl<'a> BuilderWithConfig<'a> { impl<'a> BuilderWithConfig<'a> {
fn new(builder: Builder, config: &'a Table) -> Self { fn new(builder: Builder, config: &'a Table) -> Self {
BuilderWithConfig { BuilderWithConfig {
builder, builder,
@ -289,14 +280,12 @@ mod bindings {
} }
self.builder self.builder
} }
} }
fn generate_structs() { fn generate_structs() {
let builder = Builder::get_initial_builder() let builder = Builder::get_initial_builder()
.enable_cxx_namespaces() .enable_cxx_namespaces()
.with_codegen_config( .with_codegen_config(CodegenConfig::TYPES | CodegenConfig::VARS | CodegenConfig::FUNCTIONS);
CodegenConfig::TYPES | CodegenConfig::VARS | CodegenConfig::FUNCTIONS,
);
let mut fixups = vec![]; let mut fixups = vec![];
let builder = BuilderWithConfig::new(builder, CONFIG["structs"].as_table().unwrap()) let builder = BuilderWithConfig::new(builder, CONFIG["structs"].as_table().unwrap())
.handle_common(&mut fixups) .handle_common(&mut fixups)
@ -336,9 +325,9 @@ mod bindings {
}) })
.get_builder(); .get_builder();
write_binding_file(builder, STRUCTS_FILE, &fixups); write_binding_file(builder, STRUCTS_FILE, &fixups);
} }
fn setup_logging() -> bool { fn setup_logging() -> bool {
struct BuildLogger { struct BuildLogger {
file: Option<Mutex<fs::File>>, file: Option<Mutex<fs::File>>,
filter: String, filter: String,
@ -387,9 +376,9 @@ mod bindings {
} else { } else {
false false
} }
} }
fn generate_atoms() { fn generate_atoms() {
let script = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()) let script = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap())
.join("gecko") .join("gecko")
.join("regen_atoms.py"); .join("regen_atoms.py");
@ -403,9 +392,11 @@ mod bindings {
if !status.success() { if !status.success() {
exit(1); exit(1);
} }
} }
pub fn generate() { pub fn generate() {
println!("cargo:rerun-if-changed=build_gecko.rs");
fs::create_dir_all(&*OUTDIR_PATH).unwrap();
setup_logging(); setup_logging();
generate_structs(); generate_structs();
generate_atoms(); generate_atoms();
@ -413,47 +404,4 @@ mod bindings {
for path in ADDED_PATHS.lock().unwrap().iter() { for path in ADDED_PATHS.lock().unwrap().iter() {
println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
} }
}
}
#[cfg(not(feature = "bindgen"))]
mod bindings {
use super::common::*;
use std::path::{Path, PathBuf};
use std::{env, fs, io};
/// Copy contents of one directory into another.
/// It currently only does a shallow copy.
fn copy_dir<P, Q, F>(from: P, to: Q, callback: F) -> io::Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>,
F: Fn(&Path),
{
let to = to.as_ref();
for entry in from.as_ref().read_dir()? {
let entry = entry?;
let path = entry.path();
callback(&path);
fs::copy(&path, to.join(entry.file_name()))?;
}
Ok(())
}
pub fn generate() {
let dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("gecko/generated");
println!("cargo:rerun-if-changed={}", dir.display());
copy_dir(&dir, &*OUTDIR_PATH, |path| {
println!("cargo:rerun-if-changed={}", path.display());
})
.expect("Fail to copy generated files to out dir");
}
}
pub fn generate() {
use self::common::*;
use std::fs;
println!("cargo:rerun-if-changed=build_gecko.rs");
fs::create_dir_all(&*OUTDIR_PATH).unwrap();
bindings::generate();
} }