Skip to content

Commit

Permalink
Generate a list of supported DOM APIs from parsed WebIDLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Jul 15, 2016
1 parent 2df5d70 commit 3c2435a
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 12 deletions.
34 changes: 34 additions & 0 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -8,6 +8,7 @@
from itertools import groupby

import operator
import os
import re
import string
import textwrap
Expand Down Expand Up @@ -6437,3 +6438,36 @@ def UnionTypes(config):

# Done.
return curr

@staticmethod
def SupportedDomApis(config):
descriptors = config.getDescriptors(isExposedConditionally=False)

base_path = os.path.join('dom', 'bindings', 'codegen')
with open(os.path.join(base_path, 'apis.html.template')) as f:
base_template = f.read()
with open(os.path.join(base_path, 'api.html.template')) as f:
api_template = f.read()
with open(os.path.join(base_path, 'property.html.template')) as f:
property_template = f.read()
with open(os.path.join(base_path, 'interface.html.template')) as f:
interface_template = f.read()

apis = []
interfaces = []
for descriptor in descriptors:
props = []
for m in descriptor.interface.members:
if PropertyDefiner.getStringAttr(m, 'Pref') or \
PropertyDefiner.getStringAttr(m, 'Func') or \
(m.isMethod() and m.isIdentifierLess()):
continue
display = m.identifier.name + ('()' if m.isMethod() else '')
props += [property_template.replace('${name}', display)]
name = descriptor.interface.identifier.name
apis += [(api_template.replace('${interface}', name)
.replace('${properties}', '\n'.join(props)))]
interfaces += [interface_template.replace('${interface}', name)]

return CGGeneric((base_template.replace('${apis}', '\n'.join(apis))
.replace('${interfaces}', '\n'.join(interfaces))))
2 changes: 2 additions & 0 deletions components/script/dom/bindings/codegen/Configuration.py
Expand Up @@ -87,6 +87,8 @@ def getDescriptors(self, **filters):
getter = lambda x: x.interface.isJSImplemented()
elif key == 'isGlobal':
getter = lambda x: x.isGlobal()
elif key == 'isExposedConditionally':
getter = lambda x: x.interface.isExposedConditionally()
else:
getter = lambda x: getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr)
Expand Down
30 changes: 19 additions & 11 deletions components/script/dom/bindings/codegen/GlobalGen.py
Expand Up @@ -32,6 +32,8 @@ def main():
o = OptionParser(usage=usageString)
o.add_option("--cachedir", dest='cachedir', default=None,
help="Directory in which to cache lex/parse tables.")
o.add_option("--only-html", dest='only_html', action="store_true",
help="Only generate HTML from WebIDL inputs")
(options, args) = o.parse_args()

if len(args) < 2:
Expand All @@ -51,24 +53,30 @@ def main():
parser.parse(''.join(lines), fullPath)
parserResults = parser.finish()

# Write the parser results out to a pickle.
resultsPath = os.path.join(outputdir, 'ParserResults.pkl')
with open(resultsPath, 'wb') as resultsFile:
cPickle.dump(parserResults, resultsFile, -1)
if not options.only_html:
# Write the parser results out to a pickle.
resultsPath = os.path.join(outputdir, 'ParserResults.pkl')
with open(resultsPath, 'wb') as resultsFile:
cPickle.dump(parserResults, resultsFile, -1)

# Load the configuration.
config = Configuration(configFile, parserResults)

to_generate = [
('PrototypeList', 'PrototypeList.rs'),
('RegisterBindings', 'RegisterBindings.rs'),
('InterfaceObjectMap', 'InterfaceObjectMap.rs'),
('InterfaceTypes', 'InterfaceTypes.rs'),
('InheritTypes', 'InheritTypes.rs'),
('Bindings', os.path.join('Bindings', 'mod.rs')),
('UnionTypes', 'UnionTypes.rs'),
('SupportedDomApis', 'apis.html'),
]

if not options.only_html:
to_generate = [
('PrototypeList', 'PrototypeList.rs'),
('RegisterBindings', 'RegisterBindings.rs'),
('InterfaceObjectMap', 'InterfaceObjectMap.rs'),
('InterfaceTypes', 'InterfaceTypes.rs'),
('InheritTypes', 'InheritTypes.rs'),
('Bindings', os.path.join('Bindings', 'mod.rs')),
('UnionTypes', 'UnionTypes.rs'),
]

for name, filename in to_generate:
generate_file(config, name, os.path.join(outputdir, filename))

Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/bindings/codegen/api.html.template
@@ -0,0 +1,6 @@
<table id="${interface}">
<tr>
<th>${interface}</th>
</tr>
${properties}
</table>
35 changes: 35 additions & 0 deletions components/script/dom/bindings/codegen/apis.html.template
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `servo` crate.">
<meta name="keywords" content="rust, rustlang, rust-lang, servo">
<title>Supported DOM APIs - servo - Rust</title>
<link rel="stylesheet" type="text/css" href="../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class='sidebar'>
<div class='block crate'>
<h3>Interfaces</h3>
<ul>
${interfaces}
</ul>
</div>
</nav>
<section id='main' class="content mod">
<h1 class='fqn'><span class='in-band'>DOM APIs currently supported in <a class='mod' href=''>Servo</a></span></h1>
<div id='properties' class='docblock'>
${apis}
</div>
</section>
</body>
</html>
@@ -0,0 +1 @@
<li><a href="#${interface}">${interface}</a></li>
3 changes: 3 additions & 0 deletions components/script/dom/bindings/codegen/property.html.template
@@ -0,0 +1,3 @@
<tr>
<td>${name}</td>
</tr>
12 changes: 11 additions & 1 deletion components/script/makefile.cargo
Expand Up @@ -18,7 +18,7 @@ bindinggen_dependencies := $(addprefix $(BINDINGS_SRC)/,BindingGen.py Bindings.c

globalgen_dependencies := $(addprefix $(BINDINGS_SRC)/,GlobalGen.py Bindings.conf Configuration.py CodegenRust.py parser/WebIDL.py) $(CACHE_DIR)/.done $(OUT_DIR)/Bindings/.done

.PHONY: all
.PHONY: all dom_docs
all: $(AUTOGEN_SRC)

$(OUT_DIR)/Bindings/.done:
Expand All @@ -38,6 +38,16 @@ $(OUT_DIR)/ParserResults.pkl: $(globalgen_dependencies) $(WEBIDLS)
. \
$(WEBIDLS)

dom_docs: $(CACHE_DIR)/.done
$(PYTHON) \
$(BINDINGS_SRC)/GlobalGen.py \
--cachedir=$(CACHE_DIR) \
--only-html \
$(BINDINGS_SRC)/Bindings.conf \
$(OUT_DIR) \
. \
$(WEBIDLS)

$(AUTOGEN_SRC): $(OUT_DIR)/Bindings/%Binding.rs: $(bindinggen_dependencies) \
$(addprefix $(WEBIDLS_SRC)/,%.webidl)
$(PYTHON) \
Expand Down
2 changes: 2 additions & 0 deletions etc/ci/upload_docs.sh
Expand Up @@ -16,5 +16,7 @@ cp etc/doc.servo.org/* target/doc/

python components/style/properties/build.py servo html

OUT_DIR="`pwd`/target/doc" make -f makefile.cargo -C components/script dom_docs

ghp-import -n target/doc
git push -qf "https://${TOKEN}@github.com/servo/doc.servo.org.git" gh-pages

0 comments on commit 3c2435a

Please sign in to comment.