Bug 1108294 - Use mozbuild.makeutil for dependency file writing; r=froydnj

AccEventGen.py was using an old, one-off Python module for writing make
dependency files. We have a more appropriate API now. So we use it.

While we were here, we modified file writing to use FileAvoidWrite to
avoid always writing the output files and bumping mtimes.

--HG--
extra : rebase_source : 34ef9badacceb4791f27816c756ad9c95bf4069c
This commit is contained in:
Gregory Szorc 2014-12-06 15:47:06 -08:00
parent 0fb6606df2
commit 3e5523d480

View File

@ -4,7 +4,10 @@
# 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, os, xpidl, makeutils
import sys, os, xpidl
from mozbuild.makeutil import write_dep_makefile
from mozbuild.util import FileAvoidWrite
def findIDL(includePath, interfaceFileName):
for d in includePath:
@ -20,11 +23,9 @@ def findIDL(includePath, interfaceFileName):
def loadEventIDL(parser, includePath, eventname):
eventidl = ("nsIAccessible%s.idl" % eventname)
idlFile = findIDL(includePath, eventidl)
if not idlFile in makeutils.dependencies:
makeutils.dependencies.append(idlFile)
idl = p.parse(open(idlFile).read(), idlFile)
idl.resolve(includePath, p)
return idl
return idl, idlFile
class Configuration:
def __init__(self, filename):
@ -42,6 +43,8 @@ def writeAttributeParams(a):
return ("%s a%s" % (a.realtype.nativeType('in'), firstCap(a.name)))
def print_header_file(fd, conf):
idl_paths = set()
fd.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n")
fd.write("#ifndef _mozilla_a11y_generated_AccEvents_h_\n"
"#define _mozilla_a11y_generated_AccEvents_h_\n\n")
@ -52,7 +55,8 @@ def print_header_file(fd, conf):
for e in conf.simple_events:
fd.write("#include \"nsIAccessible%s.h\"\n" % e)
for e in conf.simple_events:
idl = loadEventIDL(p, options.incdirs, e)
idl, idl_path = loadEventIDL(p, options.incdirs, e)
idl_paths.add(idl_path)
for iface in filter(lambda p: p.kind == "interface", idl.productions):
classname = ("xpcAcc%s" % e)
baseinterfaces = interfaces(iface)
@ -83,6 +87,8 @@ def print_header_file(fd, conf):
fd.write("#endif\n")
return idl_paths
def interfaceAttributeTypes(idl):
ifaces = filter(lambda p: p.kind == "interface", idl.productions)
attributes = []
@ -98,6 +104,7 @@ def print_cpp(idl, fd, conf, eventname):
write_cpp(eventname, p, fd)
def print_cpp_file(fd, conf):
idl_paths = set()
fd.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
fd.write('#include "xpcAccEvents.h"\n')
@ -108,7 +115,8 @@ def print_cpp_file(fd, conf):
types = []
for e in conf.simple_events:
idl = loadEventIDL(p, options.incdirs, e)
idl, idl_path = loadEventIDL(p, options.incdirs, e)
idl_paths.add(idl_path)
types.extend(interfaceAttributeTypes(idl))
for c in types:
@ -116,7 +124,11 @@ def print_cpp_file(fd, conf):
fd.write("\n")
for e in conf.simple_events:
print_cpp(loadEventIDL(p, options.incdirs, e), fd, conf, e)
idl, idl_path = loadEventIDL(p, options.incdirs, e)
idl_paths.add(idl_path)
print_cpp(idl, fd, conf, e)
return idl_paths
def attributeVariableTypeAndName(a):
if a.realtype.nativeType('in').endswith('*'):
@ -215,12 +227,12 @@ def main():
conf = readConfigFile(options.config)
makeutils.targets.append(options.stub_output)
with open(options.stub_output, 'w') as fh:
print_cpp_file(fh, conf)
makeutils.writeMakeDependOutput(options.makedepend_output)
with open(options.header_output, 'w') as fh:
print_header_file(fh, conf)
with FileAvoidWrite(options.header_output) as fh:
idl_paths = print_header_file(fh, conf)
with FileAvoidWrite(options.stub_output) as fh:
idl_paths |= print_cpp_file(fh, conf)
with FileAvoidWrite(options.makedepend_output) as fh:
write_dep_makefile(fh, options.stub_output, idl_paths)
if __name__ == '__main__':
main()