Test that Servo_* functions have the right signatures

Fixes #12992
This commit is contained in:
Manish Goregaokar 2016-10-06 21:28:39 +05:30
parent 6bd898626f
commit af57a98694
9 changed files with 148 additions and 37 deletions

View file

@ -4,6 +4,8 @@ version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
build = "build.rs"
[lib]
name = "stylo_tests"
path = "lib.rs"
@ -11,6 +13,15 @@ doctest = false
[dependencies]
app_units = "0.3"
cssparser = {version = "0.7", features = ["heap_size"]}
style = {path = "../../../components/style", features = ["gecko"]}
env_logger = "0.3"
euclid = "0.10.1"
lazy_static = "0.2"
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "0.2.2"
parking_lot = "0.3"
selectors = "0.13"
url = "1.2"
style_traits = {path = "../../../components/style_traits"}
geckoservo = {path = "../../../ports/geckolib"}
style = {path = "../../../components/style", features = ["gecko"]}

13
tests/unit/stylo/build.rs Normal file
View file

@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=check_bindings.py");
println!("cargo:rerun-if-changed=../../../ports/geckolib/glue.rs");
assert!(Command::new("python").arg("./check_bindings.py")
.spawn().unwrap().wait().unwrap().success());
}

View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import re
ROOT_PATH = os.path.join("..", "..", "..")
INPUT_FILE = os.path.join(ROOT_PATH, "components", "style", "gecko_bindings", "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")
TEMPLATE = """\
[ Servo_{name}, bindings::Servo_{name} ];
"""
with open(INPUT_FILE, "r") as bindings, open(OUTPUT_FILE, "w+") as tests:
tests.write("fn assert_types() {\n")
pattern = re.compile("fn\s*Servo_([a-zA-Z0-9_]+)\s*\(")
for line in bindings:
match = pattern.search(line)
# GetStyleVariables is a Servo_* function, but temporarily defined on
# the gecko side
if match and match.group(1) != "GetStyleVariables":
tests.write(TEMPLATE.format(name=match.group(1)))
tests.write("}\n")
with open(GLUE_FILE, "r") as glue, open(GLUE_OUTPUT_FILE, "w+") as glue_output:
for line in glue:
glue_output.write(line.replace("pub extern \"C\" fn", "pub unsafe extern \"C\" fn"))

View file

@ -3,8 +3,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate app_units;
extern crate cssparser;
extern crate env_logger;
extern crate euclid;
extern crate geckoservo;
extern crate libc;
#[macro_use] extern crate log;
extern crate parking_lot;
extern crate style;
extern crate style_traits;
extern crate url;
mod sanity_checks;
mod servo_function_signatures;

View file

@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(unused)]
use self::glue::*;
use style::gecko_bindings::bindings;
use style::gecko_properties::*;
include!(concat!(env!("OUT_DIR"), "/check_bindings.rs"));
#[allow(non_snake_case, unused_unsafe, private_no_mangle_fns)]
mod glue {
// this module pretends to be glue.rs, with the safe functions swapped for unsafe ones. This is
// a hack to compensate for the fact that `fn` types cannot coerce to `unsafe fn` types. The
// imports are populated with the same things so the type assertion should be equivalent
use geckoservo::*;
include!(concat!(env!("OUT_DIR"), "/glue.rs"));
}