Example #1
0
def findClassesAndLocations(where):
    """Return list of class names and dict of Class.cpp locations for each class"""
    classes = []
    locations = {}

    def appendClasses( fileName, classList, prefix ):
        for c in classList:
            c.name = prefix + c.name
            classes.append( c )
            locations[ c.name ] = fileName
            appendClasses( fileName, c._class, c.name )

    def findCppHeaders(top):
        for dirname, subdirs, files in os.walk(top):
            if not re.search('\\bUnitTest\\b', dirname):
                for f in  [ f for f in files if f.endswith(".h") ]:
                    yield os.path.join(dirname, f)

    for fileName in findCppHeaders(where):
        if util.hasReflectionDeclaration( open(fileName).read() ):
            dom = headerToDom.headerToDom( fileName )
            if dom.file.product != "NONE" and dom.file.platform != "NONE":
                filename = dom.file.destinationFilename(dom.localfilename, "Class.cpp")
                appendClasses( filename, dom.file._class, '' )                    
        
    return classes, locations
Example #2
0
 def processfile(inputfilename, debug=0):
     """Convenience function to create a class from an xml class file.
     """
     if inputfilename.endswith(".h"):
         dom = headerToDom.headerToDom(inputfilename)
     else:
         dom = hkcToDom.hkcToDom(inputfilename)
     return domToClass(dom, debug)
Example #3
0
 def processfile(inputfilename, debug=0):
     """Convenience function to create a class from an xml class file.
     """
     if inputfilename.endswith(".h"):
         dom = headerToDom.headerToDom(inputfilename)
     else:
         dom = hkcToDom.hkcToDom(inputfilename)
     return domToManagedClass(dom, debug)
 def processfile(inputfilename, debug=0):
     """Return the text of a c++ header file from a given input file.
     """
     if inputfilename.endswith(".h"):
         dom = headerToDom.headerToDom(inputfilename)
     else:
         dom = hkcToDom.hkcToDom(inputfilename)
     return domToHeader(dom, debug)
Example #5
0
 def processfile(inputfilename, debug=0):
     """Return the text of a c++ header file from a given input file.
     """
     if inputfilename.endswith(".h"):
         dom = headerToDom.headerToDom(inputfilename)
     else:
         dom = hkcToDom.hkcToDom(inputfilename)
     return domToHeader(dom, debug)
Example #6
0
def main():
    import hkcToDom
    import headerToDom
    
    master = headerToDom.headerToDom( r'E:\DEV\serialize\havok\source\hkbase\class\hkClass.h' )
    edited = hkcToDom.hkcToDom( "edited.hkclass" )

    print >>open("master.hkclass","w"), bindingToXml.bindingToXml("file",master.file)
    rejectFileName = "masterXml.rej"
    print >>open(rejectFileName,"w"), '\n'.join(mergeBind(master.file, edited.file, master.name))
    print >>open("merged.hkclass","w"), bindingToXml.bindingToXml("file",master.file)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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"
Example #10
0
def processDir(where, options):
    if options.output:
        fileNamePrefix = options.output
    else:
        fileNamePrefix = ""
    managedClassesHeaderFile = fileNamePrefix+"Classes.h"
    managedClassesImplFile = fileNamePrefix+"Classes.cpp"
    managedClassesHeader = domToManagedClass.FormatedSourceCode()
    managedClassesImpl = domToManagedClass.FormatedSourceCode()

    customLines = []
    genManagedHeaderStart( customLines, (options.manifest=="2") )
    domToManagedClass.genFileHeadlines( managedClassesHeader, customLines=customLines )
    if options.manifest=="2":
        ### custom manifest file, so include header for the Havok wrappers
        managedClassesHeader.append("#include <HavokAssembly/hkHavokManagedClasses.h>")
    
    domToManagedClass.genFileHeadlines(managedClassesImpl)
    managedClassesImpl.append("#include <HavokAssembly/%s>" % getName(managedClassesHeaderFile))
    
    nfile = 0
    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 = []
    excludeDirs = []
    if options.exclude:
        excludeDirs = options.exclude
    for dirname, subdirs, files in os.walk(where):
        files.sort()
        subdirs.sort()
        #print dirname
        if "CVS" in subdirs:
            subdirs.remove("CVS")
        if "UnitTest" in subdirs:
            subdirs.remove("UnitTest")
        if dirname in excludeDirs:
            del subdirs[:]
        else:
            reflected_files.extend( get_reflected_files(dirname,files) )

    fatDom = hkcToDom.Document(fileNamePrefix)
    fatDom.file = hkcToDom.File()
    fatDom.file.product = ""
    fatDom.file.platform = ".NET"
    fatDom.file.visibility = "PUBLIC"
    fatDom.file.includeheaders = ""

    def updatePath(filepath):
        updatedPath = filepath.replace("\\","/")
        if options.manifest=="2":
            updatedPath = "/".join( [ p for p in updatedPath.replace(where.replace("\\","/"),"").split("/") if p ] )
        return updatedPath

    def mergeDomDocs(domDocTo, domDocFrom):
        # merge
        domDocTo.file.mergeWith(domDocFrom.file)
        domDocTo.file.includeheaders += "#include <%s>\n" % updatePath(domDocFrom.localfilename)

    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
        ### collect all doms info
        mergeDomDocs(fatDom, dom)

    if len(fatDom.file.includeheaders):
        headerfiles = [x for x in fatDom.file.includeheaders.split("\n") if not x.endswith(".inl>")]
        if options.manifest!="2":
            headerfiles.sort()
        cleanList = [""]
        for line in headerfiles:
            if line != cleanList[-1]:
                cleanList.append(line)
        headerfiles = "\n".join(cleanList[1:])
        managedClassesHeader.append("\n//\n// All reflected class headers\n//")
        managedClassesHeader.append("#pragma unmanaged")
        managedClassesHeader.append(headerfiles)
        managedClassesHeader.append("#pragma managed")

    managedClassDecl, managedClassDef = domToManagedClass.domToManagedClass(fatDom, collectAll=True)
    
    managedClassesHeader.append("\n".join(managedClassDecl.replace("\t","").split("/n")))
    managedClassesImpl.append("\n".join(managedClassDef.replace("\t","").split("/n")))

    genManagedHeaderEnd( managedClassesHeader, (options.manifest=="2") )
    
    updatedClassesHeaderContent = "\n".join(managedClassesHeader.lines)
    updatedClassesImplContent = "\n".join(managedClassesImpl.lines)
    if options.output:
        ### we open two files for output
        writeIfDifferent(updatedClassesHeaderContent, managedClassesHeaderFile, False)
        writeIfDifferent(updatedClassesImplContent, managedClassesImplFile, False)
    else:
        print >>sys.stdout, updatedClassesHeaderContent
        print >>sys.stdout, updatedClassesImplContent

    if not options.quiet:
        print >>sys.stderr, "DONE", where, nfile, "files processed"
Example #11
0
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"