mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
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.
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
# 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/.
|
|
|
|
import sys
|
|
sys.path.append("./parser/")
|
|
sys.path.append("./ply/")
|
|
import os
|
|
import cPickle
|
|
from Configuration import Configuration
|
|
from CodegenRust import CGBindingRoot, replaceFileIfChanged
|
|
|
|
|
|
def generate_binding_rs(config, outputprefix, webidlfile):
|
|
"""
|
|
|config| Is the configuration object.
|
|
|outputprefix| is a prefix to use for the header guards and filename.
|
|
"""
|
|
|
|
filename = outputprefix + ".rs"
|
|
root = CGBindingRoot(config, outputprefix, webidlfile)
|
|
if replaceFileIfChanged(filename, root.define()):
|
|
print "Generating binding implementation: %s" % (filename)
|
|
|
|
|
|
def main():
|
|
# Parse arguments.
|
|
from optparse import OptionParser
|
|
usagestring = "usage: %prog configFile outputPrefix webIDLFile"
|
|
o = OptionParser(usage=usagestring)
|
|
o.add_option("--verbose-errors", action='store_true', default=False,
|
|
help="When an error happens, display the Python traceback.")
|
|
(options, args) = o.parse_args()
|
|
|
|
if len(args) != 3:
|
|
o.error(usagestring)
|
|
configFile = os.path.normpath(args[0])
|
|
outputPrefix = args[1]
|
|
webIDLFile = os.path.normpath(args[2])
|
|
|
|
# Load the parsing results
|
|
f = open('ParserResults.pkl', 'rb')
|
|
parserData = cPickle.load(f)
|
|
f.close()
|
|
|
|
# Create the configuration data.
|
|
config = Configuration(configFile, parserData)
|
|
|
|
# Generate the prototype classes.
|
|
generate_binding_rs(config, outputPrefix, webIDLFile)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|