Bug 1135075 - move generation of nsStyleStructList.h to GENERATED_FILES; r=mshal

We can't completely eliminate the Makefile.in here, because we still
need the INSTALL_TARGETS bits to export the generated header, but we can
at least get rid of a lot of the Makefile.in.
This commit is contained in:
Nathan Froyd 2015-02-20 09:51:28 -05:00
parent f11edd5123
commit 096d149883
3 changed files with 32 additions and 34 deletions

View File

@ -6,12 +6,3 @@ INSTALL_TARGETS += structlist
structlist_FILES := nsStyleStructList.h
structlist_DEST = $(DIST)/include
structlist_TARGET := export
include $(topsrcdir)/config/rules.mk
nsStyleStructList.h : $(srcdir)/generate-stylestructlist.py
$(PYTHON) $< > $@
GARBAGE += \
nsStyleStructList.h \
$(NULL)

53
layout/style/generate-stylestructlist.py Normal file → Executable file
View File

@ -37,6 +37,8 @@
# closer to one power of two than the next higher one -- the average number of
# comparisons can be reduced by splitting the top level check into more than 2.
from __future__ import print_function
import math
NORMAL_DEP = ["Variables"]
@ -106,49 +108,49 @@ for i in range(count):
break
else:
import sys
print >>sys.stderr, "ERROR: Cannot resolve style struct dependencies"
print >>sys.stderr, "Resolved items:", " ".join(resolved_items)
print("ERROR: Cannot resolve style struct dependencies", file=sys.stderr)
print("Resolved items:", " ".join(resolved_items), file=sys.stderr)
unsolved_items = [name for _, name, _, _ in STYLE_STRUCTS
if name not in resolved_items]
print >>sys.stderr, "There exist cyclic dependencies between " +\
"the following structs:", " ".join(unsolved_items)
print("There exist cyclic dependencies between " +
"the following structs:", " ".join(unsolved_items), file=sys.stderr)
exit(1)
def nextPowerOf2(x):
return int(pow(2, math.ceil(math.log(x, 2))))
def printEntry(i):
print "STYLE_STRUCT_%s(%s, %s)" % STYLE_STRUCTS[i][:3]
def printEntry(header, i):
print("STYLE_STRUCT_%s(%s, %s)" % STYLE_STRUCTS[i][:3], file=header)
for dep in STYLE_STRUCTS[i][3]:
print "STYLE_STRUCT_DEP(%s)" % (dep,)
print "STYLE_STRUCT_END()"
print("STYLE_STRUCT_DEP(%s)" % (dep,), file=header)
print("STYLE_STRUCT_END()", file=header)
def printTestTree(min, max, depth, branches):
def printTestTree(header, min, max, depth, branches):
indent = " " * depth
if min == count - 1 and max >= count:
print " STYLE_STRUCT_TEST_CODE(%sNS_ASSERTION(STYLE_STRUCT_TEST == %d, \"out of range\");)" % (indent, min)
printEntry(min)
print(" STYLE_STRUCT_TEST_CODE(%sNS_ASSERTION(STYLE_STRUCT_TEST == %d, \"out of range\");)" % (indent, min), file=header)
printEntry(header, min)
elif max - min == 2:
print " STYLE_STRUCT_TEST_CODE(%sif (STYLE_STRUCT_TEST == %d) {)" % (indent, min)
printEntry(min)
print " STYLE_STRUCT_TEST_CODE(%s} else {)" % indent
printEntry(min + 1)
print " STYLE_STRUCT_TEST_CODE(%s})" % indent
print(" STYLE_STRUCT_TEST_CODE(%sif (STYLE_STRUCT_TEST == %d) {)" % (indent, min), file=header)
printEntry(header, min)
print(" STYLE_STRUCT_TEST_CODE(%s} else {)" % indent, file=header)
printEntry(header, min + 1)
print(" STYLE_STRUCT_TEST_CODE(%s})" % indent, file=header)
elif min < count:
mid = min + (max - min) / branches
print " STYLE_STRUCT_TEST_CODE(%sif (STYLE_STRUCT_TEST < %d) {)" % (indent, mid)
printTestTree(min, mid, depth + 1, 2)
print(" STYLE_STRUCT_TEST_CODE(%sif (STYLE_STRUCT_TEST < %d) {)" % (indent, mid), file=header)
printTestTree(header, min, mid, depth + 1, 2)
for branch in range(1, branches):
lo = min + branch * (max - min) / branches
hi = min + (branch + 1) * (max - min) / branches
if lo >= count:
break
if branch == branches - 1 or hi >= count:
print " STYLE_STRUCT_TEST_CODE(%s} else {)" % indent
print(" STYLE_STRUCT_TEST_CODE(%s} else {)" % indent, file=header)
else:
print " STYLE_STRUCT_TEST_CODE(%s} else if (STYLE_STRUCT_TEST < %d) {)" % (indent, hi)
printTestTree(lo, hi, depth + 1, 2)
print " STYLE_STRUCT_TEST_CODE(%s})" % indent
print(" STYLE_STRUCT_TEST_CODE(%s} else if (STYLE_STRUCT_TEST < %d) {)" % (indent, hi), file=header)
printTestTree(header, lo, hi, depth + 1, 2)
print(" STYLE_STRUCT_TEST_CODE(%s})" % indent, file=header)
HEADER = """/* THIS FILE IS AUTOGENERATED BY generate-stylestructlist.py - DO NOT EDIT */
@ -223,6 +225,7 @@ FOOTER = """
#undef STYLE_STRUCT_TEST_CODE
"""
print HEADER
printTestTree(0, nextPowerOf2(count), 0, TOPLEVELBRANCHES)
print FOOTER
def main(header):
print(HEADER, file=header)
printTestTree(header, 0, nextPowerOf2(count), 0, TOPLEVELBRANCHES)
print(FOOTER, file=header)

View File

@ -175,6 +175,10 @@ RESOURCE_FILES += [
'TopLevelVideoDocument.css',
]
GENERATED_FILES += ['nsStyleStructList.h']
style_struct_list = GENERATED_FILES['nsStyleStructList.h']
style_struct_list.script = 'generate-stylestructlist.py'
if CONFIG['GNU_CC']:
CFLAGS += ['-Wshadow']
CXXFLAGS += ['-Wshadow']