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

View file

@ -1,6 +1,6 @@
# This Source Code Form is subject to the terms of the Mozilla Public # 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, # License, v. 2.0. If a copy of the MPL was not distributed with this
# You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys import sys
import string import string
@ -18,9 +18,9 @@ for [prop, pref] in propList:
props += " [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs), props += " [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
prop) prop)
idlFile = open(sys.argv[1], "r"); idlFile = open(sys.argv[1], "r")
idlTemplate = idlFile.read(); idlTemplate = idlFile.read()
idlFile.close(); idlFile.close()
print ("/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n" + 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 # 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, # License, v. 2.0. If a copy of the MPL was not distributed with this
# You can obtain one at http://mozilla.org/MPL/2.0/. # 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 # We do one global pass over all the WebIDL to generate our prototype enum
# and generate information for subsequent phases. # and generate information for subsequent phases.
@ -9,12 +9,12 @@ import sys
sys.path.append("./parser/") sys.path.append("./parser/")
sys.path.append("./ply/") sys.path.append("./ply/")
import os import os
import cStringIO
import WebIDL import WebIDL
import cPickle import cPickle
from Configuration import * from Configuration import Configuration
from CodegenRust import GlobalGenRoots, replaceFileIfChanged from CodegenRust import GlobalGenRoots, replaceFileIfChanged
def generate_file(config, name, filename): def generate_file(config, name, filename):
root = getattr(GlobalGenRoots, name)(config) root = getattr(GlobalGenRoots, name)(config)
code = root.define() code = root.define()
@ -24,6 +24,7 @@ def generate_file(config, name, filename):
else: else:
print "%s hasn't changed - not touching it" % (filename) print "%s hasn't changed - not touching it" % (filename)
def main(): def main():
# Parse arguments. # Parse arguments.
from optparse import OptionParser 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 ... # Freeze scope here ... why this makes things work I have no idea ...
frozenglobals = globals() frozenglobals = globals()
import sys, os import sys
import os
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv[1:]) main(sys.argv[1:])

View file

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

View file

@ -32,9 +32,10 @@ ignored_files = [
"python/mozinfo/*", "python/mozinfo/*",
"python/mozlog/*", "python/mozlog/*",
"python/toml/*", "python/toml/*",
"components/script/dom/bindings/codegen/parser/*",
"components/script/dom/bindings/codegen/ply/*",
# Generated and upstream code combined with our own. Could use cleanup # Generated and upstream code combined with our own. Could use cleanup
"components/script/dom/bindings/codegen/*",
"components/style/properties/mod.rs", "components/style/properties/mod.rs",
"target/*", "target/*",
"ports/gonk/src/native_window_glue.cpp", "ports/gonk/src/native_window_glue.cpp",
@ -72,7 +73,13 @@ def should_check_reftest(file_name):
return file_name.endswith(reftest_filetype) return file_name.endswith(reftest_filetype)
EMACS_HEADER = "/* -*- Mode:"
VIM_HEADER = "/* vim:"
def check_license(contents): def check_license(contents):
while contents.startswith(EMACS_HEADER) or contents.startswith(VIM_HEADER):
_, _, contents = contents.partition("\n")
valid_license = any(contents.startswith(license) for license in licenses) valid_license = any(contents.startswith(license) for license in licenses)
acknowledged_bad_license = "xfail-license" in contents[:100] acknowledged_bad_license = "xfail-license" in contents[:100]
if not (valid_license or acknowledged_bad_license): if not (valid_license or acknowledged_bad_license):