Bug 1885357 - Use a single mako invocation to generate the style crate. r=sergesanspaille

This is significantly faster. While at it:

 * Remove unused "additional_methods".
 * Fix help text to remove an option that no longer exists.

Differential Revision: https://phabricator.services.mozilla.com/D205047
This commit is contained in:
Emilio Cobos Álvarez 2024-03-20 09:51:02 +00:00
parent c9d0da9645
commit e6f37004e1
37 changed files with 71 additions and 185 deletions

View File

@ -30,7 +30,7 @@ def generate_data(output, template):
)
# Add all relevant files into the dependencies of the generated file.
DEP_EXTS = [".py", ".rs", ".zip"]
DEP_EXTS = [".py", ".rs"]
deps = set()
for path, dirs, files in os.walk(SERVO_PROP_BASE):
for file in files:

View File

@ -14,57 +14,9 @@ cargo_extra_outputs = {
"selectors": ["ascii_case_insensitive_html_attributes.rs"],
"style": [
"gecko/atom_macro.rs",
"gecko/bindings.rs",
"gecko/pseudo_element_definition.rs",
"gecko/structs.rs",
"gecko_properties.rs",
"longhands/background.rs",
"longhands/border.rs",
"longhands/box.rs",
"longhands/color.rs",
"longhands/column.rs",
"longhands/counters.rs",
"longhands/effects.rs",
"longhands/font.rs",
"longhands/inherited_box.rs",
"longhands/inherited_svg.rs",
"longhands/inherited_table.rs",
"longhands/inherited_text.rs",
"longhands/inherited_ui.rs",
"longhands/list.rs",
"longhands/margin.rs",
"longhands/outline.rs",
"longhands/padding.rs",
"longhands/position.rs",
"longhands/svg.rs",
"longhands/table.rs",
"longhands/text.rs",
"longhands/ui.rs",
"longhands/xul.rs",
"properties.rs",
"shorthands/background.rs",
"shorthands/border.rs",
"shorthands/box.rs",
"shorthands/color.rs",
"shorthands/column.rs",
"shorthands/counters.rs",
"shorthands/effects.rs",
"shorthands/font.rs",
"shorthands/inherited_box.rs",
"shorthands/inherited_svg.rs",
"shorthands/inherited_table.rs",
"shorthands/inherited_text.rs",
"shorthands/inherited_ui.rs",
"shorthands/list.rs",
"shorthands/margin.rs",
"shorthands/outline.rs",
"shorthands/padding.rs",
"shorthands/position.rs",
"shorthands/svg.rs",
"shorthands/table.rs",
"shorthands/text.rs",
"shorthands/ui.rs",
"shorthands/xul.rs",
],
"webrender": ["shaders.rs"],
"geckodriver": ["build-info.rs"],

View File

@ -20,36 +20,10 @@ RE_PYTHON_ADDR = re.compile(r"<.+? object at 0x[0-9a-fA-F]+>")
OUT_DIR = os.environ.get("OUT_DIR", "")
STYLE_STRUCT_LIST = [
"background",
"border",
"box",
"column",
"counters",
"effects",
"font",
"inherited_box",
"inherited_svg",
"inherited_table",
"inherited_text",
"inherited_ui",
"list",
"margin",
"outline",
"page",
"padding",
"position",
"svg",
"table",
"text",
"ui",
"xul",
]
def main():
usage = (
"Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> | html ]"
"Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> ]"
% sys.argv[0]
)
if len(sys.argv) < 3:
@ -60,26 +34,12 @@ def main():
if engine not in ["servo", "gecko"] or output not in [
"style-crate",
"geckolib",
"html",
]:
abort(usage)
properties = data.PropertiesData(engine=engine)
files = {}
for kind in ["longhands", "shorthands"]:
files[kind] = {}
for struct in STYLE_STRUCT_LIST:
file_name = os.path.join(BASE, kind, "{}.mako.rs".format(struct))
if kind == "shorthands" and not os.path.exists(file_name):
files[kind][struct] = ""
continue
files[kind][struct] = render(
file_name,
engine=engine,
data=properties,
)
properties_template = os.path.join(BASE, "properties.mako.rs")
files["properties"] = render(
properties_file = render(
properties_template,
engine=engine,
data=properties,
@ -87,19 +47,7 @@ def main():
OUT_DIR=OUT_DIR,
)
if output == "style-crate":
write(OUT_DIR, "properties.rs", files["properties"])
for kind in ["longhands", "shorthands"]:
for struct in files[kind]:
write(
os.path.join(OUT_DIR, kind),
"{}.rs".format(struct),
files[kind][struct],
)
if engine == "gecko":
template = os.path.join(BASE, "gecko.mako.rs")
rust = render(template, data=properties)
write(OUT_DIR, "gecko_properties.rs", rust)
write(OUT_DIR, "properties.rs", properties_file)
if engine == "servo":
properties_dict = {

View File

@ -741,7 +741,7 @@ class Method(object):
class StyleStruct(object):
def __init__(self, name, inherited, gecko_name=None, additional_methods=None):
def __init__(self, name, inherited, gecko_name=None):
self.gecko_struct_name = "Gecko" + name
self.name = name
self.name_lower = to_snake_case(name)
@ -750,15 +750,12 @@ class StyleStruct(object):
self.inherited = inherited
self.gecko_name = gecko_name or name
self.gecko_ffi_name = "nsStyle" + self.gecko_name
self.additional_methods = additional_methods or []
self.document_dependent = self.gecko_name in ["Font", "Visibility", "Text"]
class PropertiesData(object):
def __init__(self, engine):
self.engine = engine
self.style_structs = []
self.current_style_struct = None
self.longhands = []
self.longhands_by_name = {}
self.longhands_by_logical_group = {}
@ -770,13 +767,35 @@ class PropertiesData(object):
CountedUnknownProperty(p) for p in COUNTED_UNKNOWN_PROPERTIES
]
def new_style_struct(self, *args, **kwargs):
style_struct = StyleStruct(*args, **kwargs)
self.style_structs.append(style_struct)
self.current_style_struct = style_struct
self.style_structs = [
StyleStruct("Background", inherited=False),
StyleStruct("Border", inherited=False),
StyleStruct("Box", inherited=False, gecko_name="Display"),
StyleStruct("Column", inherited=False),
StyleStruct("Counters", inherited=False, gecko_name="Content"),
StyleStruct("Effects", inherited=False),
StyleStruct("Font", inherited=True),
StyleStruct("InheritedBox", inherited=True, gecko_name="Visibility"),
StyleStruct("InheritedSVG", inherited=True, gecko_name="SVG"),
StyleStruct("InheritedTable", inherited=True, gecko_name="TableBorder"),
StyleStruct("InheritedText", inherited=True, gecko_name="Text"),
StyleStruct("InheritedUI", inherited=True, gecko_name="UI"),
StyleStruct("List", inherited=True),
StyleStruct("Margin", inherited=False),
StyleStruct("Outline", inherited=False),
StyleStruct("Padding", inherited=False),
StyleStruct("Page", inherited=False),
StyleStruct("Position", inherited=False),
StyleStruct("SVG", inherited=False, gecko_name="SVGReset"),
StyleStruct("Table", inherited=False),
StyleStruct("Text", inherited=False, gecko_name="TextReset"),
StyleStruct("UI", inherited=False, gecko_name="UIReset"),
StyleStruct("XUL", inherited=False),
]
self.current_style_struct = None
def active_style_structs(self):
return [s for s in self.style_structs if s.additional_methods or s.longhands]
return [s for s in self.style_structs if s.longhands]
def add_prefixed_aliases(self, property):
# FIXME Servo's DOM architecture doesn't support vendor-prefixed properties.

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("Background", inherited=False) %>
${helpers.predefined_type(
"background-color",
"Color",

View File

@ -3,11 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Keyword, Method, ALL_CORNERS, PHYSICAL_SIDES, ALL_SIDES, maybe_moz_logical_alias %>
<% from data import ALL_CORNERS, ALL_SIDES, maybe_moz_logical_alias %>
<% data.new_style_struct("Border", inherited=False,
additional_methods=[Method("border_" + side + "_has_nonzero_width",
"bool") for side in ["top", "right", "bottom", "left"]]) %>
<%
def maybe_logical_spec(side, kind):
if side[1]: # if it is logical

View File

@ -3,11 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_AXES, Keyword, Method, to_rust_ident, to_camel_case%>
<% data.new_style_struct("Box",
inherited=False,
gecko_name="Display") %>
<% from data import ALL_AXES %>
${helpers.predefined_type(
"display",

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("Column", inherited=False) %>
${helpers.predefined_type(
"column-width",
"length::NonNegativeLengthOrAuto",

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("Counters", inherited=False, gecko_name="Content") %>
${helpers.predefined_type(
"content",
"Content",

View File

@ -4,9 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
// Box-shadow, etc.
<% data.new_style_struct("Effects", inherited=False) %>
${helpers.predefined_type(
"opacity",
"Opacity",

View File

@ -3,9 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Method, to_camel_case, to_rust_ident, to_camel_case_lower, SYSTEM_FONT_LONGHANDS %>
<% data.new_style_struct("Font", inherited=True) %>
<% from data import SYSTEM_FONT_LONGHANDS %>
${helpers.predefined_type(
"font-family",

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("InheritedBox", inherited=True, gecko_name="Visibility") %>
// TODO: collapse. Well, do tables first.
${helpers.single_keyword(
"visibility",

View File

@ -4,10 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
// SVG 2
// https://svgwg.org/svg2-draft/
<% data.new_style_struct("InheritedSVG", inherited=True, gecko_name="SVG") %>
// Section 10 - Text
${helpers.single_keyword(

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("InheritedTable", inherited=True, gecko_name="TableBorder") %>
${helpers.single_keyword(
"border-collapse",
"separate collapse",

View File

@ -3,8 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Keyword %>
<% data.new_style_struct("InheritedText", inherited=True, gecko_name="Text") %>
${helpers.predefined_type(
"color",

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("InheritedUI", inherited=True, gecko_name="UI") %>
${helpers.predefined_type(
"cursor",
"Cursor",

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("List", inherited=True) %>
${helpers.single_keyword(
"list-style-position",
"outside inside",

View File

@ -4,7 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_SIDES, DEFAULT_RULES_AND_PAGE, maybe_moz_logical_alias %>
<% data.new_style_struct("Margin", inherited=False) %>
% for side in ALL_SIDES:
<%

View File

@ -3,13 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Method %>
<% data.new_style_struct("Outline",
inherited=False,
additional_methods=[Method("outline_has_nonzero_width", "bool")]) %>
// TODO(pcwalton): `invert`
${helpers.predefined_type(
"outline-color",
"Color",

View File

@ -4,7 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_SIDES, maybe_moz_logical_alias %>
<% data.new_style_struct("Padding", inherited=False) %>
% for side in ALL_SIDES:
<%

View File

@ -5,8 +5,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import PAGE_RULE %>
<% data.new_style_struct("Page", inherited=False) %>
${helpers.predefined_type(
"size",
"PageSize",

View File

@ -2,12 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%! from data import to_rust_ident %>
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_SIZES, PHYSICAL_SIDES, LOGICAL_SIDES %>
<% data.new_style_struct("Position", inherited=False) %>
// "top" / "left" / "bottom" / "right"
% for side in PHYSICAL_SIDES:
${helpers.predefined_type(

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("SVG", inherited=False, gecko_name="SVGReset") %>
${helpers.single_keyword(
"vector-effect",
"none non-scaling-stroke",

View File

@ -4,8 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<% data.new_style_struct("Table", inherited=False) %>
${helpers.single_keyword(
"table-layout",
"auto fixed",

View File

@ -3,9 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Method %>
<% data.new_style_struct("Text", inherited=False, gecko_name="TextReset") %>
${helpers.predefined_type(
"text-overflow",

View File

@ -3,11 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import DEFAULT_RULES_EXCEPT_KEYFRAME, Method %>
// CSS Basic User Interface Module Level 1
// https://drafts.csswg.org/css-ui-3/
<% data.new_style_struct("UI", inherited=False, gecko_name="UIReset") %>
<% from data import DEFAULT_RULES_EXCEPT_KEYFRAME %>
// TODO spec says that UAs should not support this
// we should probably remove from gecko (https://bugzilla.mozilla.org/show_bug.cgi?id=1328331)

View File

@ -3,10 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import Method %>
// Non-standard properties that Gecko uses for XUL elements.
<% data.new_style_struct("XUL", inherited=False) %>
${helpers.single_keyword(
"-moz-box-align",

View File

@ -17,12 +17,6 @@ pub use self::generated::*;
#[deny(missing_docs)]
pub mod generated {
include!(concat!(env!("OUT_DIR"), "/properties.rs"));
#[cfg(feature = "gecko")]
#[allow(unsafe_code, missing_docs)]
pub mod gecko {
include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs"));
}
}
use crate::custom_properties::{self, ComputedCustomProperties};

View File

@ -87,10 +87,19 @@ macro_rules! expanded {
#[allow(missing_docs)]
pub mod longhands {
% for style_struct in data.style_structs:
include!("${repr(os.path.join(OUT_DIR, 'longhands/{}.rs'.format(style_struct.name_lower)))[1:-1]}");
<% data.current_style_struct = style_struct %>
<%include file="/longhands/${style_struct.name_lower}.mako.rs" />
% endfor
}
#[cfg(feature = "gecko")]
#[allow(unsafe_code, missing_docs)]
pub mod gecko {
<%include file="/gecko.mako.rs" />
}
macro_rules! unwrap_or_initial {
($prop: ident) => (unwrap_or_initial!($prop, $prop));
($prop: ident, $expr: expr) =>
@ -107,7 +116,7 @@ pub mod shorthands {
use crate::values::specified;
% for style_struct in data.style_structs:
include!("${repr(os.path.join(OUT_DIR, 'shorthands/{}.rs'.format(style_struct.name_lower)))[1:-1]}");
<%include file="/shorthands/${style_struct.name_lower}.mako.rs" />
% endfor
// We didn't define the 'all' shorthand using the regular helpers:shorthand

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */

View File

@ -0,0 +1,3 @@
/* 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 https://mozilla.org/MPL/2.0/. */