def extract_consts(gecko_dir, filenames): import xpidl # The directories where the base IDLs are idl_xpcom_base_dir = os.path.join(gecko_dir, 'xpcom', 'base') idl_dom_base_dir = os.path.join(gecko_dir, 'dom', 'interfaces', 'base') # By default also include the directories the given IDLs are in idl_dirs = [os.path.dirname(ff) for ff in filenames] + [idl_xpcom_base_dir, idl_dom_base_dir] p = xpidl.IDLParser() for f in filenames: idl = p.parse(open(f).read(), filename=f) idl.resolve(idl_dirs, p) for production in idl.productions: if production.kind == 'interface': # Print interfaces even if they don't have any const members, # as they might still be of use as empty containers to get # things working print("const {} = {{".format(production.name)) for member in production.members: if member.kind == 'const': print(" {}: {},".format(member.name, member.value(idl))) print("};")
def update_uuids(self, path, interfaces): import os import xpidl from mozpack.files import FileFinder import mozpack.path from tempfile import mkdtemp finder = FileFinder(path, find_executables=False) # Avoid creating xpidllex and xpidlyacc in the current directory. tmpdir = mkdtemp() try: parser = xpidl.IDLParser(outputdir=tmpdir) registry = InterfaceRegistry() for p, f in finder.find('**/*.idl'): p = mozpack.path.join(path, p) try: content = f.open().read() idl = parser.parse(content, filename=p) except Exception: continue for prod in idl.productions: if isinstance(prod, xpidl.Interface): registry.add(Interface(p, prod)) finally: import shutil shutil.rmtree(tmpdir) updates = IDLUpdater(registry) for interface in interfaces: updates.add(interface) updates.update()
def main(): from argparse import ArgumentParser o = ArgumentParser() o.add_argument('-I', action='append', dest='incdirs', default=['.'], help="Directory to search for imported files") o.add_argument('config', help='Config file to load') o.add_argument('header_output', metavar='FILE', help="Quick stub header output file") o.add_argument('stub_output', metavar='FILE', help="C++ source output file") o.add_argument('makedepend_output', metavar='FILE', help="gnumake dependencies output file") global options options = o.parse_args() # Instantiate the parser. global p p = xpidl.IDLParser() conf = readConfigFile(options.config) with FileAvoidWrite(options.header_output) as fh: idl_paths = print_header_file(fh, conf) with FileAvoidWrite(options.stub_output) as fh: idl_paths |= print_cpp_file(fh, conf) with FileAvoidWrite(options.makedepend_output) as fh: write_dep_makefile(fh, options.stub_output, idl_paths)
def main(): from optparse import OptionParser o = OptionParser(usage="usage: %prog [options] configfile") o.add_option('-I', action='append', dest='incdirs', default=['.'], help="Directory to search for imported files") o.add_option('-o', "--stub-output", type='string', dest='stub_output', default=None, help="C++ source output file", metavar="FILE") o.add_option('--header-output', type='string', default=None, help="Quick stub header output file", metavar="FILE") o.add_option('--makedepend-output', type='string', default=None, help="gnumake dependencies output file", metavar="FILE") o.add_option('--cachedir', dest='cachedir', default=None, help="Directory in which to cache lex/parse tables.") global options (options, filenames) = o.parse_args() if len(filenames) != 1: o.error("Exactly one config filename is needed.") filename = filenames[0] if options.cachedir is not None: if not os.path.isdir(options.cachedir): os.mkdir(options.cachedir) sys.path.append(options.cachedir) # Instantiate the parser. global p p = xpidl.IDLParser(outputdir=options.cachedir) conf = readConfigFile(filename) if options.stub_output is not None: makeutils.targets.append(options.stub_output) outfd = open(options.stub_output, 'w') print_cpp_file(outfd, conf) outfd.close() if options.makedepend_output is not None: makeutils.writeMakeDependOutput(options.makedepend_output) if options.header_output is not None: outfd = open(options.header_output, 'w') print_header_file(outfd, conf) outfd.close()
def main(outputfile): cachedir = os.path.dirname(outputfile.name if outputfile else '') or '.' if not os.path.isdir(cachedir): os.mkdir(cachedir) sys.path.append(cachedir) # Delete the lex/yacc files. Ply is too stupid to regenerate them # properly for fileglobs in [os.path.join(cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"]]: for filename in glob.glob(fileglobs): os.remove(filename) # Instantiate the parser. xpidl.IDLParser(outputdir=cachedir)
def main(argv=None): import argparse parser = argparse.ArgumentParser() parser.add_argument('input', help='idl input file') parser.add_argument('-I', action='append', dest='incdirs', default=[], help="Directory to search for imported files") parser.add_argument('--cachedir', dest='cachedir', default='.', help="Directory in which to cache lex/parse tables.") parser.add_argument('-o', dest='outfile', default=None, help="Output file (default is stdout)") parser.add_argument('-d', dest='depfile', default=None, help="Generate a make dependency file") parser.add_argument('--regen', action='store_true', dest='regen', default=False, help="Regenerate IDL Parser cache") args = parser.parse_args(argv) cachedir = args.cachedir if not os.path.isdir(cachedir): os.mkdir(cachedir) sys.path.append(cachedir) # Delete the lex/yacc files. Ply is too stupid to regenerate them # properly if args.regen: for fileglobs in [os.path.join(args.cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"]]: for filename in glob.glob(fileglobs): os.remove(filename) if args.outfile: outfd = open(args.outfile,'w') else: outfd = sys.stdout inputfile = args.input p = xpidl.IDLParser(outputdir=cachedir) idl = p.parse(open(inputfile).read(), filename=inputfile) idl.resolve(args.incdirs, p) print_header(idl, outfd, inputfile) if args.depfile is not None: depfd = open(args.depfile, 'w') deps = [dep.replace('\\', '/') for dep in idl.deps] print("%s: %s" % (args.outfile, " ".join(deps)), file=depfd)
o.add_option('--webidltarget', dest='webidltarget', default=None, help="Directory in which to store generated WebIDL files.") (options, filenames) = o.parse_args() if len(filenames) != 1: o.error("Exactly one config filename is needed.") filename = filenames[0] if options.cachedir is not None: if not os.path.isdir(options.cachedir): os.mkdir(options.cachedir) sys.path.append(options.cachedir) # Instantiate the parser. p = xpidl.IDLParser(outputdir=options.cachedir) conf = readConfigFile(filename) if options.header_output is not None: outfd = open(options.header_output, 'w') print_header_file(outfd, conf) outfd.close() if options.class_declarations is not None: outfd = open(options.class_declarations, 'w') print_classes_file(outfd, conf) outfd.close() if options.stub_output is not None: makeutils.targets.append(options.stub_output) outfd = open(options.stub_output, 'w') print_cpp_file(outfd, conf)
analysis = read_cpp_analysis(fname) linebreaks = [] lines = text.split('\n') cur = 0 for l in lines: cur += len(l) + 1 linebreaks.append(cur) if analysis: # compatibility before and after bug 1633156 import inspect initMethod = [ obj for (name, obj) in inspect.getmembers(xpidl.IDLParser) if name == '__init__' ][0] if 'outputdir' in inspect.getargspec(initMethod).args: p = xpidl.IDLParser(outputdir='/tmp') else: p = xpidl.IDLParser() try: r = p.parse(text, filename=fname) except xpidl.IDLError as e: print('Syntax error in IDL', fname, file=sys.stderr) raise e sys.exit(1) for p in r.productions: if isinstance(p, xpidl.Interface): handle_interface(analysis.get(p.name, {}), p)
# The xpidl parser is not incorporated in the in-tree virtualenv. xpidl_dir = mozpath.join(buildconfig.topsrcdir, 'xpcom', 'idl-parser', 'xpidl') xpidl_cachedir = mozpath.join(buildconfig.topobjdir, 'xpcom', 'idl-parser', 'xpidl') sys.path.extend([xpidl_dir, xpidl_cachedir]) import xpidl # Load the webidl configuration file. glbl = {} execfile( mozpath.join(buildconfig.topsrcdir, 'dom', 'bindings', 'Bindings.conf'), glbl) webidlconfig = glbl['DOMInterfaces'] # Instantiate the parser. p = xpidl.IDLParser() def findIDL(includePath, interfaceFileName): for d in includePath: path = mozpath.join(d, interfaceFileName) if os.path.exists(path): return path raise BaseException("No IDL file found for interface %s " "in include path %r" % (interfaceFileName, includePath)) def loadEventIDL(parser, includePath, eventname): eventidl = ("nsIAccessible%s.idl" % eventname) idlFile = findIDL(includePath, eventidl)
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: outfd = sys.stdout closeoutfd = False p = xpidl.IDLParser(outputdir=options.cachedir) idl = p.parse(open(file).read(), filename=file)
def completeConfiguration(conf, includePath, cachedir): # Now read IDL files to connect the information in the config file to # actual XPCOM interfaces, methods, and attributes. interfaces = [] interfacesByName = {} parser = xpidl.IDLParser(cachedir) def getInterface(interfaceName, errorLoc): iface = interfacesByName.get(interfaceName) if iface is None: idlFile = findIDL(conf.includePath, conf.irregularFilenames, interfaceName) idl = loadIDL(parser, conf.includePath, idlFile) if not idl.hasName(interfaceName): raise UserError("The interface %s was not found " "in the idl file %r." % (interfaceName, idlFile)) iface = idl.getName(interfaceName, errorLoc) if not iface.attributes.scriptable: raise UserError("Interface %s is not scriptable. " "IDL file: %r." % (interfaceName, idlFile)) iface.stubMembers = [] interfaces.append(iface) interfacesByName[interfaceName] = iface return iface stubbedInterfaces = [] for clazz in conf.list_classes.itervalues(): interfaceName = 'nsIDOM' + clazz.name iface = getInterface(interfaceName, errorLoc='looking for %r' % clazz.name) for member in iface.members: if member.kind in ('method', 'attribute') and not member.noscript: #addStubMember(iface.name + '.' + member.name, member) clazz.members.add(member) # Stub all scriptable members of this interface. while True: if iface not in stubbedInterfaces: stubbedInterfaces.append(iface) if not clazz.indexGetter and iface.ops['index']['getter']: clazz.indexGetter = iface.ops['index']['getter'] if not clazz.indexSetter and iface.ops['index']['setter']: clazz.indexSetter = iface.ops['index']['setter'] if not clazz.nameGetter and iface.ops['name']['getter']: clazz.nameGetter = iface.ops['name']['getter'] if not clazz.nameSetter and iface.ops['name']['setter']: clazz.nameSetter = iface.ops['name']['setter'] if not clazz.stringifier and iface.ops['stringifier']: clazz.stringifier = iface.ops['stringifier'] interfaceName = conf.customInheritance.get(iface.name, iface.base) iface = getInterface(interfaceName, errorLoc='looking for %r' % clazz.name) if iface.name == 'nsISupports': break assert iface.name.startswith( 'nsIDOM') and not iface.name.startswith('nsIDOMNS') clazz.base = iface.name[6:] # For now we only support base classes that are real DOM # list classes assert clazz.base in conf.list_classes if not conf.list_classes[clazz.base].isBase: conf.list_classes[clazz.base].isBase = True conf.derivedClasses[clazz.base] = [] conf.derivedClasses[clazz.base].append(clazz.name) # Now go through and check all the interfaces' members for iface in stubbedInterfaces: for member in iface.stubMembers: checkStubMember(member) return interfaces
def setUp(self): self.p = xpidl.IDLParser()
def main(): from optparse import OptionParser o = OptionParser() 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[0] if args else None if options.cachedir is not None: if not os.path.isdir(options.cachedir): os.mkdir(options.cachedir) sys.path.append(options.cachedir) # The only thing special about a regen is that there are no input files. if options.regen: if options.cachedir is None: print >> sys.stderr, "--regen useless without --cachedir" # Delete the lex/yacc files. Ply is too stupid to regenerate them # properly for fileglobs in [ os.path.join(options.cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"] ]: for filename in glob.glob(fileglobs): os.remove(filename) # Instantiate the parser. p = xpidl.IDLParser(outputdir=options.cachedir) if options.regen: 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: outfd = sys.stdout closeoutfd = False idl = p.parse(open(file).read(), filename=file) idl.resolve(options.incdirs, p) print_header(idl, outfd, file) if closeoutfd: outfd.close() if options.depfile is not None: dirname = os.path.dirname(options.depfile) if dirname: try: os.makedirs(dirname) except: pass depfd = open(options.depfile, 'w') deps = [dep.replace('\\', '/') for dep in idl.deps] print >> depfd, "%s: %s" % (options.outfile, " ".join(deps)) for dep in deps: print >> depfd, "%s:" % dep
def __init__(self, sources): self.parser = xpidl.IDLParser('cache') self.sources = sources