def headerToClass(headerfile, options): if options.verbose: print "Processing '%s'" % headerfile classfile = headerfile.replace(".h", ".hkclass") master = headerToDom.headerToDom(headerfile) if options.verbose: print "Found:", ", ".join([c.name for c in master.file._class]) if os.path.exists(classfile): edited = hkcToDom.hkcToDom(classfile) rejects = mergeBind.mergeBind(master.file, edited.file, master.name) if len(rejects): rejfile = "%s.rej" % classfile open(rejfile, "a").write("\n".join(rejects) + "\n") print "%s:1:Conflicts found" % headerfile pch_file = options.pch_file cppfile = master.file.destinationFilename( master.origfilename, "Class%s.cpp" % options.version_suffix) if master.file.overridedestination: pch_file = hkcToDom.Document(cppfile).pchfile try: cpptext = domToClass.domToClass(master, collectAll=False, pchfile=pch_file) except: print "Error in: " + headerfile raise try: writeIfDifferent(cpptext, cppfile, options.force_output) except IOError: print "Error in: %(headerfile)s\n\nDestination class file path is wrong:\n%(cppfile)s.\n" % locals( ) raise if options.dump_xml: xmltext = bindingToXml.bindingToXml("document", master) try: xmlfile = genPathToFile( headerfile.replace(".h", "Class%s.xml" % options.version_suffix), destSpecifier) writeIfDifferent(xmltext, xmlfile, options.force_output) except IOError: print "Error in: %(headerfile)s\n\nDestination class file path is wrong:\n%(xmlfile)s.\n" % locals( ) raise if options.cvsignore: removeFromCvsignore(headerfile) addToCvsignore(cppfile) addToCvsignore(classfile)
def classToHeader(classfile, options): if options.verbose: print "Processing '%s'" % classfile dom = hkcToDom.hkcToDom(classfile) headerfile, cppfile = classfile.replace(".hkclass",".h"), classfile.replace(".hkclass","Class.cpp") try: if util.hasReflectionDeclaration(open(headerfile).read()): raise RuntimeError("'%s' contains HK_DECLARE_REFLECTION. Not overwriting" % headerfile) except IOError: pass writeIfDifferent( domToHeader.domToHeader(dom), headerfile ) writeIfDifferent( domToClass.domToClass(dom), cppfile ) if options.cvsignore: removeFromCvsignore(classfile) addToCvsignore(headerfile) addToCvsignore(cppfile)
def headerToClass(headerfile, options): if options.verbose: print "Processing '%s'" % headerfile classfile = headerfile.replace(".h", ".hkclass") master = headerToDom.headerToDom(headerfile) if options.verbose: print "Found:", ", ".join( [c.name for c in master.file._class] ) if os.path.exists(classfile): edited = hkcToDom.hkcToDom(classfile) rejects = mergeBind.mergeBind(master.file, edited.file, master.name) if len(rejects): rejfile = "%s.rej" % classfile open(rejfile,"a").write( "\n".join(rejects)+"\n" ) print "%s:1:Conflicts found" % headerfile pch_file = options.pch_file cppfile = master.file.destinationFilename(master.origfilename, "Class%s.cpp" % options.version_suffix ) if master.file.overridedestination: pch_file = hkcToDom.Document(cppfile).pchfile try: cpptext = domToClass.domToClass(master, collectAll=False, pchfile=pch_file) except: print "Error in: " + headerfile raise try: writeIfDifferent( cpptext, cppfile, options.force_output ) except IOError: print "Error in: %(headerfile)s\n\nDestination class file path is wrong:\n%(cppfile)s.\n" % locals() raise if options.dump_xml: xmltext = bindingToXml.bindingToXml("document",master) try: xmlfile = genPathToFile(headerfile.replace(".h", "Class%s.xml" % options.version_suffix ), destSpecifier) writeIfDifferent( xmltext, xmlfile, options.force_output ) except IOError: print "Error in: %(headerfile)s\n\nDestination class file path is wrong:\n%(xmlfile)s.\n" % locals() raise if options.cvsignore: removeFromCvsignore(headerfile) addToCvsignore(cppfile) addToCvsignore(classfile)
def classToHeader(classfile, options): if options.verbose: print "Processing '%s'" % classfile dom = hkcToDom.hkcToDom(classfile) headerfile, cppfile = classfile.replace(".hkclass", ".h"), classfile.replace( ".hkclass", "Class.cpp") try: if util.hasReflectionDeclaration(open(headerfile).read()): raise RuntimeError( "'%s' contains HK_DECLARE_REFLECTION. Not overwriting" % headerfile) except IOError: pass writeIfDifferent(domToHeader.domToHeader(dom), headerfile) writeIfDifferent(domToClass.domToClass(dom), cppfile) if options.cvsignore: removeFromCvsignore(classfile) addToCvsignore(headerfile) addToCvsignore(cppfile)
def processDir(where, options): nfile = 0 cpplist = [] def get_reflected_files(where, lst): for f in lst: full = os.path.join(where,f) if f.endswith(".h"): content = open(full).read() tkbms = util.extract_tkbms(content) valid_tkbms = lambda x : (not tkbms.has_key(x) or tkbms[x] != "NONE") if valid_tkbms("platform") and valid_tkbms("product") and util.hasReflectionDeclaration(content): yield full elif f.endswith(".hkclass") and not os.path.exists(full.replace(".hkclass",".h")): yield full reflected_files = [] for dirname, subdirs, files in os.walk(where): files.sort() subdirs.sort() reflected_files.extend( get_reflected_files(dirname,files) ) manifest = hkcToDom.Document("Manifest") manifest.file = hkcToDom.File() manifest.file.visibility = "PUBLIC" for reflected in reflected_files: nfile += 1 if reflected.endswith(".h"): dom = headerToDom.headerToDom(reflected) if os.path.exists( reflected+"kclass" ): override = hkcToDom.hkcToDom( reflected+"kclass" ) mergeBind.mergeBind(dom.file, override.file, dom.name) elif reflected.endswith(".hkclass"): dom = hkcToDom.hkcToDom( reflected ) else: assert 0 manifest.file.mergeWith(dom.file) cpplist.append( domToClass.domToClass(manifest, collectAll=True)) if options.output: outfile = open(options.output,"w") else: outfile = None cpptxt = "\n".join(cpplist) symbols = [ s for s in re.findall(r"^hkClass\s+([^\(]+)\s*\($(?m)", cpptxt) ] symbols.sort() cpptxt = re.sub("\s*//.*(?m)","", cpptxt) cpptxt = re.sub("^extern\s+hkClass\s+.*(?m)","", cpptxt) cpptxt = re.sub("\n\s*\n","\n", cpptxt) namespace = "hkHavok%sClasses" % options.version_suffix.replace("_","") versionNumString = ".".join( [ s for s in options.version_suffix.replace("_","")[:3] ] ) versionStage = options.version_suffix.replace("_","")[3:] if versionStage is not "": versionNumString = "-".join( [versionNumString, versionStage] ) listname = "Classes" print >>outfile, _tkbms % ("ALL","ALL","PUBLIC",namespace,versionNumString,int(options.class_version)) print >>outfile, "\n".join( ["\textern hkClass %s;"%s.replace("(",";") for s in symbols]) print >>outfile, cpptxt.replace("\n","\n\t")[:-1] print >>outfile, "\tstatic hkClass* const %s[] =\n\t{\n%s\n\t\tHK_NULL\n\t}; " % ( listname, "\n".join(["\t\t&%s,"%s for s in symbols] ) ) print >>outfile, "\tconst hkStaticClassNameRegistry hkHavokDefaultClassRegistry\n\t(\n\t\tClasses,\n\t\tClassVersion,\n\t\tVersionString\n\t);" print >>outfile, "".join( ["\n} // namespace ", namespace, "\n" ] ) if not options.quiet: print >>sys.stderr, "DONE", where, nfile, "files processed"
def processDir(where, options): nfile = 0 cpplist = [] def get_reflected_files(where, lst): for f in lst: full = os.path.join(where, f) if f.endswith(".h"): content = open(full).read() tkbms = util.extract_tkbms(content) valid_tkbms = lambda x: (not tkbms.has_key(x) or tkbms[x] != "NONE") if valid_tkbms("platform") and valid_tkbms( "product") and util.hasReflectionDeclaration(content): yield full elif f.endswith(".hkclass") and not os.path.exists( full.replace(".hkclass", ".h")): yield full reflected_files = [] for dirname, subdirs, files in os.walk(where): files.sort() subdirs.sort() reflected_files.extend(get_reflected_files(dirname, files)) manifest = hkcToDom.Document("Manifest") manifest.file = hkcToDom.File() manifest.file.visibility = "PUBLIC" for reflected in reflected_files: nfile += 1 if reflected.endswith(".h"): dom = headerToDom.headerToDom(reflected) if os.path.exists(reflected + "kclass"): override = hkcToDom.hkcToDom(reflected + "kclass") mergeBind.mergeBind(dom.file, override.file, dom.name) elif reflected.endswith(".hkclass"): dom = hkcToDom.hkcToDom(reflected) else: assert 0 manifest.file.mergeWith(dom.file) cpplist.append(domToClass.domToClass(manifest, collectAll=True)) if options.output: outfile = open(options.output, "w") else: outfile = None cpptxt = "\n".join(cpplist) symbols = [s for s in re.findall(r"^hkClass\s+([^\(]+)\s*\($(?m)", cpptxt)] symbols.sort() cpptxt = re.sub("\s*//.*(?m)", "", cpptxt) cpptxt = re.sub("^extern\s+hkClass\s+.*(?m)", "", cpptxt) cpptxt = re.sub("\n\s*\n", "\n", cpptxt) namespace = "hkHavok%sClasses" % options.version_suffix.replace("_", "") versionNumString = ".".join( [s for s in options.version_suffix.replace("_", "")[:3]]) versionStage = options.version_suffix.replace("_", "")[3:] if versionStage is not "": versionNumString = "-".join([versionNumString, versionStage]) listname = "Classes" print >> outfile, _tkbms % ("ALL", "ALL", "PUBLIC", namespace, versionNumString, int(options.class_version)) print >> outfile, "\n".join( ["\textern hkClass %s;" % s.replace("(", ";") for s in symbols]) print >> outfile, cpptxt.replace("\n", "\n\t")[:-1] print >> outfile, "\tstatic hkClass* const %s[] =\n\t{\n%s\n\t\tHK_NULL\n\t}; " % ( listname, "\n".join(["\t\t&%s," % s for s in symbols])) print >> outfile, "\tconst hkStaticClassNameRegistry hkHavokDefaultClassRegistry\n\t(\n\t\tClasses,\n\t\tClassVersion,\n\t\tVersionString\n\t);" print >> outfile, "".join(["\n} // namespace ", namespace, "\n"]) if not options.quiet: print >> sys.stderr, "DONE", where, nfile, "files processed"