2012-10-18 01:01:55 +04: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 12:59:08 +04:00
|
|
|
from Configuration import Configuration
|
2012-10-18 01:01:55 +04:00
|
|
|
from Codegen import CGExampleRoot, replaceFileIfChanged
|
|
|
|
|
|
|
|
def generate_interface_example(config, interfaceName):
|
|
|
|
"""
|
|
|
|
|config| Is the configuration object.
|
|
|
|
|interfaceName| is the name of the interface we're generating an example for.
|
|
|
|
"""
|
|
|
|
|
|
|
|
root = CGExampleRoot(config, interfaceName)
|
|
|
|
exampleHeader = interfaceName + "-example.h"
|
|
|
|
exampleImpl = interfaceName + "-example.cpp"
|
|
|
|
replaceFileIfChanged(exampleHeader, root.declare())
|
|
|
|
replaceFileIfChanged(exampleImpl, root.define())
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
# Parse arguments.
|
|
|
|
from optparse import OptionParser
|
|
|
|
usagestring = "usage: %prog configFile interfaceName"
|
|
|
|
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) != 2:
|
|
|
|
o.error(usagestring)
|
|
|
|
configFile = os.path.normpath(args[0])
|
|
|
|
interfaceName = args[1]
|
|
|
|
|
2013-05-09 21:06:48 +04:00
|
|
|
# Load the configuration
|
2012-10-18 01:01:55 +04:00
|
|
|
f = open('ParserResults.pkl', 'rb')
|
2013-05-09 21:06:48 +04:00
|
|
|
config = cPickle.load(f)
|
2012-10-18 01:01:55 +04:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
# Generate the example class.
|
|
|
|
generate_interface_example(config, interfaceName)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|