Update generate scripts for python3
authorEric Werness <ewerness@nvidia.com>
Tue, 20 Nov 2018 17:34:06 +0000 (09:34 -0800)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 9 May 2019 16:00:53 +0000 (12:00 -0400)
Components: Framework

Change-Id: Ia3db51e520ffbab7613f9948f23e6320b2815462
(cherry picked from commit c7ebd5a8c32ae0b16789fc700d62502a5891aeae)

external/vulkancts/scripts/gen_ext_deps.py
external/vulkancts/scripts/gen_framework.py
scripts/build/build.py
scripts/build/common.py
scripts/build/config.py
scripts/build_caselists.py
scripts/khr_util/format.py
scripts/khr_util/registry.py
scripts/khr_util/registry_cache.py
scripts/mustpass.py

index 8b69a97..c643b52 100644 (file)
@@ -66,7 +66,7 @@ def writeInlFile(filename, lines):
 def genExtDepArray(extDepsName, extDepsDict):
        yield 'static const std::pair<const char*, const char*>\t%s[]\t=' % extDepsName
        yield '{'
-       for ext in sorted(extDepsDict.iterkeys()):
+       for ext in sorted(extDepsDict.keys()):
                for dep in extDepsDict[ext]:
                        yield '\tstd::make_pair("%s", "%s"),' % (ext, dep)
        yield '};'
@@ -110,7 +110,7 @@ def genExtDeps(extInfoDict):
        allExtDepsDict[VK_DEV_EXT_DEP_1_0]      = {}
        allExtDepsDict[VK_DEV_EXT_DEP_1_1]      = {}
 
-       for ext, info in extInfoDict.iteritems():
+       for ext, info in extInfoDict.items():
                if info.deps == None:
                        continue
 
index 2a9d889..47e3954 100644 (file)
@@ -266,8 +266,8 @@ class Variable:
                self.arraySize  = arraySize
 
        def contains(self, big, small):
-               for i in xrange(len(big)-len(small)+1):
-                       for j in xrange(len(small)):
+               for i in range(len(big)-len(small)+1):
+                       for j in range(len(small)):
                                if big[i+j] != small[j]:
                                        break
                        else:
@@ -391,7 +391,7 @@ class API:
                self.extensions         = extensions
 
 def readFile (filename):
-       with open(filename, 'rb') as f:
+       with open(filename, 'rt') as f:
                return f.read()
 
 IDENT_PTRN     = r'[a-zA-Z_][a-zA-Z0-9_]*'
index f6f9074..053f550 100644 (file)
@@ -24,8 +24,8 @@ import os
 import sys
 import shutil
 
-from common import *
-from config import *
+from common import *
+from config import *
 
 def initBuildDir (config, generator):
        cfgArgs = []
@@ -51,8 +51,8 @@ def build (config, generator, targets = None):
                try:
                        initBuildDir(config, generator)
                except Exception as e:
-                       print e
-                       print "WARNING: Using existing build directory failed; re-creating build directory"
+                       print(e)
+                       print("WARNING: Using existing build directory failed; re-creating build directory")
                        shutil.rmtree(config.buildDir)
                        initBuildDir(config, generator)
        else:
index c1ea6de..d85f610 100644 (file)
@@ -88,13 +88,13 @@ def execute (args):
                raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
 
 def readFile (filename):
-       f = open(filename, 'rb')
+       f = open(filename, 'rt')
        data = f.read()
        f.close()
        return data
 
 def writeFile (filename, data):
-       f = open(filename, 'wb')
+       f = open(filename, 'wt')
        f.write(data)
        f.close()
 
index f05bc6b..616ef6d 100644 (file)
@@ -25,10 +25,14 @@ import sys
 import copy
 import multiprocessing
 
-from common import which, HostInfo, DEQP_DIR
+from common import which, HostInfo, DEQP_DIR
 
 try:
-       import _winreg
+       if sys.version_info < (3, 0):
+               import _winreg
+       else:
+               import winreg
+               _winreg = winreg
 except:
        _winreg = None
 
index 329eaaa..8b15191 100644 (file)
@@ -158,5 +158,5 @@ if __name__ == "__main__":
                modules = getBuiltModules(buildCfg)
 
        for module in modules:
-               print "Generating test case list for %s" % module.name
+               print("Generating test case list for %s" % module.name)
                genAndCopyCaseList(buildCfg, generator, module, args.dst, args.caseListType)
index 6d0e4f7..0790d8d 100644 (file)
@@ -79,7 +79,7 @@ def readFile (filename):
 
 def writeFileIfChanged (filename, data):
        if not os.path.exists(filename) or readFile(filename) != data:
-               f = open(filename, 'wb')
+               f = open(filename, 'wt')
                f.write(data)
                f.close()
 
@@ -90,7 +90,7 @@ def writeLines (filename, lines):
                text += "\n"
 
        writeFileIfChanged(filename, text)
-       print filename
+       print(filename)
 
 def writeInlFile (filename, header, source):
        writeLines(filename, chain([header], source))
index 7b0e050..0c1bc94 100644 (file)
@@ -170,7 +170,8 @@ class EnumIndex(NameApiIndex):
                name, api, alias = (item.get(attrib) for attrib in ['name', 'api', 'alias'])
                return [(name, api)] + ([(alias, api)] if alias is not None else [])
 
-       def duplicateKey(self, (name, api), item):
+       def duplicateKey(self, nameapipair, item):
+               (name, api) = nameapipair
                if name == item.get('alias'):
                        warnElem(item, "Alias already present: %s", name)
                else:
@@ -190,7 +191,7 @@ class Registry:
                self.apis = {}
                for eFeature in self.features:
                        self.apis.setdefault(eFeature.get('api'), []).append(eFeature)
-               for apiFeatures in self.apis.itervalues():
+               for apiFeatures in self.apis.values():
                        apiFeatures.sort(key=lambda eFeature: eFeature.get('number'))
                self.extensions = ElemNameIndex(eRegistry.findall('extensions/extension'))
                self.element = eRegistry
@@ -337,7 +338,7 @@ def createInterface(registry, spec, api=None):
                        ptype=extractPtype(eProto),
                        group=extractGroup(eProto),
                        alias=extractAlias(eCmd),
-                       params=NameIndex(map(parseParam, eCmd.findall('param'))))
+                       params=NameIndex(list(map(parseParam, eCmd.findall('param')))))
 
        def createGroup(name):
                info('Add group %s', name)
@@ -356,11 +357,11 @@ def createInterface(registry, spec, api=None):
                return NameIndex(sorted(items, key=lambda item: item.location))
 
        groups = NameIndex(createMissing=createGroup, kind="group")
-       types = NameIndex(map(createType, spec.types),
+       types = NameIndex(list(map(createType, spec.types)),
                                          createMissing=createType, kind="type")
-       enums = NameIndex(map(createEnum, spec.enums),
+       enums = NameIndex(list(map(createEnum, spec.enums)),
                                          createMissing=Enum, kind="enum")
-       commands = NameIndex(map(createCommand, spec.commands),
+       commands = NameIndex(list(map(createCommand, spec.commands)),
                                                createMissing=Command, kind="command")
        versions = sorted(spec.versions)
 
index d5ea50e..1c7f2ab 100644 (file)
 
 import os
 import sys
-import urllib2
 import hashlib
 
-import registry
+from . import registry
 
 sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
 
@@ -68,7 +67,7 @@ class RegistrySource:
                return self.filename
 
 def computeChecksum (data):
-       return hashlib.sha256(data).hexdigest()
+       return hashlib.sha256(data.replace('\r','').encode("utf-8")).hexdigest()
 
 def makeSourceUrl (repository, revision, filename):
        return "%s/%s/%s" % (repository, revision, filename)
@@ -85,31 +84,36 @@ def checkoutGit (repository, revision, fullDstPath):
                popWorkingDir()
 
 def checkoutFile (repository, revision, filename, cacheDir):
+       if sys.version_info < (3, 0):
+               from urllib2 import urlopen
+       else:
+               from urllib.request import urlopen
+
        try:
-               req             = urllib2.urlopen(makeSourceUrl(repository, revision, filename))
+               req             = urlopen(makeSourceUrl(repository, revision, filename))
                data    = req.read()
        except IOError:
                fullDstPath = os.path.join(cacheDir, "git")
 
                checkoutGit(repository, revision, fullDstPath)
-               f               = open(os.path.join(fullDstPath, filename), "r")
+               f               = open(os.path.join(fullDstPath, filename), "rt")
                data    = f.read()
                f.close()
        except:
-               print "Unexpected error:", sys.exc_info()[0]
+               print(("Unexpected error:", sys.exc_info()[0]))
 
        return data
 
 def fetchFile (dstPath, repository, revision, filename, checksum, cacheDir):
        def writeFile (filename, data):
-               f = open(filename, 'wb')
+               f = open(filename, 'wt')
                f.write(data)
                f.close()
 
        if not os.path.exists(os.path.dirname(dstPath)):
                os.makedirs(os.path.dirname(dstPath))
 
-       print "Fetching %s/%s@%s" % (repository, filename, revision)
+       print(("Fetching %s/%s@%s" % (repository, filename, revision)))
        data            = checkoutFile(repository, revision, filename, cacheDir)
        gotChecksum     = computeChecksum(data)
 
@@ -120,7 +124,7 @@ def fetchFile (dstPath, repository, revision, filename, checksum, cacheDir):
 
 def checkFile (filename, checksum):
        def readFile (filename):
-               f = open(filename, 'rb')
+               f = open(filename, 'rt')
                data = f.read()
                f.close()
                return data
index 49c6baa..8fc69c7 100644 (file)
@@ -139,7 +139,7 @@ def getCommandLine (config):
 
 def readCaseList (filename):
        cases = []
-       with open(filename, 'rb') as f:
+       with open(filename, 'rt') as f:
                for line in f:
                        if line[:6] == "TEST: ":
                                cases.append(line[6:].strip())
@@ -152,7 +152,7 @@ def getCaseList (buildCfg, generator, module):
 
 def readPatternList (filename):
        ptrns = []
-       with open(filename, 'rb') as f:
+       with open(filename, 'rt') as f:
                for line in f:
                        line = line.strip()
                        if len(line) > 0 and line[0] != '#':
@@ -192,7 +192,7 @@ def applyPatterns (caseList, patterns, filename, op):
                curList = [c for c in curList if c not in matched]
 
        for pattern, reason in errors:
-               print "ERROR: %s: %s" % (reason, pattern)
+               print("ERROR: %s: %s" % (reason, pattern))
 
        if len(errors) > 0:
                die("Found %s invalid patterns while processing file %s" % (len(errors), filename))
@@ -342,7 +342,7 @@ def genAndroidTestXml (mustpass):
        return configElement
 
 def genMustpass (mustpass, moduleCaseLists):
-       print "Generating mustpass '%s'" % mustpass.version
+       print("Generating mustpass '%s'" % mustpass.version)
 
        patternLists = readPatternLists(mustpass)
 
@@ -353,24 +353,24 @@ def genMustpass (mustpass, moduleCaseLists):
                        filtered        = applyFilters(allCasesInPkg, patternLists, config.filters)
                        dstFile         = getDstCaseListPath(mustpass, package, config)
 
-                       print "  Writing deqp caselist: " + dstFile
+                       print("  Writing deqp caselist: " + dstFile)
                        writeFile(dstFile, "\n".join(filtered) + "\n")
 
        specXML                 = genSpecXML(mustpass)
        specFilename    = os.path.join(mustpass.project.path, mustpass.version, "mustpass.xml")
 
-       print "  Writing spec: " + specFilename
-       writeFile(specFilename, prettifyXML(specXML))
+       print("  Writing spec: " + specFilename)
+       writeFile(specFilename, prettifyXML(specXML).decode())
 
        # TODO: Which is the best selector mechanism?
        if (mustpass.version == "master"):
                androidTestXML          = genAndroidTestXml(mustpass)
                androidTestFilename     = os.path.join(mustpass.project.path, "AndroidTest.xml")
 
-               print "  Writing AndroidTest.xml: " + androidTestFilename
-               writeFile(androidTestFilename, prettifyXML(androidTestXML))
+               print("  Writing AndroidTest.xml: " + androidTestFilename)
+               writeFile(androidTestFilename, prettifyXML(androidTestXML).decode())
 
-       print "Done!"
+       print("Done!")
 
 def genMustpassLists (mustpassLists, generator, buildCfg):
        moduleCaseLists = {}