Bug 1444991 - Part 1: Read webidl's Bindings.conf, and pass it into xpidl, r=mccr8
authorNika Layzell <nika@thelayzells.com>
Fri, 06 Apr 2018 18:20:49 -0400
changeset 467733 40a027a1f2cf5318f96e97cef8a5a7a388cb0a20
parent 467732 90e79480ebc68009799722ec9882df00f3ec986f
child 467734 c59b5be67ba225f8864219c8b8d589446d1d8459
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1444991
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1444991 - Part 1: Read webidl's Bindings.conf, and pass it into xpidl, r=mccr8 This information is read in order to handle correctly selecting the native type and header files for WebIDL types.
accessible/xpcom/AccEventGen.py
config/makefiles/xpidl/Makefile.in
python/mozbuild/mozbuild/action/xpidl-process.py
xpcom/idl-parser/xpidl/runtests.py
xpcom/idl-parser/xpidl/xpidl.py
--- a/accessible/xpcom/AccEventGen.py
+++ b/accessible/xpcom/AccEventGen.py
@@ -13,33 +13,40 @@ import mozpack.path as mozpath
 # 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)
     idl = p.parse(open(idlFile).read(), idlFile)
-    idl.resolve(includePath, p)
+    idl.resolve(includePath, p, webidlconfig)
     return idl, idlFile
 
 class Configuration:
     def __init__(self, filename):
         config = {}
         execfile(filename, config)
         self.simple_events = config.get('simple_events', [])
 
--- a/config/makefiles/xpidl/Makefile.in
+++ b/config/makefiles/xpidl/Makefile.in
@@ -35,16 +35,17 @@ code_gen_py := $(topsrcdir)/xpcom/reflec
 code_gen_deps := $(topsrcdir)/xpcom/reflect/xptinfo/perfecthash.py
 
 # TODO we should use py_action, but that would require extra directories to be
 # in the virtualenv.
 %.xpt:
 	$(REPORT_BUILD)
 	$(PYTHON_PATH) $(PLY_INCLUDE) -I$(topsrcdir)/xpcom/idl-parser -I$(DEPTH)/xpcom/idl-parser/xpidl \
 		$(process_py) --cache-dir $(DEPTH)/xpcom/idl-parser/xpidl --depsdir $(idl_deps_dir) \
+		--bindings-conf $(topsrcdir)/dom/bindings/Bindings.conf \
 		$(dist_idl_dir) $(dist_include_dir) $(dist_xpcrs_dir) $(@D) \
 		$(basename $(notdir $@)) $($(basename $(notdir $@))_deps)
 # When some IDL is added or removed, if the actual IDL file was already, or
 # still is, in the tree, simple dependencies can't detect that the XPT needs
 # to be rebuilt.
 # Add the current value of $($(xpidl_module)_deps) in the depend file, such that
 # we can later check if the value has changed since last build, which will
 # indicate whether IDLs were added or removed.
--- a/python/mozbuild/mozbuild/action/xpidl-process.py
+++ b/python/mozbuild/mozbuild/action/xpidl-process.py
@@ -22,34 +22,38 @@ from xpidl.rust import print_rust_bindin
 from xpidl.rust_macros import print_rust_macros_bindings
 from xpidl.xpidl import IDLParser
 
 from mozbuild.makeutil import Makefile
 from mozbuild.pythonutil import iter_modules_in_path
 from mozbuild.util import FileAvoidWrite
 
 
-def process(input_dir, inc_paths, cache_dir, header_dir, xpcrs_dir,
-            xpt_dir, deps_dir, module, stems):
+def process(input_dir, inc_paths, bindings_conf, cache_dir, header_dir,
+            xpcrs_dir, xpt_dir, deps_dir, module, stems):
     p = IDLParser(outputdir=cache_dir)
 
     xpts = []
     mk = Makefile()
     rule = mk.create_rule()
 
+    glbl = {}
+    execfile(bindings_conf, glbl)
+    webidlconfig = glbl['DOMInterfaces']
+
     # Write out dependencies for Python modules we import. If this list isn't
     # up to date, we will not re-process XPIDL files if the processor changes.
     rule.add_dependencies(iter_modules_in_path(topsrcdir))
 
     for stem in stems:
         path = os.path.join(input_dir, '%s.idl' % stem)
         idl_data = open(path).read()
 
         idl = p.parse(idl_data, filename=path)
-        idl.resolve([input_dir] + inc_paths, p)
+        idl.resolve([input_dir] + inc_paths, p, webidlconfig)
 
         header_path = os.path.join(header_dir, '%s.h' % stem)
         rs_rt_path = os.path.join(xpcrs_dir, 'rt', '%s.rs' % stem)
         rs_bt_path = os.path.join(xpcrs_dir, 'bt', '%s.rs' % stem)
 
         xpts.append(jsonxpt.build_typelib(idl))
 
         rule.add_dependencies(idl.deps)
@@ -75,29 +79,32 @@ def process(input_dir, inc_paths, cache_
 
 
 def main(argv):
     parser = argparse.ArgumentParser()
     parser.add_argument('--cache-dir',
         help='Directory in which to find or write cached lexer data.')
     parser.add_argument('--depsdir',
         help='Directory in which to write dependency files.')
+    parser.add_argument('--bindings-conf',
+        help='Path to the WebIDL binding configuration file.')
     parser.add_argument('inputdir',
         help='Directory in which to find source .idl files.')
     parser.add_argument('headerdir',
         help='Directory in which to write header files.')
     parser.add_argument('xpcrsdir',
         help='Directory in which to write rust xpcom binding files.')
     parser.add_argument('xptdir',
         help='Directory in which to write xpt file.')
     parser.add_argument('module',
         help='Final module name to use for linked output xpt file.')
     parser.add_argument('idls', nargs='+',
         help='Source .idl file(s). Specified as stems only.')
     parser.add_argument('-I', dest='incpath', action='append', default=[],
         help='Extra directories where to look for included .idl files.')
 
     args = parser.parse_args(argv)
-    process(args.inputdir, args.incpath, args.cache_dir, args.headerdir,
-        args.xpcrsdir, args.xptdir, args.depsdir, args.module, args.idls)
+    process(args.inputdir, args.incpath, args.bindings_conf, args.cache_dir,
+        args.headerdir, args.xpcrsdir, args.xptdir, args.depsdir, args.module,
+        args.idls)
 
 if __name__ == '__main__':
     main(sys.argv[1:])
--- a/xpcom/idl-parser/xpidl/runtests.py
+++ b/xpcom/idl-parser/xpidl/runtests.py
@@ -60,17 +60,17 @@ void bar();
         self.assertTrue(isinstance(m, xpidl.Method))
         self.assertEqual("bar", m.name)
         self.assertEqual("void", m.type)
 
     def testMethodParams(self):
         i = self.p.parse("""[uuid(abc)] interface foo {
 long bar(in long a, in float b, [array] in long c);
 };""", filename='f')
-        i.resolve([], self.p)
+        i.resolve([], self.p, {})
         self.assertTrue(isinstance(i, xpidl.IDL))
         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
         iface = i.productions[0]
         m = iface.members[0]
         self.assertTrue(isinstance(m, xpidl.Method))
         self.assertEqual("bar", m.name)
         self.assertEqual("long", m.type)
         self.assertEqual(3, len(m.params))
--- a/xpcom/idl-parser/xpidl/xpidl.py
+++ b/xpcom/idl-parser/xpidl/xpidl.py
@@ -295,17 +295,17 @@ class Include(object):
             for dir in parent.incdirs:
                 yield os.path.join(dir, self.filename)
 
         for file in incfiles():
             if not os.path.exists(file):
                 continue
 
             self.IDL = parent.parser.parse(open(file).read(), filename=file)
-            self.IDL.resolve(parent.incdirs, parent.parser)
+            self.IDL.resolve(parent.incdirs, parent.parser, parent.webidlconfig)
             for type in self.IDL.getNames():
                 parent.setName(type)
             parent.deps.extend(self.IDL.deps)
             return
 
         raise IDLError("File '%s' not found" % self.filename, self.location)
 
 
@@ -327,20 +327,21 @@ class IDL(object):
         return id in self.namemap
 
     def getNames(self):
         return iter(self.namemap)
 
     def __str__(self):
         return "".join([str(p) for p in self.productions])
 
-    def resolve(self, incdirs, parser):
+    def resolve(self, incdirs, parser, webidlconfig):
         self.namemap = NameMap()
         self.incdirs = incdirs
         self.parser = parser
+        self.webidlconfig = webidlconfig
         for p in self.productions:
             p.resolve(self)
 
     def includes(self):
         for p in self.productions:
             if p.kind == 'include':
                 yield p