Make atom files generated at build-time.

This commit is contained in:
Xidorn Quan 2017-05-08 13:23:39 +10:00
parent d44b904f08
commit 10b7001dd1
4 changed files with 30 additions and 12 deletions

View file

@ -97,7 +97,9 @@ class Atom:
def collect_atoms(objdir):
atoms = []
for source in SOURCES:
with open(os.path.join(objdir, source.FILE)) as f:
path = os.path.abspath(os.path.join(objdir, source.FILE))
print("cargo:rerun-if-changed={}".format(path))
with open(path) as f:
for line in f.readlines():
result = re.match(source.PATTERN, line)
if result:
@ -255,15 +257,14 @@ def write_pseudo_element_helper(atoms, target_filename):
f.write("}\n")
def generate_atoms(dist):
style_path = os.path.dirname(os.path.dirname(__file__))
def generate_atoms(dist, out):
atoms = collect_atoms(dist)
write_atom_macro(atoms, os.path.join(style_path, "gecko/generated/atom_macro.rs"))
write_pseudo_element_helper(atoms, os.path.join(style_path, "gecko/generated/pseudo_element_helper.rs"))
write_atom_macro(atoms, os.path.join(out, "atom_macro.rs"))
write_pseudo_element_helper(atoms, os.path.join(out, "pseudo_element_helper.rs"))
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: {} objdir".format(sys.argv[0]))
if len(sys.argv) != 3:
print("Usage: {} dist out".format(sys.argv[0]))
exit(2)
generate_atoms(os.path.join(sys.argv[1], "dist"))
generate_atoms(sys.argv[1], sys.argv[2])

View file

@ -22,9 +22,11 @@ mod bindings {
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, exit};
use std::sync::Mutex;
use std::time::SystemTime;
use super::common::*;
use super::super::PYTHON;
const STRUCTS_DEBUG_FILE: &'static str = "structs_debug.rs";
const STRUCTS_RELEASE_FILE: &'static str = "structs_release.rs";
@ -814,6 +816,20 @@ mod bindings {
write_binding_file(builder, BINDINGS_FILE, &Vec::new());
}
fn generate_atoms() {
let script = Path::new(file!()).parent().unwrap().join("binding_tools").join("regen_atoms.py");
println!("cargo:rerun-if-changed={}", script.display());
let status = Command::new(&*PYTHON)
.arg(&script)
.arg(DISTDIR_PATH.as_os_str())
.arg(OUTDIR_PATH.as_os_str())
.status()
.unwrap();
if !status.success() {
exit(1);
}
}
pub fn generate() {
use std::thread;
macro_rules! run_tasks {
@ -832,6 +848,7 @@ mod bindings {
generate_structs(BuildType::Debug),
generate_structs(BuildType::Release),
generate_bindings(),
generate_atoms(),
}
}
}

View file

@ -165,7 +165,7 @@ impl PseudoElement {
}}
}
include!("generated/pseudo_element_helper.rs");
include!(concat!(env!("OUT_DIR"), "/gecko/pseudo_element_helper.rs"));
None
}
@ -190,7 +190,7 @@ impl PseudoElement {
}}
}
include!("generated/pseudo_element_helper.rs");
include!(concat!(env!("OUT_DIR"), "/gecko/pseudo_element_helper.rs"));
None
}
@ -492,7 +492,7 @@ impl SelectorImpl {
}}
}
include!("generated/pseudo_element_helper.rs")
include!(concat!(env!("OUT_DIR"), "/gecko/pseudo_element_helper.rs"));
}
#[inline]

View file

@ -26,7 +26,7 @@ use std::slice;
#[macro_use]
#[allow(improper_ctypes, non_camel_case_types, missing_docs)]
pub mod atom_macro {
include!("../gecko/generated/atom_macro.rs");
include!(concat!(env!("OUT_DIR"), "/gecko/atom_macro.rs"));
}
#[macro_use]