--- a/servo/components/style/properties/build.py
+++ b/servo/components/style/properties/build.py
@@ -14,36 +14,91 @@ sys.path.insert(0, BASE) # For importin
from mako import exceptions
from mako.lookup import TemplateLookup
from mako.template import Template
import data
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():
usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> | html ]" % sys.argv[0]
if len(sys.argv) < 3:
abort(usage)
product = sys.argv[1]
output = sys.argv[2]
if product not in ["servo", "gecko"] or output not in ["style-crate", "geckolib", "html"]:
abort(usage)
properties = data.PropertiesData(product=product)
- template = os.path.join(BASE, "properties.mako.rs")
- rust = render(template, product=product, data=properties, __file__=template)
+ 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,
+ 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":
- 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":
template = os.path.join(BASE, "gecko.mako.rs")
rust = render(template, data=properties)
- write(os.environ["OUT_DIR"], "gecko_properties.rs", rust)
+ write(OUT_DIR, "gecko_properties.rs", rust)
elif output == "geckolib":
if len(sys.argv) < 4:
abort(usage)
template = sys.argv[3]
header = render(template, data=properties)
sys.stdout.write(header)
elif output == "html":
write_html(properties)
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -92,39 +92,19 @@ macro_rules! expanded {
)+
}
}
}
/// A module with all the code for longhand properties.
#[allow(missing_docs)]
pub mod longhands {
- <%include file="/longhands/background.mako.rs" />
- <%include file="/longhands/border.mako.rs" />
- <%include file="/longhands/box.mako.rs" />
- <%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" />
+ % for style_struct in data.style_structs:
+ include!("${os.path.join(OUT_DIR, 'longhands/{}.rs'.format(style_struct.name_lower))}");
+ % endfor
}
macro_rules! unwrap_or_initial {
($prop: ident) => (unwrap_or_initial!($prop, $prop));
($prop: ident, $expr: expr) =>
($expr.unwrap_or_else(|| $prop::get_initial_specified_value()));
}
@@ -158,32 +138,21 @@ pub mod shorthands {
style.to_css(dest)?;
if *color != Color::CurrentColor {
dest.write_str(" ")?;
color.to_css(dest)?;
}
Ok(())
}
- <%include file="/shorthands/background.mako.rs" />
- <%include file="/shorthands/border.mako.rs" />
- <%include file="/shorthands/box.mako.rs" />
- <%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
+ % for style_struct in data.style_structs:
+ include!("${os.path.join(OUT_DIR, 'shorthands/{}.rs'.format(style_struct.name_lower))}");
+ % endfor
+
+ // We didn't define the 'all' shorthand using the regular helpers:shorthand
// mechanism, since it causes some very large types to be generated.
//
// Also, make sure logical properties appear before its physical
// counter-parts, in order to prevent bugs like:
//
// https://bugzilla.mozilla.org/show_bug.cgi?id=1410028
//
// FIXME(emilio): Adopt the resolution from: