Bug 1253431 part 4 - Convert header.py to a GENERATED_FILES script; r?gps
We only ever execute this in one place, so we can just have the main
action do the --regen --cachedir=. mode of operation.
MozReview-Commit-ID: Fis4YBPFjMl
deleted file mode 100644
--- a/xpcom/idl-parser/xpidl/Makefile.in
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# 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/.
-
-PARSER_SRCS = \
- header.py \
- typelib.py \
- xpidl.py \
- $(NULL)
-
-PLY_FILES = \
- $(topsrcdir)/other-licenses/ply/ply/__init__.py \
- $(topsrcdir)/other-licenses/ply/ply/lex.py \
- $(topsrcdir)/other-licenses/ply/ply/yacc.py \
- $(NULL)
-
-include $(topsrcdir)/config/rules.mk
-
-# Generate the PLY lexer and parser.
-xpidllex.py: $(PARSER_SRCS) $(PLY_FILES)
- $(PYTHON_PATH) \
- $(PLY_INCLUDE) \
- $(srcdir)/header.py --cachedir=. --regen
-
-# generating xpidllex.py generates xpidlyacc.py too
-xpidlyacc.py: xpidllex.py
-
-GARBAGE += \
- xpidllex.py \
- xpidllex.pyc \
- xpidlyacc.py \
- xpidlyacc.pyc \
- xpidl_debug \
- $(NULL)
--- a/xpcom/idl-parser/xpidl/header.py
+++ b/xpcom/idl-parser/xpidl/header.py
@@ -521,79 +521,25 @@ def write_interface(iface, fd):
'returntype': methodReturnType(member, 'NS_IMETHODIMP'),
'nativeName': methodNativeName(member),
'paramList': paramlistAsNative(member, empty='')})
fd.write('\n')
fd.write(iface_template_epilog)
-def main():
- from optparse import OptionParser
- o = OptionParser()
- o.add_option('-I', action='append', dest='incdirs', default=['.'],
- help="Directory to search for imported files")
- o.add_option('--cachedir', dest='cachedir', default=None,
- help="Directory in which to cache lex/parse tables.")
- o.add_option('-o', dest='outfile', default=None,
- help="Output file (default is stdout)")
- o.add_option('-d', dest='depfile', default=None,
- help="Generate a make dependency file")
- o.add_option('--regen', action='store_true', dest='regen', default=False,
- help="Regenerate IDL Parser cache")
- options, args = o.parse_args()
- file = args[0] if args else None
+def main(outputfile):
+ cachedir = '.'
+ if not os.path.isdir(cachedir):
+ os.mkdir(cachedir)
+ sys.path.append(cachedir)
- if options.cachedir is not None:
- if not os.path.isdir(options.cachedir):
- os.mkdir(options.cachedir)
- sys.path.append(options.cachedir)
-
- # The only thing special about a regen is that there are no input files.
- if options.regen:
- if options.cachedir is None:
- print >>sys.stderr, "--regen useless without --cachedir"
- # Delete the lex/yacc files. Ply is too stupid to regenerate them
- # properly
- for fileglobs in [os.path.join(options.cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"]]:
- for filename in glob.glob(fileglobs):
- os.remove(filename)
+ # Delete the lex/yacc files. Ply is too stupid to regenerate them
+ # properly
+ for fileglobs in [os.path.join(cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"]]:
+ for filename in glob.glob(fileglobs):
+ os.remove(filename)
# Instantiate the parser.
- p = xpidl.IDLParser(outputdir=options.cachedir)
-
- if options.regen:
- sys.exit(0)
-
- if options.depfile is not None and options.outfile is None:
- print >>sys.stderr, "-d requires -o"
- sys.exit(1)
-
- if options.outfile is not None:
- outfd = open(options.outfile, 'w')
- closeoutfd = True
- else:
- outfd = sys.stdout
- closeoutfd = False
-
- idl = p.parse(open(file).read(), filename=file)
- idl.resolve(options.incdirs, p)
- print_header(idl, outfd, file)
-
- if closeoutfd:
- outfd.close()
-
- if options.depfile is not None:
- dirname = os.path.dirname(options.depfile)
- if dirname:
- try:
- os.makedirs(dirname)
- except:
- pass
- depfd = open(options.depfile, 'w')
- deps = [dep.replace('\\', '/') for dep in idl.deps]
-
- print >>depfd, "%s: %s" % (options.outfile, " ".join(deps))
- for dep in deps:
- print >>depfd, "%s:" % dep
+ p = xpidl.IDLParser(outputdir=cachedir)
if __name__ == '__main__':
main()
--- a/xpcom/idl-parser/xpidl/moz.build
+++ b/xpcom/idl-parser/xpidl/moz.build
@@ -8,16 +8,18 @@ PYTHON_UNIT_TESTS += [
'runtests.py',
]
GENERATED_FILES += [
'xpidllex.py',
'xpidlyacc.py',
]
+GENERATED_FILES['xpidllex.py'].script = 'header.py:main'
+
SDK_FILES.bin += [
'!xpidllex.py',
'!xpidlyacc.py',
'header.py',
'typelib.py',
'xpidl.py',
]