diff options
author | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 22:25:12 +0000 |
---|---|---|
committer | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 22:25:12 +0000 |
commit | 782c809f5c3f88edc1ecdb83d5d6406d7beb9801 (patch) | |
tree | b869f3c1f23643cc1fbd2a44458e53fa74091090 /ppapi/generators | |
parent | e99ee9cd37864004d9f98f3880405fc651f29b58 (diff) | |
download | chromium_src-782c809f5c3f88edc1ecdb83d5d6406d7beb9801.zip chromium_src-782c809f5c3f88edc1ecdb83d5d6406d7beb9801.tar.gz chromium_src-782c809f5c3f88edc1ecdb83d5d6406d7beb9801.tar.bz2 |
Fix version discovery for Interfaces, Structs
Now that we are looking at including structures and interfaces pointers in the
version graph, we need to fix remove some simplifying assumptions, and correct
the versioning calculation.
Includes minor cleanup to how we call 'Main' to make it more compliant as
well as catching exceptions so that we show the commandline options that caused
that exception.
BUG=154127,158980
TBR=sehr@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11263062
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165526 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/generators')
-rwxr-xr-x | ppapi/generators/generator.py | 53 | ||||
-rwxr-xr-x | ppapi/generators/idl_node.py | 63 |
2 files changed, 79 insertions, 37 deletions
diff --git a/ppapi/generators/generator.py b/ppapi/generators/generator.py index b1ab0ee..4511cd9 100755 --- a/ppapi/generators/generator.py +++ b/ppapi/generators/generator.py @@ -5,6 +5,7 @@ import os import sys +import traceback # Note: some of these files are imported to register cmdline options. from idl_generator import Generator @@ -15,33 +16,41 @@ from idl_c_header import HGen from idl_gen_pnacl import PnaclGen -def Main(): - args = sys.argv[1:] +def Main(args): # If no arguments are provided, assume we are trying to rebuild the # C headers with warnings off. - if not args: - args = [ - '--wnone', '--cgen', '--range=start,end', - '--pnacl', '--pnaclshim', - '../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c', - ] - current_dir = os.path.abspath(os.getcwd()) - script_dir = os.path.abspath(os.path.dirname(__file__)) - if current_dir != script_dir: - print '\nIncorrect CWD, default run skipped.' - print 'When running with no arguments set CWD to the scripts directory:' - print '\t' + script_dir + '\n' - print 'This ensures correct default paths and behavior.\n' + try: + if not args: + args = [ + '--wnone', '--cgen', '--range=start,end', + '--pnacl', '--pnaclshim', + '../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c', + ] + current_dir = os.path.abspath(os.getcwd()) + script_dir = os.path.abspath(os.path.dirname(__file__)) + if current_dir != script_dir: + print '\nIncorrect CWD, default run skipped.' + print 'When running with no arguments set CWD to the scripts directory:' + print '\t' + script_dir + '\n' + print 'This ensures correct default paths and behavior.\n' + return 1 + + filenames = ParseOptions(args) + ast = ParseFiles(filenames) + if ast.errors: + print 'Found %d errors. Aborting build.\n' % ast.errors return 1 + return Generator.Run(ast) + except SystemExit, ec: + print 'Exiting with %d' % ec.code + sys.exit(ec.code) - filenames = ParseOptions(args) - ast = ParseFiles(filenames) - if ast.errors: - print 'Found %d errors. Aborting build.\n' % ast.errors - return 1 - return Generator.Run(ast) + except: + typeinfo, value, tb = sys.exc_info() + traceback.print_exception(typeinfo, value, tb) + print 'Called with: ' + ' '.join(sys.argv) if __name__ == '__main__': - sys.exit(Main()) + sys.exit(Main(sys.argv[1:])) diff --git a/ppapi/generators/idl_node.py b/ppapi/generators/idl_node.py index 34c4d22..88d9445 100755 --- a/ppapi/generators/idl_node.py +++ b/ppapi/generators/idl_node.py @@ -39,7 +39,6 @@ class IDLAttribute(object): def __str__(self): return '%s=%s' % (self.name, self.value) - # # IDLNode # @@ -245,15 +244,37 @@ class IDLNode(IDLRelease): self.hashes[release] = hashval return hashval.hexdigest() - def GetDeps(self, release): + def GetDeps(self, release, visited=None): + visited = visited or set() + + # If this release is not valid for this object, then done. + if not self.IsRelease(release) or self.IsA('Comment', 'Copyright'): + return set([]) + + # If we have cached the info for this release, return the cached value deps = self.deps.get(release, None) - if deps is None: - deps = set([self]) - for child in self.GetChildren(): - deps |= child.GetDeps(release) - typeref = self.GetType(release) - if typeref: deps |= typeref.GetDeps(release) - self.deps[release] = deps + if deps is not None: + return deps + + # If we are already visited, then return + if self in visited: + return set([self]) + + # Otherwise, build the dependency list + visited |= set([self]) + deps = set([self]) + + # Get child deps + for child in self.GetChildren(): + deps |= child.GetDeps(release, visited) + visited |= set(deps) + + # Get type deps + typeref = self.GetType(release) + if typeref: + deps |= typeref.GetDeps(release, visited) + + self.deps[release] = deps return deps def GetVersion(self, release): @@ -263,6 +284,10 @@ class IDLNode(IDLRelease): return filenode.release_map.GetVersion(release) def GetUniqueReleases(self, releases): + """Return the unique set of first releases corresponding to input + + Since we are returning the corresponding 'first' version for a + release, we may return a release version prior to the one in the list.""" my_min, my_max = self.GetMinMax(releases) if my_min > releases[-1] or my_max < releases[0]: return [] @@ -271,8 +296,6 @@ class IDLNode(IDLRelease): for rel in releases: remapped = self.first_release[rel] if not remapped: continue - if remapped < releases[0]: - remapped = releases[0] out |= set([remapped]) out = sorted(out) return out @@ -299,7 +322,7 @@ class IDLNode(IDLRelease): return self.releases - def _GetReleaseList(self, releases): + def _GetReleaseList(self, releases, visited=set()): if not self.releases: # If we are unversionable, then return first available release if self.IsA('Comment', 'Copyright', 'Label'): @@ -315,19 +338,29 @@ class IDLNode(IDLRelease): else: my_releases = set([my_min]) - # Files inherit all there releases from items in the file + # Break cycle if we reference ourselves + if self in visited: + return [my_min] + + visited |= set([self]) + + # Files inherit all thier releases from items in the file if self.IsA('AST', 'File'): my_releases = set() + # Visit all children child_releases = set() for child in self.children: - child_releases |= set(child._GetReleaseList(releases)) + child_releases |= set(child._GetReleaseList(releases, visited)) + visited |= set(child_releases) + # Visit my type type_releases = set() if self.typelist: type_list = self.typelist.GetReleases() for typenode in type_list: - type_releases |= set(typenode._GetReleaseList(releases)) + type_releases |= set(typenode._GetReleaseList(releases, visited)) + visited |= set(type_releases) type_release_list = sorted(type_releases) if my_min < type_release_list[0]: |