зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1464542: Part 1 - Generate symbolic names for XPT interfaces and add lookup function. r=nika,froydnj
This makes it much simpler for the for the static JS services cache to store and lookup interface IDs for components. Differential Revision: https://phabricator.services.mozilla.com/D81416
This commit is contained in:
Родитель
2808f56f12
Коммит
b18c12677e
|
@ -29,8 +29,11 @@ idl_deps_dir := .deps
|
|||
dist_idl_dir := $(DIST)/idl
|
||||
dist_include_dir := $(DIST)/include
|
||||
dist_xpcrs_dir := $(DIST)/xpcrs
|
||||
stub_file := xptdata.stub
|
||||
process_py := $(topsrcdir)/python/mozbuild/mozbuild/action/xpidl-process.py
|
||||
generated_file := $(topobjdir)/xpcom/reflect/xptinfo/xptdata.cpp
|
||||
target_file := $(topobjdir)/xpcom/reflect/xptinfo/xptdata.cpp
|
||||
xptdata_h := $(dist_include_dir)/xptdata.h
|
||||
generated_files := $(target_file) $(xptdata_h)
|
||||
code_gen_py := $(topsrcdir)/xpcom/reflect/xptinfo/xptcodegen.py
|
||||
code_gen_deps := $(topsrcdir)/xpcom/ds/tools/perfecthash.py
|
||||
|
||||
|
@ -59,17 +62,21 @@ xpt_files := $(addsuffix .xpt,$(xpidl_modules))
|
|||
|
||||
depends_files := $(foreach root,$(xpidl_modules),$(idl_deps_dir)/$(root).pp)
|
||||
|
||||
GARBAGE += $(xpt_files) $(depends_files) $(generated_file)
|
||||
GARBAGE += $(stub_file) $(xpt_files) $(depends_files) $(target_file)
|
||||
|
||||
ifdef COMPILE_ENVIRONMENT
|
||||
xpidl:: $(generated_file)
|
||||
xpidl:: $(generated_files)
|
||||
endif
|
||||
|
||||
# See bug 1420119 for why we need the semicolon.
|
||||
$(target_file) $(xptdata_h) : $(stub_file) ;
|
||||
|
||||
$(xpt_files): $(process_py) $(call mkdir_deps,$(idl_deps_dir) $(dist_include_dir) $(dist_xpcrs_dir))
|
||||
|
||||
$(generated_file): $(xpt_files) $(code_gen_py) $(code_gen_deps)
|
||||
$(stub_file) : $(xpt_files) $(code_gen_py) $(code_gen_deps)
|
||||
$(REPORT_BUILD)
|
||||
$(PYTHON3) $(code_gen_py) $(generated_file) $(xpt_files)
|
||||
$(PYTHON3) $(code_gen_py) $(generated_files) $(xpt_files)
|
||||
@touch $@
|
||||
|
||||
-include $(depends_files)
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ utility_types = [
|
|||
|
||||
# Core of the code generator. Takes a list of raw JSON XPT interfaces, and
|
||||
# writes out a file containing the necessary static declarations into fd.
|
||||
def link_to_cpp(interfaces, fd):
|
||||
def link_to_cpp(interfaces, fd, header_fd):
|
||||
# Perfect Hash from IID to interface.
|
||||
iid_phf = PerfectHash(interfaces, PHFSIZE,
|
||||
key=lambda i: iid_bytes(i['uuid']))
|
||||
|
@ -449,8 +449,20 @@ def link_to_cpp(interfaces, fd):
|
|||
for iface in iid_phf.entries:
|
||||
lower_iface(iface)
|
||||
|
||||
# Write out the final output file
|
||||
# Write out the final output files
|
||||
fd.write("/* THIS FILE WAS GENERATED BY xptcodegen.py - DO NOT EDIT */\n\n")
|
||||
header_fd.write("/* THIS FILE WAS GENERATED BY xptcodegen.py - DO NOT EDIT */\n\n")
|
||||
|
||||
header_fd.write("""
|
||||
enum class nsXPTInterface : uint16_t {
|
||||
""")
|
||||
|
||||
for entry in iid_phf.entries:
|
||||
header_fd.write(" %s,\n" % entry['name'])
|
||||
|
||||
header_fd.write("""
|
||||
};
|
||||
""")
|
||||
|
||||
# Include any bindings files which we need to include for webidl types
|
||||
for include in sorted(includes):
|
||||
|
@ -548,7 +560,7 @@ const uint16_t sInterfacesSize = mozilla::ArrayLength(sInterfaces);
|
|||
""")
|
||||
|
||||
|
||||
def link_and_write(files, outfile):
|
||||
def link_and_write(files, outfile, outheader):
|
||||
interfaces = []
|
||||
for file in files:
|
||||
with open(file, 'r') as fd:
|
||||
|
@ -562,7 +574,7 @@ def link_and_write(files, outfile):
|
|||
iids.add(interface['uuid'])
|
||||
names.add(interface['name'])
|
||||
|
||||
link_to_cpp(interfaces, outfile)
|
||||
link_to_cpp(interfaces, outfile, outheader)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -571,11 +583,12 @@ def main():
|
|||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('outfile', help='Output C++ file to generate')
|
||||
parser.add_argument('outheader', help='Output C++ header file to generate')
|
||||
parser.add_argument('xpts', nargs='*', help='source xpt files')
|
||||
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
with open(args.outfile, 'w') as fd:
|
||||
link_and_write(args.xpts, fd)
|
||||
with open(args.outfile, 'w') as fd, open(args.outheader, 'w') as header_fd:
|
||||
link_and_write(args.xpts, fd, header_fd)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "js/Value.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "xptdata.h"
|
||||
|
||||
// Forward Declarations
|
||||
namespace mozilla {
|
||||
|
@ -69,6 +70,10 @@ struct nsXPTInterfaceInfo {
|
|||
return xpt::detail::InterfaceByName(aName);
|
||||
}
|
||||
|
||||
static const nsXPTInterfaceInfo* Get(nsXPTInterface aID) {
|
||||
return ByIndex(uint16_t(aID));
|
||||
}
|
||||
|
||||
// These are only needed for Components_interfaces's enumerator.
|
||||
static const nsXPTInterfaceInfo* ByIndex(uint16_t aIndex) {
|
||||
// NOTE: We add 1 here, as the internal index 0 is reserved for null.
|
||||
|
|
Загрузка…
Ссылка в новой задаче