Bug 678479: Add a --regen argument to header.py and typelib.py to regenerate the IDL parser. r=ted
authorKyle Huey <khuey@kylehuey.com>
Fri, 12 Aug 2011 12:06:46 -0400
changeset 74330 b9854d39643ab27a9fdb938211411536083471be
parent 74329 b021d1f9f57de8db7ea9d27bcf96ed11de3c994a
child 74331 27023581b24ac987d8ccb789b169316addc5fd8a
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersted
bugs678479
milestone8.0a1
Bug 678479: Add a --regen argument to header.py and typelib.py to regenerate the IDL parser. r=ted
xpcom/idl-parser/header.py
xpcom/idl-parser/typelib.py
xpcom/idl-parser/xpidl.py
--- a/xpcom/idl-parser/header.py
+++ b/xpcom/idl-parser/header.py
@@ -478,24 +478,34 @@ if __name__ == '__main__':
     o.add_option('-I', action='append', dest='incdirs', default=['.'],
                  help="Directory to search for imported files")
     o.add_option('--cachedir', dest='cachedir', default=None,
                  help="Directory in which to cache lex/parse tables.")
     o.add_option('-o', dest='outfile', default=None,
                  help="Output file (default is stdout)")
     o.add_option('-d', dest='depfile', default=None,
                  help="Generate a make dependency file")
+    o.add_option('--regen', action='store_true', dest='regen', default=False,
+                 help="Regenerate IDL Parser cache")
     options, args = o.parse_args()
     file, = args
 
     if options.cachedir is not None:
         if not os.path.isdir(options.cachedir):
             os.mkdir(options.cachedir)
         sys.path.append(options.cachedir)
 
+    if options.regen:
+        if options.cachedir is None:
+            print >>sys.stderr, "--regen requires --cachedir"
+            sys.exit(1)
+
+        p = xpidl.IDLParser(outputdir=options.cachedir, regen=True)
+        sys.exit(0)
+
     if options.depfile is not None and options.outfile is None:
         print >>sys.stderr, "-d requires -o"
         sys.exit(1)
 
     if options.outfile is not None:
         outfd = open(options.outfile, 'w')
         closeoutfd = True
     else:
--- a/xpcom/idl-parser/typelib.py
+++ b/xpcom/idl-parser/typelib.py
@@ -276,24 +276,34 @@ if __name__ == '__main__':
     o.add_option('-I', action='append', dest='incdirs', default=['.'],
                  help="Directory to search for imported files")
     o.add_option('--cachedir', dest='cachedir', default=None,
                  help="Directory in which to cache lex/parse tables.")
     o.add_option('-o', dest='outfile', default=None,
                  help="Output file")
     o.add_option('-d', dest='depfile', default=None,
                  help="Generate a make dependency file")
+    o.add_option('--regen', action='store_true', dest='regen', default=False,
+                 help="Regenerate IDL Parser cache")
     options, args = o.parse_args()
     file, = args
 
     if options.cachedir is not None:
         if not os.path.isdir(options.cachedir):
             os.mkdir(options.cachedir)
         sys.path.append(options.cachedir)
 
+    if options.regen:
+        if options.cachedir is None:
+            print >>sys.stderr, "--regen requires --cachedir"
+            sys.exit(1)
+
+        p = xpidl.IDLParser(outputdir=options.cachedir, regen=True)
+        sys.exit(0)
+
     if options.depfile is not None and options.outfile is None:
         print >>sys.stderr, "-d requires -o"
         sys.exit(1)
 
     if options.outfile is not None:
         outfd = open(options.outfile, 'wb')
         closeoutfd = True
     else:
--- a/xpcom/idl-parser/xpidl.py
+++ b/xpcom/idl-parser/xpidl.py
@@ -1331,27 +1331,27 @@ class IDLParser(object):
         """idlist : IDENTIFIER ',' idlist"""
         p[0] = list(p[3])
         p[0].insert(0, p[1])
 
     def p_error(self, t):
         location = Location(self.lexer, t.lineno, t.lexpos)
         raise IDLError("invalid syntax", location)
 
-    def __init__(self, outputdir=''):
+    def __init__(self, outputdir='', regen=False):
         self._doccomments = []
         self.lexer = lex.lex(object=self,
                              outputdir=outputdir,
                              lextab='xpidllex',
-                             optimize=1)
+                             optimize=0 if regen else 1)
         self.parser = yacc.yacc(module=self,
                                 outputdir=outputdir,
                                 debugfile='xpidl_debug',
                                 tabmodule='xpidlyacc',
-                                optimize=1)
+                                optimize=0 if regen else 1)
 
     def clearComments(self):
         self._doccomments = []
 
     def token(self):
         t = self.lexer.token()
         if t is not None and t.type != 'CDATA':
             t.doccomments = self._doccomments