From 5e60865d1922a3a9cb813c4c7b4c9908604adfcd Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 18 May 2017 17:17:29 +0200 Subject: [PATCH 1/2] Use size_of_test! macro in style and stylo tests. --- Cargo.lock | 2 ++ .../style/properties/properties.mako.rs | 24 ------------------- tests/unit/style/Cargo.toml | 3 ++- tests/unit/style/lib.rs | 1 + tests/unit/style/size_of.rs | 7 +++--- tests/unit/stylo/Cargo.toml | 3 ++- tests/unit/stylo/lib.rs | 1 + tests/unit/stylo/size_of.rs | 5 +--- 8 files changed, 12 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b21ff19f356..fbb8b7a7213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2872,6 +2872,7 @@ dependencies = [ "servo_atoms 0.0.1", "servo_config 0.0.1", "servo_url 0.0.1", + "size_of_test 0.0.1", "style 0.0.1", "style_traits 0.0.1", ] @@ -2901,6 +2902,7 @@ dependencies = [ "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.18.0", + "size_of_test 0.0.1", "style 0.0.1", "style_traits 0.0.1", ] diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1f5c951d1f4..cc89cf1b648 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2802,30 +2802,6 @@ macro_rules! longhand_properties_idents { } } -/// Testing function to check the size of a PropertyDeclaration. We implement -/// this here so that the code can be used by both servo and stylo unit tests. -/// This is important because structs can have different sizes in stylo and -/// servo. -#[cfg(feature = "testing")] -pub fn test_size_of_property_declaration() { - use std::mem::size_of; - - let old = 32; - let new = size_of::(); - if new < old { - panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \ - Good work! Please update the size in components/style/properties/properties.mako.rs.", - old, new) - } else if new > old { - panic!("Your changes have increased the stack size of PropertyDeclaration enum from {} to {}. \ - These enum is present in large quantities in the style, and increasing the size \ - may negatively affect style system performance. Please consider using `boxed=\"True\"` in \ - the longhand If you feel that the increase is necessary, update to the new size in \ - components/style/properties/properties.mako.rs.", - old, new) - } -} - /// Testing function to check the size of all SpecifiedValues. #[cfg(feature = "testing")] pub fn test_size_of_specified_values() { diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml index 6eeb9817c93..185b83b8c5c 100644 --- a/tests/unit/style/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -24,6 +24,7 @@ rustc-serialize = "0.3" selectors = {path = "../../../components/selectors"} servo_atoms = {path = "../../../components/atoms"} servo_config = {path = "../../../components/config"} +servo_url = {path = "../../../components/url"} +size_of_test = {path = "../../../components/size_of_test"} style = {path = "../../../components/style"} style_traits = {path = "../../../components/style_traits"} -servo_url = {path = "../../../components/url"} diff --git a/tests/unit/style/lib.rs b/tests/unit/style/lib.rs index 9d6d2b8e8be..0f531673e19 100644 --- a/tests/unit/style/lib.rs +++ b/tests/unit/style/lib.rs @@ -17,6 +17,7 @@ extern crate selectors; extern crate servo_atoms; extern crate servo_config; extern crate servo_url; +#[macro_use] extern crate size_of_test; extern crate style; extern crate style_traits; extern crate test; diff --git a/tests/unit/style/size_of.rs b/tests/unit/style/size_of.rs index f43163b82c6..c0b14276c24 100644 --- a/tests/unit/style/size_of.rs +++ b/tests/unit/style/size_of.rs @@ -2,10 +2,9 @@ * 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/. */ -#[test] -fn size_of_property_declaration() { - ::style::properties::test_size_of_property_declaration(); -} +use style::properties; + +size_of_test!(test_size_of_property_declaration, properties::PropertyDeclaration, 32); #[test] fn size_of_specified_values() { diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml index 46d9c6df281..23c14fc0a5b 100644 --- a/tests/unit/stylo/Cargo.toml +++ b/tests/unit/stylo/Cargo.toml @@ -19,9 +19,10 @@ atomic_refcell = "0.1" cssparser = "0.13.3" env_logger = "0.4" euclid = "0.11" +geckoservo = {path = "../../../ports/geckolib"} libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} selectors = {path = "../../../components/selectors", features = ["gecko_like_types"]} +size_of_test = {path = "../../../components/size_of_test"} style_traits = {path = "../../../components/style_traits"} -geckoservo = {path = "../../../ports/geckolib"} style = {path = "../../../components/style", features = ["gecko"]} diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs index fedbba703b9..6527c90609f 100644 --- a/tests/unit/stylo/lib.rs +++ b/tests/unit/stylo/lib.rs @@ -8,6 +8,7 @@ extern crate env_logger; extern crate geckoservo; #[macro_use] extern crate log; extern crate selectors; +#[macro_use] extern crate size_of_test; #[macro_use] extern crate style; extern crate style_traits; diff --git a/tests/unit/stylo/size_of.rs b/tests/unit/stylo/size_of.rs index f8770a8842e..ce2e076ba86 100644 --- a/tests/unit/stylo/size_of.rs +++ b/tests/unit/stylo/size_of.rs @@ -19,10 +19,7 @@ fn size_of_selectors_dummy_types() { assert_eq!(align_of::(), align_of::()); } -#[test] -fn size_of_property_declaration() { - ::style::properties::test_size_of_property_declaration(); -} +size_of_test!(test_size_of_property_declaration, style::properties::PropertyDeclaration, 32); #[test] fn size_of_specified_values() { From ee2794e9667cc7ce0f2ab451f94f9206e4109048 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 18 May 2017 18:28:25 +0200 Subject: [PATCH 2/2] Move bindings tests out of the style crate. This cuts in almost half the time to run: ``` touch components/style/lib.rs ./mach test-stylo ``` --- components/style/Cargo.toml | 3 +++ components/style/build.rs | 1 + components/style/lib.rs | 2 +- python/servo/testing_commands.py | 7 +------ tests/unit/stylo/build.rs | 13 +++++++++++++ tests/unit/stylo/lib.rs | 6 ++++++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 708488861e8..e19f2b00768 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -7,6 +7,9 @@ publish = false build = "build.rs" +# https://github.com/rust-lang/cargo/issues/3544 +links = "for some reason the links key is required to pass data around between build scripts" + [lib] name = "style" path = "lib.rs" diff --git a/components/style/build.rs b/components/style/build.rs index 8d40ccb9969..d31bc87e88a 100644 --- a/components/style/build.rs +++ b/components/style/build.rs @@ -83,6 +83,7 @@ fn generate_properties() { fn main() { println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap()); generate_properties(); build_gecko::generate(); } diff --git a/components/style/lib.rs b/components/style/lib.rs index 4210304217f..fc61dd1b001 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -61,7 +61,7 @@ extern crate log; extern crate matches; #[cfg(feature = "gecko")] #[macro_use] -extern crate nsstring_vendor as nsstring; +pub extern crate nsstring_vendor as nsstring; #[cfg(feature = "gecko")] extern crate num_cpus; extern crate num_integer; extern crate num_traits; diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 64d79e38501..a36d50c2658 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -299,13 +299,8 @@ class MachCommands(CommandBase): env["CARGO_TARGET_DIR"] = path.join(self.context.topdir, "target", "geckolib").encode("UTF-8") release = ["--release"] if release else [] - ret = 0 with cd(path.join("ports", "geckolib")): - ret = call(["cargo", "test", "-p", "stylo_tests", "--features", "testing"] + release, env=env) - if ret != 0: - return ret - with cd(path.join("ports", "geckolib")): - return call(["cargo", "test", "-p", "style"] + release, env=env) + return call(["cargo", "test", "-p", "stylo_tests", "--features", "testing"] + release, env=env) @Command('test-compiletest', description='Run compiletests', diff --git a/tests/unit/stylo/build.rs b/tests/unit/stylo/build.rs index fe161688da3..111da70f57e 100644 --- a/tests/unit/stylo/build.rs +++ b/tests/unit/stylo/build.rs @@ -2,6 +2,10 @@ * 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::env; +use std::fs; +use std::io::Write; +use std::path; use std::process::Command; fn main() { @@ -11,4 +15,13 @@ fn main() { println!("cargo:rerun-if-changed=../../../components/style/gecko_bindings/bindings.rs"); assert!(Command::new("python").arg("./check_bindings.py") .spawn().unwrap().wait().unwrap().success()); + + // https://github.com/rust-lang/cargo/issues/3544 + let style_out_dir = env::var_os("DEP_FOR SOME REASON THE LINKS KEY IS REQUIRED \ + TO PASS DATA AROUND BETWEEN BUILD SCRIPTS_OUT_DIR").unwrap(); + fs::File::create(path::PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("bindings.rs")) + .unwrap() + .write_all(format!("include!(concat!({:?}, \"/gecko/structs_debug.rs\"));", + style_out_dir).as_bytes()) + .unwrap(); } diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs index 6527c90609f..05a32869c4e 100644 --- a/tests/unit/stylo/lib.rs +++ b/tests/unit/stylo/lib.rs @@ -17,3 +17,9 @@ mod size_of; mod servo_function_signatures; +use style::*; + +#[allow(dead_code, improper_ctypes)] +mod bindings { + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +}