servo: Merge #15669 - Read ServoArcTypeList.h for list of arc types (from upsuper:bindgen-arc-type); r=heycam
authorXidorn Quan <me@upsuper.org>
Tue, 21 Feb 2017 18:56:41 -0800
changeset 373153 e863fac5d373b4227f9155577c856b8bb05fd855
parent 373152 e52cd3f75ebfeacb1bd2a39df6175fa919777f49
child 373154 4de2e38a987a0c4731befedaa4c50f40f18a2d8f
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs15669
milestone54.0a1
servo: Merge #15669 - Read ServoArcTypeList.h for list of arc types (from upsuper:bindgen-arc-type); r=heycam r? @heycam Source-Repo: https://github.com/servo/servo Source-Revision: 07debf5dc02e48ede1652100377a4c51979ca7e6
servo/components/style/build_gecko.rs
--- a/servo/components/style/build_gecko.rs
+++ b/servo/components/style/build_gecko.rs
@@ -227,16 +227,34 @@ mod bindings {
         let mut result = builder.generate().expect("Unable to generate bindings").to_string();
         for fixup in fixups.iter() {
             result = Regex::new(&format!(r"\b{}\b", fixup.pat)).unwrap().replace_all(&result, fixup.rep.as_str())
                 .into_owned().into();
         }
         File::create(&out_file).unwrap().write_all(&result.into_bytes()).expect("Unable to write output");
     }
 
+    fn get_arc_types() -> Vec<String> {
+        // Read the file
+        let mut list_file = File::open(DISTDIR_PATH.join("include/mozilla/ServoArcTypeList.h"))
+            .expect("Unable to open ServoArcTypeList.h");
+        let mut content = String::new();
+        list_file.read_to_string(&mut content).expect("Fail to read ServoArcTypeList.h");
+        // Remove comments
+        let block_comment_re = Regex::new(r#"(?s)/\*.*?\*/"#).unwrap();
+        let content = block_comment_re.replace_all(&content, "");
+        // Extract the list
+        let re = Regex::new(r#"^SERVO_ARC_TYPE\(\w+,\s*(\w+)\)$"#).unwrap();
+        content.lines().map(|line| line.trim()).filter(|line| !line.is_empty())
+            .map(|line| re.captures(&line)
+                 .expect(&format!("Unrecognized line in ServoArcTypeList.h: '{}'", line))
+                 .get(1).unwrap().as_str().to_string())
+            .collect()
+    }
+
     pub fn generate_structs(build_type: BuildType) {
         let mut builder = Builder::get_initial_builder(build_type)
             .enable_cxx_namespaces()
             .with_codegen_config(CodegenConfig {
                 types: true,
                 vars: true,
                 ..CodegenConfig::nothing()
             })
@@ -595,25 +613,16 @@ mod bindings {
         ];
         struct ArrayType {
             cpp_type: &'static str,
             rust_type: &'static str
         }
         let array_types = [
             ArrayType { cpp_type: "uintptr_t", rust_type: "usize" },
         ];
-        let servo_nullable_arc_types = [
-            "ServoComputedValues",
-            "ServoCssRules",
-            "RawServoStyleSheet",
-            "RawServoDeclarationBlock",
-            "RawServoStyleRule",
-            "RawServoImportRule",
-            "RawServoAnimationValue",
-        ];
         struct ServoOwnedType {
             name: &'static str,
             opaque: bool,
         }
         let servo_owned_types = [
             ServoOwnedType { name: "RawServoStyleSet", opaque: true },
             ServoOwnedType { name: "StyleChildrenIterator", opaque: true },
             ServoOwnedType { name: "ServoElementSnapshot", opaque: false },
@@ -641,17 +650,17 @@ mod bindings {
                     .raw_line(format!("unsafe impl Sync for {} {{}}", ty));
             }
         }
         for &ArrayType { cpp_type, rust_type } in array_types.iter() {
             builder = builder.hide_type(format!("nsTArrayBorrowed_{}", cpp_type))
                 .raw_line(format!("pub type nsTArrayBorrowed_{}<'a> = &'a mut ::gecko_bindings::structs::nsTArray<{}>;",
                                   cpp_type, rust_type))
         }
-        for &ty in servo_nullable_arc_types.iter() {
+        for ty in get_arc_types().iter() {
             builder = builder
                 .hide_type(format!("{}Strong", ty))
                 .raw_line(format!("pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;", ty))
                 .borrowed_type(ty)
                 .zero_size_type(ty, &structs_types);
         }
         for &ServoOwnedType { name, opaque } in servo_owned_types.iter() {
             builder = builder