Kaydet (Commit) 7580149b authored tarafından Martin v. Löwis's avatar Martin v. Löwis

Patch #1355883: Build Python-ast.c and Python-ast.h

independently. Fixes #1355883.
üst 969ef750
...@@ -219,13 +219,15 @@ PGENOBJS= $(PGENMAIN) $(POBJS) $(PGOBJS) ...@@ -219,13 +219,15 @@ PGENOBJS= $(PGENMAIN) $(POBJS) $(PGOBJS)
########################################################################## ##########################################################################
# AST # AST
AST_H= $(srcdir)/Include/Python-ast.h AST_H_DIR= $(srcdir)/Include
AST_C= $(srcdir)/Python/Python-ast.c AST_H= $(AST_H_DIR)/Python-ast.h
AST_C_DIR= $(srcdir)/Python
AST_C= $(AST_C_DIR)/Python-ast.c
AST_ASDL= $(srcdir)/Parser/Python.asdl AST_ASDL= $(srcdir)/Parser/Python.asdl
ASDLGEN_FILES= $(srcdir)/Parser/asdl.py $(srcdir)/Parser/asdl_c.py ASDLGEN_FILES= $(srcdir)/Parser/asdl.py $(srcdir)/Parser/asdl_c.py
# XXX Note that a build now requires Python exist before the build starts # XXX Note that a build now requires Python exist before the build starts
ASDLGEN= $(srcdir)/Parser/asdl_c.py -h $(srcdir)/Include -c $(srcdir)/Python ASDLGEN= $(srcdir)/Parser/asdl_c.py
########################################################################## ##########################################################################
# Python # Python
...@@ -465,9 +467,12 @@ Parser/metagrammar.o: $(srcdir)/Parser/metagrammar.c ...@@ -465,9 +467,12 @@ Parser/metagrammar.o: $(srcdir)/Parser/metagrammar.c
Parser/tokenizer_pgen.o: $(srcdir)/Parser/tokenizer.c Parser/tokenizer_pgen.o: $(srcdir)/Parser/tokenizer.c
$(AST_H) $(AST_C): $(AST_ASDL) $(ASDLGEN_FILES) $(AST_H): $(AST_ASDL) $(ASDLGEN_FILES)
$(ASDLGEN) $(AST_ASDL) $(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL)
$(AST_C): $(AST_ASDL) $(ASDLGEN_FILES)
$(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL)
Python/compile.o Python/symtable.o: $(GRAMMAR_H) $(AST_H) Python/compile.o Python/symtable.o: $(GRAMMAR_H) $(AST_H)
Python/getplatform.o: $(srcdir)/Python/getplatform.c Python/getplatform.o: $(srcdir)/Python/getplatform.c
......
...@@ -726,39 +726,35 @@ def main(srcfile): ...@@ -726,39 +726,35 @@ def main(srcfile):
sys.exit(1) sys.exit(1)
if INC_DIR: if INC_DIR:
p = "%s/%s-ast.h" % (INC_DIR, mod.name) p = "%s/%s-ast.h" % (INC_DIR, mod.name)
else: f = open(p, "wb")
p = "%s-ast.h" % mod.name print >> f, auto_gen_msg
f = open(p, "wb") print >> f, '#include "asdl.h"\n'
print >> f, auto_gen_msg c = ChainOfVisitors(TypeDefVisitor(f),
print >> f, '#include "asdl.h"\n' StructVisitor(f),
c = ChainOfVisitors(TypeDefVisitor(f), PrototypeVisitor(f),
StructVisitor(f), )
PrototypeVisitor(f), c.visit(mod)
) print >>f, "PyObject* PyAST_mod2obj(mod_ty t);"
c.visit(mod) f.close()
print >>f, "PyObject* PyAST_mod2obj(mod_ty t);"
f.close()
if SRC_DIR: if SRC_DIR:
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c") p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
else: f = open(p, "wb")
p = "%s-ast.c" % mod.name print >> f, auto_gen_msg
f = open(p, "wb") print >> f, '#include "Python.h"'
print >> f, auto_gen_msg print >> f, '#include "%s-ast.h"' % mod.name
print >> f, '#include "Python.h"' print >> f
print >> f, '#include "%s-ast.h"' % mod.name print >>f, "static PyTypeObject* AST_type;"
print >> f v = ChainOfVisitors(
print >>f, "static PyTypeObject* AST_type;" PyTypesDeclareVisitor(f),
v = ChainOfVisitors( PyTypesVisitor(f),
PyTypesDeclareVisitor(f), FunctionVisitor(f),
PyTypesVisitor(f), ObjVisitor(f),
FunctionVisitor(f), ASTModuleVisitor(f),
ObjVisitor(f), PartingShots(f),
ASTModuleVisitor(f), )
PartingShots(f), v.visit(mod)
) f.close()
v.visit(mod)
f.close()
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
...@@ -767,6 +763,9 @@ if __name__ == "__main__": ...@@ -767,6 +763,9 @@ if __name__ == "__main__":
INC_DIR = '' INC_DIR = ''
SRC_DIR = '' SRC_DIR = ''
opts, args = getopt.getopt(sys.argv[1:], "h:c:") opts, args = getopt.getopt(sys.argv[1:], "h:c:")
if len(opts) != 1:
print "Must specify exactly one output file"
sys.exit(1)
for o, v in opts: for o, v in opts:
if o == '-h': if o == '-h':
INC_DIR = v INC_DIR = v
...@@ -774,4 +773,5 @@ if __name__ == "__main__": ...@@ -774,4 +773,5 @@ if __name__ == "__main__":
SRC_DIR = v SRC_DIR = v
if len(args) != 1: if len(args) != 1:
print "Must specify single input file" print "Must specify single input file"
sys.exit(1)
main(args[0]) main(args[0])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment