зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
7b58ab8671
Коммит
691d1784ff
|
@ -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)
|
fd.write(iface_template_epilog)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(outputfile):
|
||||||
from optparse import OptionParser
|
cachedir = '.'
|
||||||
o = OptionParser()
|
if not os.path.isdir(cachedir):
|
||||||
o.add_option('-I', action='append', dest='incdirs', default=['.'],
|
os.mkdir(cachedir)
|
||||||
help="Directory to search for imported files")
|
sys.path.append(cachedir)
|
||||||
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
|
|
||||||
|
|
||||||
if options.cachedir is not None:
|
# Delete the lex/yacc files. Ply is too stupid to regenerate them
|
||||||
if not os.path.isdir(options.cachedir):
|
# properly
|
||||||
os.mkdir(options.cachedir)
|
for fileglobs in [os.path.join(cachedir, f) for f in ["xpidllex.py*", "xpidlyacc.py*"]]:
|
||||||
sys.path.append(options.cachedir)
|
for filename in glob.glob(fileglobs):
|
||||||
|
os.remove(filename)
|
||||||
# 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)
|
|
||||||
|
|
||||||
# Instantiate the parser.
|
# Instantiate the parser.
|
||||||
p = xpidl.IDLParser(outputdir=options.cachedir)
|
p = xpidl.IDLParser(outputdir=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
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -13,6 +13,8 @@ GENERATED_FILES += [
|
||||||
'xpidlyacc.py',
|
'xpidlyacc.py',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
GENERATED_FILES['xpidllex.py'].script = 'header.py:main'
|
||||||
|
|
||||||
SDK_FILES.bin += [
|
SDK_FILES.bin += [
|
||||||
'!xpidllex.py',
|
'!xpidllex.py',
|
||||||
'!xpidlyacc.py',
|
'!xpidlyacc.py',
|
||||||
|
|
Загрузка…
Ссылка в новой задаче