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

--HG--
extra : rebase_source : f19ac1ad688115c0aee4bf307b72d6207512f702
This commit is contained in:
Mike Shal 2016-03-03 14:15:58 -05:00
Родитель 7b58ab8671
Коммит 691d1784ff
3 изменённых файлов: 13 добавлений и 100 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -526,74 +526,20 @@ def write_interface(iface, fd):
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 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()

Просмотреть файл

@ -13,6 +13,8 @@ GENERATED_FILES += [
'xpidlyacc.py',
]
GENERATED_FILES['xpidllex.py'].script = 'header.py:main'
SDK_FILES.bin += [
'!xpidllex.py',
'!xpidlyacc.py',