aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/BindingGen.py
blob: 79576b67e58dc1b97983edfa863c71d6e70f3bf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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
import os
sys.path.append(os.path.join(".", "parser"))
sys.path.append(os.path.join(".", "ply"))
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"
    module = CGBindingRoot(config, outputprefix, webidlfile).define()
    if not module:
        print "Skipping empty module: %s" % (filename)
    elif replaceFileIfChanged(filename, module):
        print "Generating binding implementation: %s" % (filename)


def main():
    # Parse arguments.
    from optparse import OptionParser
    usagestring = "usage: %prog configFile outputdir outputPrefix webIDLFile"
    o = OptionParser(usage=usagestring)
    (options, args) = o.parse_args()

    if len(args) != 4:
        o.error(usagestring)
    configFile = os.path.normpath(args[0])
    outputdir = args[1]
    outputPrefix = args[2]
    webIDLFile = os.path.normpath(args[3])

    # Load the parsing results
    resultsPath = os.path.join(outputdir, 'ParserResults.pkl')
    with open(resultsPath, 'rb') as f:
        parserData = cPickle.load(f)

    # Create the configuration data.
    config = Configuration(configFile, parserData)

    # Generate the prototype classes.
    generate_binding_rs(config, outputPrefix, webIDLFile)

if __name__ == '__main__':
    main()