Remove tidy blacklist for 'script/dom/bindings/*'

Recently, I found myself reading through the Python codegen scripts that
live in 'components/script/dom/bindings/*' and noticed that there were
many tidy violations: unnecessary semicolons, weird spacing, unused
variables, lack of license headers, etc. Considering these files are now
living in our tree and mostly maintained directly by contributors of
Servo (as opposed to being from upstream), I feel these files should not
be excluded from our normal tidy process. This commit removes the
blacklist on these files and fixes all tidy violations.

I added these subdirectories to the blacklist because they appear to be
maintained upstream somewhere else:

* "components/script/dom/bindings/codegen/parser/*",
* "components/script/dom/bindings/codegen/ply/*",

Also, I added a '# noqa' comment which tells us to ignore the
flake8 errors for that line. I chose to ignore this (instead of fixing
it) to make the work for this commit simpler for me.
This commit is contained in:
Corey Farwell 2015-07-05 12:10:53 -07:00
parent fe17067d6a
commit 0ec2375cab
8 changed files with 476 additions and 261 deletions

View file

@ -1,16 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
sys.path.append("./parser/")
sys.path.append("./ply/")
import os
import cPickle
import WebIDL
from Configuration import *
from Configuration import Configuration
from CodegenRust import CGBindingRoot, replaceFileIfChanged
def generate_binding_rs(config, outputprefix, webidlfile):
"""
|config| Is the configuration object.
@ -22,6 +22,7 @@ def generate_binding_rs(config, outputprefix, webidlfile):
if replaceFileIfChanged(filename, root.define()):
print "Generating binding implementation: %s" % (filename)
def main():
# Parse arguments.
from optparse import OptionParser
@ -46,7 +47,7 @@ def main():
config = Configuration(configFile, parserData)
# Generate the prototype classes.
generate_binding_rs(config, outputPrefix, webIDLFile);
generate_binding_rs(config, outputPrefix, webIDLFile)
if __name__ == '__main__':
main()

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,12 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from WebIDL import IDLInterface
autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"
class Configuration:
"""
Represents global configuration state based on IDL parse data and
@ -22,7 +23,7 @@ class Configuration:
# |parseData|.
self.descriptors = []
self.interfaces = {}
self.maxProtoChainLength = 0;
self.maxProtoChainLength = 0
for thing in parseData:
# Some toplevel things are sadly types, and those have an
# isInterface that doesn't mean the same thing as IDLObject's
@ -44,7 +45,8 @@ class Configuration:
if not isinstance(entry, list):
assert isinstance(entry, dict)
entry = [entry]
self.descriptors.extend([Descriptor(self, iface, x) for x in entry])
self.descriptors.extend(
[Descriptor(self, iface, x) for x in entry])
# Mark the descriptors for which only a single nativeType implements
# an interface.
@ -60,10 +62,11 @@ class Configuration:
c.isCallback() and not c.isInterface()]
# Keep the descriptor list sorted for determinism.
self.descriptors.sort(lambda x,y: cmp(x.name, y.name))
self.descriptors.sort(lambda x, y: cmp(x.name, y.name))
def getInterface(self, ifname):
return self.interfaces[ifname]
def getDescriptors(self, **filters):
"""Gets the descriptors that match the given filters."""
curr = self.descriptors
@ -80,6 +83,7 @@ class Configuration:
getter = lambda x: getattr(x, key)
curr = filter(lambda x: getter(x) == val, curr)
return curr
def getEnums(self, webIDLFile):
return filter(lambda e: e.filename() == webIDLFile, self.enums)
@ -93,6 +97,7 @@ class Configuration:
def getDictionaries(self, webIDLFile=""):
return self._filterForFile(self.dictionaries, webIDLFile=webIDLFile)
def getCallbacks(self, webIDLFile=""):
return self._filterForFile(self.callbacks, webIDLFile=webIDLFile)
@ -104,20 +109,23 @@ class Configuration:
descriptors = self.getDescriptors(interface=iface)
# We should have exactly one result.
if len(descriptors) is not 1:
if len(descriptors) != 1:
raise NoSuchDescriptorError("For " + interfaceName + " found " +
str(len(matches)) + " matches");
str(len(descriptors)) + " matches")
return descriptors[0]
def getDescriptorProvider(self):
"""
Gets a descriptor provider that can provide descriptors as needed.
"""
return DescriptorProvider(self)
class NoSuchDescriptorError(TypeError):
def __init__(self, str):
TypeError.__init__(self, str)
class DescriptorProvider:
"""
A way of getting descriptors for interface names
@ -132,6 +140,7 @@ class DescriptorProvider:
"""
return self.config.getDescriptor(interfaceName)
class Descriptor(DescriptorProvider):
"""
Represents a single descriptor for an interface. See Bindings.conf.
@ -148,7 +157,7 @@ class Descriptor(DescriptorProvider):
if self.interface.isCallback():
self.needsRooting = False
ty = "%sBinding::%s" % (ifaceName, ifaceName)
self.returnType = "Rc<%s>"% ty
self.returnType = "Rc<%s>" % ty
self.argumentType = "???"
self.memberType = "???"
self.nativeType = ty
@ -230,7 +239,7 @@ class Descriptor(DescriptorProvider):
# self.extendedAttributes is a dict of dicts, keyed on
# all/getterOnly/setterOnly and then on member name. Values are an
# array of extended attributes.
self.extendedAttributes = { 'all': {}, 'getterOnly': {}, 'setterOnly': {} }
self.extendedAttributes = {'all': {}, 'getterOnly': {}, 'setterOnly': {}}
def addExtendedAttribute(attribute, config):
def add(key, members, attribute):
@ -334,6 +343,7 @@ def getTypesFromDescriptor(descriptor):
types.extend(a.type for a in members if a.isAttr())
return types
def getFlatTypes(types):
retval = set()
for type in types:
@ -344,6 +354,7 @@ def getFlatTypes(types):
retval.add(type)
return retval
def getTypesFromDictionary(dictionary):
"""
Get all member types for this dictionary
@ -355,12 +366,13 @@ def getTypesFromDictionary(dictionary):
curDict = curDict.parent
return types
def getTypesFromCallback(callback):
"""
Get the types this callback depends on: its return type and the
types of its arguments.
"""
sig = callback.signatures()[0]
types = [sig[0]] # Return type
types.extend(arg.type for arg in sig[1]) # Arguments
types = [sig[0]] # Return type
types.extend(arg.type for arg in sig[1]) # Arguments
return types

View file

@ -1,6 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import string
@ -18,9 +18,9 @@ for [prop, pref] in propList:
props += " [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
prop)
idlFile = open(sys.argv[1], "r");
idlTemplate = idlFile.read();
idlFile.close();
idlFile = open(sys.argv[1], "r")
idlTemplate = idlFile.read()
idlFile.close()
print ("/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n" +
string.Template(idlTemplate).substitute({ "props": props }))
string.Template(idlTemplate).substitute({"props": props}))

View file

@ -1,6 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# We do one global pass over all the WebIDL to generate our prototype enum
# and generate information for subsequent phases.
@ -9,12 +9,12 @@ import sys
sys.path.append("./parser/")
sys.path.append("./ply/")
import os
import cStringIO
import WebIDL
import cPickle
from Configuration import *
from Configuration import Configuration
from CodegenRust import GlobalGenRoots, replaceFileIfChanged
def generate_file(config, name, filename):
root = getattr(GlobalGenRoots, name)(config)
code = root.define()
@ -24,6 +24,7 @@ def generate_file(config, name, filename):
else:
print "%s hasn't changed - not touching it" % (filename)
def main():
# Parse arguments.
from optparse import OptionParser

View file

@ -54,7 +54,8 @@ def main(args):
# Freeze scope here ... why this makes things work I have no idea ...
frozenglobals = globals()
import sys, os
import sys
import os
if __name__ == '__main__':
main(sys.argv[1:])

View file

@ -1,8 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef TestBindingHeader_h
#define TestBindingHeader_h
@ -126,7 +125,7 @@ public:
const TestInterfaceOrOnlyForUseInConstructor&,
ErrorResult&);
*/
// Integer types
int8_t ReadonlyByte();
int8_t WritableByte();
@ -215,7 +214,8 @@ public:
void ReceiveNonWrapperCacheInterfaceSequence(nsTArray<nsRefPtr<TestNonWrapperCacheInterface> >&);
void ReceiveNullableNonWrapperCacheInterfaceSequence(nsTArray<nsRefPtr<TestNonWrapperCacheInterface> >&);
void ReceiveNonWrapperCacheInterfaceNullableSequence(Nullable<nsTArray<nsRefPtr<TestNonWrapperCacheInterface> > >&);
void ReceiveNullableNonWrapperCacheInterfaceNullableSequence(Nullable<nsTArray<nsRefPtr<TestNonWrapperCacheInterface> > >&);
void ReceiveNullableNonWrapperCacheInterfaceNullableSequence(
Nullable<nsTArray<nsRefPtr<TestNonWrapperCacheInterface> > >&);
already_AddRefed<TestNonCastableInterface> ReceiveOther();
already_AddRefed<TestNonCastableInterface> ReceiveNullableOther();