Optimize log print by using html format

Summary:
See facebook/yoga#453. Optimizes the node log print by generating some enum text via ```enum.py``` and moving printing to new functions to reduce boilerplate code.

Changes the log output to format the nodes in html to be able to copy paste it  into browsers for quick debugging.

Hides all default values.
Closes https://github.com/facebook/yoga/pull/479

Reviewed By: gkassabli

Differential Revision: D4802184

Pulled By: emilsjolander

fbshipit-source-id: 143bd63cbc31fb0755d711062cb4e6a448049ba3
This commit is contained in:
Lukas Wöhrl
2017-04-03 09:34:42 -07:00
committed by Facebook Github Bot
parent 5112564f08
commit 586b57009a
8 changed files with 443 additions and 153 deletions

View File

@@ -125,6 +125,16 @@ def to_java_upper(symbol):
out += c.upper()
return out
def to_log_lower(symbol):
symbol = str(symbol)
out = ''
for i in range(0, len(symbol)):
c = symbol[i]
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
out += '-'
out += c.lower()
return out
root = os.path.dirname(os.path.abspath(__file__))
@@ -143,9 +153,28 @@ with open(root + '/yoga/YGEnums.h', 'w') as f:
else:
f.write(' YG%s%s,\n' % (name, value))
f.write('} YG_ENUM_END(YG%s);\n' % name)
f.write('WIN_EXPORT const char *YG%sToString(const YG%s value);\n' % (name, name))
f.write('\n')
f.write('YG_EXTERN_C_END\n')
# write out C body for printing
with open(root + '/yoga/YGEnums.c', 'w') as f:
f.write(LICENSE)
f.write('#include "YGEnums.h"\n\n')
for name, values in sorted(ENUMS.items()):
f.write('const char *YG%sToString(const YG%s value){\n' % (name, name))
f.write(' switch(value){\n')
for value in values:
if isinstance(value, tuple):
f.write(' case YG%s%s:\n' % (name, value[0]))
f.write(' return "%s";\n' % to_log_lower(value[0]))
else:
f.write(' case YG%s%s:\n' % (name, value))
f.write(' return "%s";\n' % to_log_lower(value))
f.write(' }\n')
f.write(' return "unknown";\n')
f.write('}\n\n')
# write out java files
for name, values in sorted(ENUMS.items()):
with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f: