diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-09-20 21:57:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-09-20 21:57:56 (GMT) |
commit | b091bec824137f286b22084be5f8d397d21b9abb (patch) | |
tree | 39ac8ea636a3df84dd613007e0dfa6209736db73 /Parser/asdl_c.py | |
parent | aaf6fc0982c916cb71d9e0afcd7dda4ba495793b (diff) | |
download | cpython-b091bec824137f286b22084be5f8d397d21b9abb.zip cpython-b091bec824137f286b22084be5f8d397d21b9abb.tar.gz cpython-b091bec824137f286b22084be5f8d397d21b9abb.tar.bz2 |
bpo-31536: Avoid wholesale rebuild after `make regen-all` (#3678)
* bpo-31536: Avoid wholesale rebuild after `make regen-all`
* Add NEWS
Diffstat (limited to 'Parser/asdl_c.py')
-rw-r--r-- | Parser/asdl_c.py | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index a43d2e7..0286d66 100644 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -1285,59 +1285,55 @@ def main(srcfile, dump_module=False): print(mod) if not asdl.check(mod): sys.exit(1) - if INC_DIR: - p = "%s/%s-ast.h" % (INC_DIR, mod.name) - f = open(p, "w") - f.write(auto_gen_msg) - f.write('#include "asdl.h"\n\n') - c = ChainOfVisitors(TypeDefVisitor(f), - StructVisitor(f), - PrototypeVisitor(f), - ) - c.visit(mod) - f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") - f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") - f.write("int PyAST_Check(PyObject* obj);\n") - f.close() - - if SRC_DIR: - p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c") - f = open(p, "w") - f.write(auto_gen_msg) - f.write('#include <stddef.h>\n') - f.write('\n') - f.write('#include "Python.h"\n') - f.write('#include "%s-ast.h"\n' % mod.name) - f.write('\n') - f.write("static PyTypeObject AST_type;\n") - v = ChainOfVisitors( - PyTypesDeclareVisitor(f), - PyTypesVisitor(f), - Obj2ModPrototypeVisitor(f), - FunctionVisitor(f), - ObjVisitor(f), - Obj2ModVisitor(f), - ASTModuleVisitor(f), - PartingShots(f), - ) - v.visit(mod) - f.close() + if H_FILE: + with open(H_FILE, "w") as f: + f.write(auto_gen_msg) + f.write('#include "asdl.h"\n\n') + c = ChainOfVisitors(TypeDefVisitor(f), + StructVisitor(f), + PrototypeVisitor(f), + ) + c.visit(mod) + f.write("PyObject* PyAST_mod2obj(mod_ty t);\n") + f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n") + f.write("int PyAST_Check(PyObject* obj);\n") + + if C_FILE: + with open(C_FILE, "w") as f: + f.write(auto_gen_msg) + f.write('#include <stddef.h>\n') + f.write('\n') + f.write('#include "Python.h"\n') + f.write('#include "%s-ast.h"\n' % mod.name) + f.write('\n') + f.write("static PyTypeObject AST_type;\n") + v = ChainOfVisitors( + PyTypesDeclareVisitor(f), + PyTypesVisitor(f), + Obj2ModPrototypeVisitor(f), + FunctionVisitor(f), + ObjVisitor(f), + Obj2ModVisitor(f), + ASTModuleVisitor(f), + PartingShots(f), + ) + v.visit(mod) if __name__ == "__main__": import getopt - INC_DIR = '' - SRC_DIR = '' + H_FILE = '' + C_FILE = '' dump_module = False opts, args = getopt.getopt(sys.argv[1:], "dh:c:") for o, v in opts: if o == '-h': - INC_DIR = v + H_FILE = v if o == '-c': - SRC_DIR = v + C_FILE = v if o == '-d': dump_module = True - if INC_DIR and SRC_DIR: + if H_FILE and C_FILE: print('Must specify exactly one output file') sys.exit(1) elif len(args) != 1: |