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-09-10 11:27:39 -07:00
|
|
|
from Codegen import CGBindingRoot, replaceFileIfChanged, CGEventRoot
|
2013-08-22 16:09:17 -07:00
|
|
|
from mozbuild.makeutil import Makefile
|
|
|
|
from mozbuild.pythonutil import iter_modules_in_path
|
|
|
|
from buildconfig import topsrcdir
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-09-10 11:27:39 -07:00
|
|
|
def generate_binding_files(config, outputprefix, srcprefix, webidlfile,
|
|
|
|
generatedEventsWebIDLFiles):
|
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 10:05:33 -07:00
|
|
|
depsname = ".deps/" + outputprefix + ".pp"
|
2012-03-30 21:42:20 -07:00
|
|
|
root = CGBindingRoot(config, outputprefix, webidlfile)
|
2013-05-09 10:05:33 -07:00
|
|
|
replaceFileIfChanged(outputprefix + ".h", root.declare())
|
|
|
|
replaceFileIfChanged(outputprefix + ".cpp", root.define())
|
2013-05-09 14:11:59 -07:00
|
|
|
|
2013-09-10 11:27:39 -07:00
|
|
|
if webidlfile in generatedEventsWebIDLFiles:
|
|
|
|
eventName = webidlfile[:-len(".webidl")]
|
|
|
|
generatedEvent = CGEventRoot(config, eventName)
|
|
|
|
replaceFileIfChanged(eventName + ".h", generatedEvent.declare())
|
|
|
|
replaceFileIfChanged(eventName + ".cpp", generatedEvent.define())
|
|
|
|
|
2013-08-22 16:09:17 -07:00
|
|
|
mk = Makefile()
|
2013-08-27 21:14:55 -07:00
|
|
|
# NOTE: it's VERY important that we output dependencies for the FooBinding
|
|
|
|
# file here, not for the header or generated cpp file. These dependencies
|
|
|
|
# are used later to properly determine changedDeps and prevent rebuilding
|
|
|
|
# too much. See the comment explaining $(binding_dependency_trackers) in
|
|
|
|
# Makefile.in.
|
|
|
|
rule = mk.create_rule([outputprefix])
|
2013-09-25 21:05:00 -07:00
|
|
|
rule.add_dependencies(os.path.join(srcprefix, x) for x in sorted(root.deps()))
|
2013-08-22 16:09:17 -07:00
|
|
|
rule.add_dependencies(iter_modules_in_path(topsrcdir))
|
|
|
|
with open(depsname, 'w') as f:
|
|
|
|
mk.dump(f)
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
def main():
|
|
|
|
# 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 10:05:33 -07:00
|
|
|
configFile = os.path.normpath(args[0])
|
|
|
|
srcPrefix = os.path.normpath(args[1])
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-05-09 10:06:48 -07:00
|
|
|
# Load the configuration
|
2012-03-30 21:42:20 -07:00
|
|
|
f = open('ParserResults.pkl', 'rb')
|
2013-05-09 10:06:48 -07:00
|
|
|
config = cPickle.load(f)
|
2012-03-30 21:42:20 -07:00
|
|
|
f.close()
|
|
|
|
|
2013-05-09 10:05:33 -07:00
|
|
|
def readFile(f):
|
|
|
|
file = open(f, 'rb')
|
|
|
|
try:
|
|
|
|
contents = file.read()
|
|
|
|
finally:
|
|
|
|
file.close()
|
|
|
|
return contents
|
|
|
|
allWebIDLFiles = readFile(args[2]).split()
|
2013-09-10 11:27:39 -07:00
|
|
|
generatedEventsWebIDLFiles = readFile(args[3]).split()
|
|
|
|
changedDeps = readFile(args[4]).split()
|
2013-05-09 10:05:33 -07:00
|
|
|
|
|
|
|
if all(f.endswith("Binding") or f == "ParserResults.pkl" for f in changedDeps):
|
|
|
|
toRegenerate = filter(lambda f: f.endswith("Binding"), changedDeps)
|
2013-05-28 07:11:19 -07:00
|
|
|
if len(toRegenerate) == 0 and len(changedDeps) == 1:
|
|
|
|
# Work around build system bug 874923: if we get here that means
|
|
|
|
# that changedDeps contained only one entry and it was
|
|
|
|
# "ParserResults.pkl". That should never happen: if the
|
|
|
|
# ParserResults.pkl changes then either one of the globalgen files
|
|
|
|
# changed (in which case we wouldn't be in this "only
|
|
|
|
# ParserResults.pkl and *Binding changed" code) or some .webidl
|
|
|
|
# files changed (and then the corresponding *Binding files should
|
|
|
|
# show up in changedDeps). Since clearly the build system is
|
|
|
|
# confused, just regenerate everything to be safe.
|
|
|
|
toRegenerate = allWebIDLFiles
|
|
|
|
else:
|
|
|
|
toRegenerate = map(lambda f: f[:-len("Binding")] + ".webidl",
|
|
|
|
toRegenerate)
|
2012-03-30 21:42:20 -07:00
|
|
|
else:
|
2013-05-09 10:05:33 -07:00
|
|
|
toRegenerate = allWebIDLFiles
|
|
|
|
|
|
|
|
for webIDLFile in toRegenerate:
|
|
|
|
assert webIDLFile.endswith(".webidl")
|
|
|
|
outputPrefix = webIDLFile[:-len(".webidl")] + "Binding"
|
2013-09-10 11:27:39 -07:00
|
|
|
generate_binding_files(config, outputPrefix, srcPrefix, webIDLFile,
|
|
|
|
generatedEventsWebIDLFiles);
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|