Move binding files into another directory.

So that we can copy them when not using bindgen altogether.
This commit is contained in:
Xidorn Quan 2017-04-14 18:22:30 +08:00
parent 35dc68c234
commit a60e5f0218
6 changed files with 31 additions and 42 deletions

View file

@ -9,23 +9,6 @@ mod common {
lazy_static! {
pub static ref OUTDIR_PATH: PathBuf = PathBuf::from(env::var("OUT_DIR").unwrap()).join("gecko");
}
pub const STRUCTS_DEBUG_FILE: &'static str = "structs_debug.rs";
pub const STRUCTS_RELEASE_FILE: &'static str = "structs_release.rs";
pub const BINDINGS_FILE: &'static str = "bindings.rs";
#[derive(Clone, Copy, PartialEq)]
pub enum BuildType {
Debug,
Release,
}
pub fn structs_file(build_type: BuildType) -> &'static str {
match build_type {
BuildType::Debug => STRUCTS_DEBUG_FILE,
BuildType::Release => STRUCTS_RELEASE_FILE
}
}
}
#[cfg(feature = "bindgen")]
@ -43,6 +26,23 @@ mod bindings {
use std::time::SystemTime;
use super::common::*;
const STRUCTS_DEBUG_FILE: &'static str = "structs_debug.rs";
const STRUCTS_RELEASE_FILE: &'static str = "structs_release.rs";
const BINDINGS_FILE: &'static str = "bindings.rs";
#[derive(Clone, Copy, PartialEq)]
enum BuildType {
Debug,
Release,
}
fn structs_file(build_type: BuildType) -> &'static str {
match build_type {
BuildType::Debug => STRUCTS_DEBUG_FILE,
BuildType::Release => STRUCTS_RELEASE_FILE
}
}
lazy_static! {
static ref INCLUDE_RE: Regex = Regex::new(r#"#include\s*"(.+?)""#).unwrap();
static ref DISTDIR_PATH: PathBuf = {
@ -839,30 +839,19 @@ mod bindings {
#[cfg(not(feature = "bindgen"))]
mod bindings {
use std::fs;
use std::path::{Path, PathBuf};
use std::path::Path;
use super::common::*;
lazy_static! {
static ref BINDINGS_PATH: PathBuf = Path::new(file!()).parent().unwrap().join("gecko_bindings");
}
fn generate_structs(build_type: BuildType) {
let file = structs_file(build_type);
let source = BINDINGS_PATH.join(file);
println!("cargo:rerun-if-changed={}", source.display());
fs::copy(source, OUTDIR_PATH.join(file)).unwrap();
}
fn generate_bindings() {
let source = BINDINGS_PATH.join(BINDINGS_FILE);
println!("cargo:rerun-if-changed={}", source.display());
fs::copy(source, OUTDIR_PATH.join(BINDINGS_FILE)).unwrap();
}
pub fn generate() {
generate_structs(BuildType::Debug);
generate_structs(BuildType::Release);
generate_bindings();
let dir = Path::new(file!()).parent().unwrap().join("gecko/generated");
println!("cargo:rerun-if-changed={}", dir.display());
let entries = dir.read_dir().expect("Fail to list the generated directory");
for entry in entries {
let entry = entry.expect("Fail to get dir entry");
println!("cargo:rerun-if-changed={}", entry.path().display());
fs::copy(entry.path(), OUTDIR_PATH.join(entry.file_name()))
.expect("Fail to copy the file");
}
}
}

View file

@ -37,9 +37,9 @@ files = [
# Helper macro where actually a pseudo-element per line makes sense.
"./components/style/gecko/non_ts_pseudo_class_list.rs",
# Generated and upstream code combined with our own. Could use cleanup
"./components/style/gecko_bindings/bindings.rs",
"./components/style/gecko_bindings/structs_debug.rs",
"./components/style/gecko_bindings/structs_release.rs",
"./components/style/gecko/generated/bindings.rs",
"./components/style/gecko/generated/structs_debug.rs",
"./components/style/gecko/generated/structs_release.rs",
"./components/style/gecko_string_cache/atom_macro.rs",
"./resources/hsts_preload.json",
"./tests/wpt/metadata/MANIFEST.json",

View file

@ -8,7 +8,7 @@ import os
import re
ROOT_PATH = os.path.join("..", "..", "..")
INPUT_FILE = os.path.join(ROOT_PATH, "components", "style", "gecko_bindings", "bindings.rs")
INPUT_FILE = os.path.join(ROOT_PATH, "components", "style", "gecko", "generated", "bindings.rs")
OUTPUT_FILE = os.path.join(os.environ["OUT_DIR"], "check_bindings.rs")
GLUE_FILE = os.path.join(ROOT_PATH, "ports", "geckolib", "glue.rs")
GLUE_OUTPUT_FILE = os.path.join(os.environ["OUT_DIR"], "glue.rs")