mirror of
https://github.com/servo/servo.git
synced 2025-07-16 20:03:39 +01:00
stylo: Use proper namespaces in bindings.
This allows us to incrementally remove both bindgen hacks and stylo hacks.
This commit is contained in:
parent
0fe94a6724
commit
eafa13c724
1 changed files with 53 additions and 20 deletions
|
@ -5,12 +5,15 @@
|
||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
import copy
|
import copy
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import fileinput
|
||||||
|
|
||||||
import regen_atoms
|
import regen_atoms
|
||||||
|
|
||||||
|
@ -23,7 +26,6 @@ COMPILATION_TARGETS = {
|
||||||
COMMON_BUILD_KEY: {
|
COMMON_BUILD_KEY: {
|
||||||
"flags": [
|
"flags": [
|
||||||
"--no-unstable-rust",
|
"--no-unstable-rust",
|
||||||
"--disable-name-namespacing",
|
|
||||||
],
|
],
|
||||||
"clang_flags": [
|
"clang_flags": [
|
||||||
"-x", "c++", "-std=c++14",
|
"-x", "c++", "-std=c++14",
|
||||||
|
@ -43,6 +45,13 @@ COMPILATION_TARGETS = {
|
||||||
"structs": {
|
"structs": {
|
||||||
"target_dir": "../gecko_bindings",
|
"target_dir": "../gecko_bindings",
|
||||||
"flags": [
|
"flags": [
|
||||||
|
"--enable-cxx-namespaces",
|
||||||
|
# FIXME(emilio): Incrementally remove these. Probably mozilla::css
|
||||||
|
# and mozilla::dom are easier.
|
||||||
|
"--raw-line", "pub use self::root::*;",
|
||||||
|
"--raw-line", "pub use self::root::mozilla::*;",
|
||||||
|
"--raw-line", "pub use self::root::mozilla::css::*;",
|
||||||
|
"--raw-line", "pub use self::root::mozilla::dom::*;",
|
||||||
"--generate", "types,vars",
|
"--generate", "types,vars",
|
||||||
],
|
],
|
||||||
"includes": [
|
"includes": [
|
||||||
|
@ -69,7 +78,6 @@ COMPILATION_TARGETS = {
|
||||||
"raw_lines": [
|
"raw_lines": [
|
||||||
"use atomic_refcell::AtomicRefCell;",
|
"use atomic_refcell::AtomicRefCell;",
|
||||||
"use data::ElementData;",
|
"use data::ElementData;",
|
||||||
"pub use nsstring::nsStringRepr as nsString;"
|
|
||||||
],
|
],
|
||||||
"blacklist_types": [
|
"blacklist_types": [
|
||||||
"nsString",
|
"nsString",
|
||||||
|
@ -86,11 +94,11 @@ COMPILATION_TARGETS = {
|
||||||
],
|
],
|
||||||
"whitelist": [
|
"whitelist": [
|
||||||
"RawGecko.*",
|
"RawGecko.*",
|
||||||
"mozilla_ServoElementSnapshot.*",
|
"mozilla::ServoElementSnapshot.*",
|
||||||
"mozilla_ConsumeStyleBehavior",
|
"mozilla::ConsumeStyleBehavior",
|
||||||
"mozilla_LazyComputeBehavior",
|
"mozilla::LazyComputeBehavior",
|
||||||
"mozilla_css_SheetParsingMode",
|
"mozilla::css::SheetParsingMode",
|
||||||
"mozilla_SkipRootBehavior",
|
"mozilla::SkipRootBehavior",
|
||||||
".*ThreadSafe.*Holder",
|
".*ThreadSafe.*Holder",
|
||||||
"AnonymousContent",
|
"AnonymousContent",
|
||||||
"AudioContext",
|
"AudioContext",
|
||||||
|
@ -184,7 +192,7 @@ COMPILATION_TARGETS = {
|
||||||
"ServoAttrSnapshot",
|
"ServoAttrSnapshot",
|
||||||
"ServoElementSnapshot",
|
"ServoElementSnapshot",
|
||||||
"SheetParsingMode",
|
"SheetParsingMode",
|
||||||
"mozilla_Side",
|
"mozilla::Side",
|
||||||
"StaticRefPtr",
|
"StaticRefPtr",
|
||||||
"StyleAnimation",
|
"StyleAnimation",
|
||||||
"StyleBasicShape",
|
"StyleBasicShape",
|
||||||
|
@ -192,7 +200,8 @@ COMPILATION_TARGETS = {
|
||||||
"StyleClipPath",
|
"StyleClipPath",
|
||||||
"StyleClipPathGeometryBox",
|
"StyleClipPathGeometryBox",
|
||||||
"StyleTransition",
|
"StyleTransition",
|
||||||
"UniquePtr",
|
"mozilla::UniquePtr",
|
||||||
|
"mozilla::DefaultDelete",
|
||||||
],
|
],
|
||||||
"bitfield_enum_types": ["nsChangeHint", "nsRestyleHint"],
|
"bitfield_enum_types": ["nsChangeHint", "nsRestyleHint"],
|
||||||
"opaque_types": [
|
"opaque_types": [
|
||||||
|
@ -205,12 +214,12 @@ COMPILATION_TARGETS = {
|
||||||
"RefPtr_Proxy_member_function",
|
"RefPtr_Proxy_member_function",
|
||||||
"nsAutoPtr_Proxy",
|
"nsAutoPtr_Proxy",
|
||||||
"nsAutoPtr_Proxy_member_function",
|
"nsAutoPtr_Proxy_member_function",
|
||||||
"mozilla_detail_PointerType",
|
"mozilla::detail::PointerType",
|
||||||
"mozilla_Pair_Base",
|
"mozilla::Pair_Base",
|
||||||
"mozilla_SupportsWeakPtr",
|
"mozilla::SupportsWeakPtr",
|
||||||
"SupportsWeakPtr",
|
"SupportsWeakPtr",
|
||||||
"mozilla_detail_WeakReference",
|
"mozilla::detail::WeakReference",
|
||||||
"mozilla_WeakPtr",
|
"mozilla::WeakPtr",
|
||||||
"nsWritingIterator_reference", "nsReadingIterator_reference",
|
"nsWritingIterator_reference", "nsReadingIterator_reference",
|
||||||
"nsTObserverArray", # <- Inherits from nsAutoTObserverArray<T, 0>
|
"nsTObserverArray", # <- Inherits from nsAutoTObserverArray<T, 0>
|
||||||
"nsTHashtable", # <- Inheriting from inner typedefs that clang
|
"nsTHashtable", # <- Inheriting from inner typedefs that clang
|
||||||
|
@ -221,19 +230,22 @@ COMPILATION_TARGETS = {
|
||||||
# for clang.
|
# for clang.
|
||||||
"nsPIDOMWindow", # <- Takes the vtable from a template parameter, and we can't
|
"nsPIDOMWindow", # <- Takes the vtable from a template parameter, and we can't
|
||||||
# generate it conditionally.
|
# generate it conditionally.
|
||||||
"JS_Rooted",
|
"JS::Rooted",
|
||||||
"mozilla_Maybe",
|
"mozilla::Maybe",
|
||||||
"gfxSize", # <- union { struct { T width; T height; }; T components[2] };
|
"gfxSize", # <- union { struct { T width; T height; }; T components[2] };
|
||||||
"gfxSize_Super", # Ditto.
|
"gfxSize_Super", # Ditto.
|
||||||
],
|
],
|
||||||
|
"manual_fixups": [
|
||||||
|
["root::nsString", "::nsstring::nsStringRepr"]
|
||||||
|
],
|
||||||
"servo_mapped_generic_types": [
|
"servo_mapped_generic_types": [
|
||||||
{
|
{
|
||||||
"generic": True,
|
"generic": True,
|
||||||
"gecko": "ServoUnsafeCell",
|
"gecko": "mozilla::ServoUnsafeCell",
|
||||||
"servo": "::std::cell::UnsafeCell"
|
"servo": "::std::cell::UnsafeCell"
|
||||||
}, {
|
}, {
|
||||||
"generic": True,
|
"generic": True,
|
||||||
"gecko": "ServoCell",
|
"gecko": "mozilla::ServoCell",
|
||||||
"servo": "::std::cell::Cell"
|
"servo": "::std::cell::Cell"
|
||||||
}, {
|
}, {
|
||||||
"generic": False,
|
"generic": False,
|
||||||
|
@ -252,6 +264,7 @@ COMPILATION_TARGETS = {
|
||||||
],
|
],
|
||||||
"flags": [
|
"flags": [
|
||||||
"--generate", "functions",
|
"--generate", "functions",
|
||||||
|
"--disable-name-namespacing",
|
||||||
],
|
],
|
||||||
"match_headers": [
|
"match_headers": [
|
||||||
"ServoBindingList.h",
|
"ServoBindingList.h",
|
||||||
|
@ -481,6 +494,16 @@ def build(objdir, target_name, debug, debugger, kind_name=None,
|
||||||
|
|
||||||
flags = []
|
flags = []
|
||||||
|
|
||||||
|
# Types we have to fixup since we insert them manually.
|
||||||
|
#
|
||||||
|
# Bindgen only allows us to add stuff outside of the root module. This
|
||||||
|
# wasn't intended to add new types, but we do so, so we postprocess the
|
||||||
|
# bindgen output to fixup the path to these types.
|
||||||
|
fixups = []
|
||||||
|
|
||||||
|
if "manual_fixups" in current_target:
|
||||||
|
fixups = current_target["manual_fixups"]
|
||||||
|
|
||||||
# This makes an FFI-safe void type that can't be matched on
|
# This makes an FFI-safe void type that can't be matched on
|
||||||
# &VoidType is UB to have, because you can match on it
|
# &VoidType is UB to have, because you can match on it
|
||||||
# to produce a reachable unreachable. If it's wrapped in
|
# to produce a reachable unreachable. If it's wrapped in
|
||||||
|
@ -610,9 +633,12 @@ Option<&'a mut {0}>;".format(ty))
|
||||||
if "servo_mapped_generic_types" in current_target:
|
if "servo_mapped_generic_types" in current_target:
|
||||||
for ty in current_target["servo_mapped_generic_types"]:
|
for ty in current_target["servo_mapped_generic_types"]:
|
||||||
flags.append("--blacklist-type")
|
flags.append("--blacklist-type")
|
||||||
flags.append("mozilla_{}".format(ty["gecko"]))
|
flags.append(ty["gecko"])
|
||||||
|
|
||||||
|
gecko_name = ty["gecko"].split("::")[-1]
|
||||||
flags.append("--raw-line")
|
flags.append("--raw-line")
|
||||||
flags.append("pub type {0}{2} = {1}{2};".format(ty["gecko"], ty["servo"], "<T>" if ty["generic"] else ""))
|
flags.append("pub type {0}{2} = {1}{2};".format(gecko_name, ty["servo"], "<T>" if ty["generic"] else ""))
|
||||||
|
fixups.append(["root::{}".format(ty["gecko"]), "::gecko_bindings::structs::{}".format(gecko_name)])
|
||||||
|
|
||||||
if "servo_owned_types" in current_target:
|
if "servo_owned_types" in current_target:
|
||||||
for entry in current_target["servo_owned_types"]:
|
for entry in current_target["servo_owned_types"]:
|
||||||
|
@ -686,6 +712,13 @@ Option<&'a mut {0}>;".format(ty))
|
||||||
print("FAIL\n", e.output)
|
print("FAIL\n", e.output)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
generated = fileinput.input(output_filename, inplace=True)
|
||||||
|
for line in generated:
|
||||||
|
for fixup in fixups:
|
||||||
|
line = re.sub("\\b{}\\b".format(fixup[0]), fixup[1], line)
|
||||||
|
print(line, end='')
|
||||||
|
generated.close()
|
||||||
|
|
||||||
print("OK")
|
print("OK")
|
||||||
print("(please test with ./mach test-stylo)")
|
print("(please test with ./mach test-stylo)")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue