mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Generate different files for different structs.
Bug: 1468651 Reviewed-by: heycam MozReview-Commit-ID: KEDJ1zJVwMx
This commit is contained in:
parent
a4dcb33986
commit
202ec8a8c8
2 changed files with 66 additions and 42 deletions
|
@ -19,6 +19,34 @@ import data
|
||||||
|
|
||||||
RE_PYTHON_ADDR = re.compile(r'<.+? object at 0x[0-9a-fA-F]+>')
|
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",
|
||||||
|
"color",
|
||||||
|
"column",
|
||||||
|
"counters",
|
||||||
|
"effects",
|
||||||
|
"font",
|
||||||
|
"inherited_box",
|
||||||
|
"inherited_table",
|
||||||
|
"inherited_text",
|
||||||
|
"inherited_ui",
|
||||||
|
"inherited_svg",
|
||||||
|
"list",
|
||||||
|
"margin",
|
||||||
|
"outline",
|
||||||
|
"padding",
|
||||||
|
"position",
|
||||||
|
"table",
|
||||||
|
"text",
|
||||||
|
"ui",
|
||||||
|
"svg",
|
||||||
|
"xul",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> | html ]" % sys.argv[0]
|
usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> | html ]" % sys.argv[0]
|
||||||
|
@ -31,14 +59,41 @@ def main():
|
||||||
abort(usage)
|
abort(usage)
|
||||||
|
|
||||||
properties = data.PropertiesData(product=product)
|
properties = data.PropertiesData(product=product)
|
||||||
template = os.path.join(BASE, "properties.mako.rs")
|
files = {}
|
||||||
rust = render(template, product=product, data=properties, __file__=template)
|
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,
|
||||||
|
product = product,
|
||||||
|
data = properties,
|
||||||
|
)
|
||||||
|
properties_template = os.path.join(BASE, "properties.mako.rs")
|
||||||
|
files["properties"] = render(
|
||||||
|
properties_template,
|
||||||
|
product = product,
|
||||||
|
data = properties,
|
||||||
|
__file__ = properties_template,
|
||||||
|
OUT_DIR = OUT_DIR,
|
||||||
|
)
|
||||||
if output == "style-crate":
|
if output == "style-crate":
|
||||||
write(os.environ["OUT_DIR"], "properties.rs", rust)
|
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 product == "gecko":
|
if product == "gecko":
|
||||||
template = os.path.join(BASE, "gecko.mako.rs")
|
template = os.path.join(BASE, "gecko.mako.rs")
|
||||||
rust = render(template, data=properties)
|
rust = render(template, data=properties)
|
||||||
write(os.environ["OUT_DIR"], "gecko_properties.rs", rust)
|
write(OUT_DIR, "gecko_properties.rs", rust)
|
||||||
elif output == "geckolib":
|
elif output == "geckolib":
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 4:
|
||||||
abort(usage)
|
abort(usage)
|
||||||
|
|
|
@ -97,29 +97,9 @@ macro_rules! expanded {
|
||||||
/// A module with all the code for longhand properties.
|
/// A module with all the code for longhand properties.
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub mod longhands {
|
pub mod longhands {
|
||||||
<%include file="/longhands/background.mako.rs" />
|
% for style_struct in data.style_structs:
|
||||||
<%include file="/longhands/border.mako.rs" />
|
include!("${os.path.join(OUT_DIR, 'longhands/{}.rs'.format(style_struct.name_lower))}");
|
||||||
<%include file="/longhands/box.mako.rs" />
|
% endfor
|
||||||
<%include file="/longhands/color.mako.rs" />
|
|
||||||
<%include file="/longhands/column.mako.rs" />
|
|
||||||
<%include file="/longhands/counters.mako.rs" />
|
|
||||||
<%include file="/longhands/effects.mako.rs" />
|
|
||||||
<%include file="/longhands/font.mako.rs" />
|
|
||||||
<%include file="/longhands/inherited_box.mako.rs" />
|
|
||||||
<%include file="/longhands/inherited_table.mako.rs" />
|
|
||||||
<%include file="/longhands/inherited_text.mako.rs" />
|
|
||||||
<%include file="/longhands/inherited_ui.mako.rs" />
|
|
||||||
<%include file="/longhands/list.mako.rs" />
|
|
||||||
<%include file="/longhands/margin.mako.rs" />
|
|
||||||
<%include file="/longhands/outline.mako.rs" />
|
|
||||||
<%include file="/longhands/padding.mako.rs" />
|
|
||||||
<%include file="/longhands/position.mako.rs" />
|
|
||||||
<%include file="/longhands/table.mako.rs" />
|
|
||||||
<%include file="/longhands/text.mako.rs" />
|
|
||||||
<%include file="/longhands/ui.mako.rs" />
|
|
||||||
<%include file="/longhands/inherited_svg.mako.rs" />
|
|
||||||
<%include file="/longhands/svg.mako.rs" />
|
|
||||||
<%include file="/longhands/xul.mako.rs" />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! unwrap_or_initial {
|
macro_rules! unwrap_or_initial {
|
||||||
|
@ -163,22 +143,11 @@ pub mod shorthands {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
<%include file="/shorthands/background.mako.rs" />
|
% for style_struct in data.style_structs:
|
||||||
<%include file="/shorthands/border.mako.rs" />
|
include!("${os.path.join(OUT_DIR, 'shorthands/{}.rs'.format(style_struct.name_lower))}");
|
||||||
<%include file="/shorthands/box.mako.rs" />
|
% endfor
|
||||||
<%include file="/shorthands/column.mako.rs" />
|
|
||||||
<%include file="/shorthands/font.mako.rs" />
|
|
||||||
<%include file="/shorthands/inherited_text.mako.rs" />
|
|
||||||
<%include file="/shorthands/list.mako.rs" />
|
|
||||||
<%include file="/shorthands/margin.mako.rs" />
|
|
||||||
<%include file="/shorthands/svg.mako.rs" />
|
|
||||||
<%include file="/shorthands/outline.mako.rs" />
|
|
||||||
<%include file="/shorthands/padding.mako.rs" />
|
|
||||||
<%include file="/shorthands/position.mako.rs" />
|
|
||||||
<%include file="/shorthands/inherited_svg.mako.rs" />
|
|
||||||
<%include file="/shorthands/text.mako.rs" />
|
|
||||||
|
|
||||||
// We don't defined the 'all' shorthand using the regular helpers:shorthand
|
// We didn't define the 'all' shorthand using the regular helpers:shorthand
|
||||||
// mechanism, since it causes some very large types to be generated.
|
// mechanism, since it causes some very large types to be generated.
|
||||||
//
|
//
|
||||||
// Also, make sure logical properties appear before its physical
|
// Also, make sure logical properties appear before its physical
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue