2012-03-30 21:42:20 -07:00
|
|
|
# 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 os
|
|
|
|
import cPickle
|
2012-12-02 00:59:08 -08:00
|
|
|
from Configuration import Configuration
|
2013-05-09 14:11:59 -07:00
|
|
|
from Codegen import CGBindingRoot
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-05-09 14:11:59 -07:00
|
|
|
def generate_binding_header(config, outputprefix, srcprefix, webidlfile):
|
2012-03-30 21:42:20 -07:00
|
|
|
"""
|
|
|
|
|config| Is the configuration object.
|
|
|
|
|outputprefix| is a prefix to use for the header guards and filename.
|
|
|
|
"""
|
|
|
|
|
2013-05-09 14:11:59 -07:00
|
|
|
filename = outputprefix + ".h"
|
|
|
|
depsname = ".deps/" + filename + ".pp"
|
2012-03-30 21:42:20 -07:00
|
|
|
root = CGBindingRoot(config, outputprefix, webidlfile)
|
2013-05-09 14:11:59 -07:00
|
|
|
with open(filename, 'wb') as f:
|
|
|
|
f.write(root.declare())
|
2013-02-24 12:36:44 -08:00
|
|
|
with open(depsname, 'wb') as f:
|
2013-05-09 10:05:33 -07:00
|
|
|
# Sort so that our output is stable
|
2013-05-09 14:11:59 -07:00
|
|
|
f.write("\n".join(filename + ": " + os.path.join(srcprefix, x) for
|
|
|
|
x in sorted(root.deps())))
|
|
|
|
|
|
|
|
def generate_binding_cpp(config, outputprefix, srcprefix, webidlfile):
|
|
|
|
"""
|
|
|
|
|config| Is the configuration object.
|
|
|
|
|outputprefix| is a prefix to use for the header guards and filename.
|
|
|
|
"""
|
|
|
|
|
|
|
|
filename = outputprefix + ".cpp"
|
|
|
|
depsname = ".deps/" + filename + ".pp"
|
|
|
|
root = CGBindingRoot(config, outputprefix, webidlfile)
|
|
|
|
with open(filename, 'wb') as f:
|
|
|
|
f.write(root.define())
|
|
|
|
with open(depsname, 'wb') as f:
|
|
|
|
f.write("\n".join(filename + ": " + os.path.join(srcprefix, x) for
|
2013-04-03 19:22:14 -07:00
|
|
|
x in sorted(root.deps())))
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
def main():
|
2013-05-09 14:11:59 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
# Parse arguments.
|
|
|
|
from optparse import OptionParser
|
2013-02-24 12:36:44 -08:00
|
|
|
usagestring = "usage: %prog [header|cpp] configFile outputPrefix srcPrefix webIDLFile"
|
2012-03-30 21:42:20 -07:00
|
|
|
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()
|
|
|
|
|
2013-05-09 14:11:59 -07:00
|
|
|
if len(args) != 5 or (args[0] != "header" and args[0] != "cpp"):
|
|
|
|
o.error(usagestring)
|
|
|
|
buildTarget = args[0]
|
|
|
|
configFile = os.path.normpath(args[1])
|
|
|
|
outputPrefix = args[2]
|
|
|
|
srcPrefix = os.path.normpath(args[3])
|
|
|
|
webIDLFile = os.path.normpath(args[4])
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-05-09 14:11:59 -07:00
|
|
|
# Load the parsing results
|
2012-03-30 21:42:20 -07:00
|
|
|
f = open('ParserResults.pkl', 'rb')
|
2013-05-09 14:11:59 -07:00
|
|
|
parserData = cPickle.load(f)
|
2012-03-30 21:42:20 -07:00
|
|
|
f.close()
|
|
|
|
|
2013-05-09 14:11:59 -07:00
|
|
|
# Create the configuration data.
|
|
|
|
config = Configuration(configFile, parserData)
|
2013-05-09 10:05:33 -07:00
|
|
|
|
2013-05-09 14:11:59 -07:00
|
|
|
# Generate the prototype classes.
|
|
|
|
if buildTarget == "header":
|
|
|
|
generate_binding_header(config, outputPrefix, srcPrefix, webIDLFile);
|
|
|
|
elif buildTarget == "cpp":
|
|
|
|
generate_binding_cpp(config, outputPrefix, srcPrefix, webIDLFile);
|
2012-03-30 21:42:20 -07:00
|
|
|
else:
|
2013-05-09 14:11:59 -07:00
|
|
|
assert False # not reached
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|