#!/usr/bin/python import sys, os, re components = { 'Core': 'Q_CORE_EXPORT', 'Gui': 'Q_GUI_EXPORT', 'DBus': 'Q_DBUS_EXPORT', 'Declarative': 'Q_DECLARATIVE_EXPORT', 'Designer': 'QDESIGNER_COMPONENTS_EXPORT|QDESIGNER_EXTENSION_EXPORT|QT_FORMEDITOR_EXPORT|QT_PROPERTYEDITOR_EXPORT|QT_SIGNALSLOTEDITOR_EXPORT|QT_OBJECTINSPECTOR_EXPORT|QT_WIDGETBOX_EXPORT|QT_BUDDYEDITOR_EXPORT|QT_TABORDEREDITOR_EXPORT|QT_TASKMENU_EXPORT', 'Network': 'Q_NETWORK_EXPORT', 'Sql': 'Q_SQL_EXPORT', 'Svg': 'Q_SVG_EXPORT', 'Xml': 'Q_XML_EXPORT', 'Script': 'Q_SCRIPT_EXPORT', 'ScriptTools': 'Q_SCRIPTTOOLS_EXPORT', 'Test': 'Q_TEST_EXPORT', 'UiTools': 'Q_UITOOLS_EXPORT', } mapoutput = 'src/shared/qclass_lib_map.h' classcount = -1 mappedclasses = [] mapdata = '// Automatically generated by genmap.py, DO NOT EDIT!\n\n' mapdata += '#ifndef QT_CLASS_MAP_H\n#define QT_CLASS_MAP_H\n\n' mapdata += 'static const ClassInfoEntry qclass_lib_map[] = {\n' def exportscan(sdir, pattern, component): dirmap = '' regex = re.compile('(?:class|struct) (?:%s) (\w+)' % pattern) global classcount for sroot, sdir, lfiles in os.walk(sdir): for sfile in sorted(lfiles): if not sfile.endswith('.h') or sfile.endswith('_p.h'): continue sfull = '%s/%s' % (sroot, sfile) with open(sfull, 'rb') as f: scontent = f.read() scontent = scontent.decode('utf-8') for match in regex.findall(scontent): if match in mappedclasses: continue mappedclasses.append(match) dirmap += ' { "%s", "%s/%s"},\n' % (match, component, sfile) classcount += 1 return dirmap for component in components: pattern = components[component] mapdata += exportscan('src/%s' % component.lower(), pattern, 'Qt%s' % component) mapdata += '};\n' mapdata += 'static const int qclass_lib_count = %d;\n\n' % classcount mapdata += '#endif\n' with open(mapoutput, 'wb') as f: sys.stdout.write('-- Writing: %s\n' % mapoutput) if sys.version_info[0] == 3: f.write(bytes(mapdata, 'utf-8')) else: f.write(mapdata)