Bug 1468651: Generate different files for different structs. r=heycam

MozReview-Commit-ID: KEDJ1zJVwMx
This commit is contained in:
Emilio Cobos Álvarez 2018-06-19 13:30:04 +02:00
Родитель 83365c8ff0
Коммит 868eba5610
2 изменённых файлов: 66 добавлений и 42 удалений

Просмотреть файл

@ -19,6 +19,34 @@ 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]
@ -31,14 +59,41 @@ def main():
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)

Просмотреть файл

@ -97,29 +97,9 @@ 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 {
@ -163,22 +143,11 @@ pub mod shorthands {
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" />
% for style_struct in data.style_structs:
include!("${os.path.join(OUT_DIR, 'shorthands/{}.rs'.format(style_struct.name_lower))}");
% endfor
// 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.
//
// Also, make sure logical properties appear before its physical