diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-28 11:21:32 (GMT) |
---|---|---|
committer | Antoine Pitrou <pitrou@free.fr> | 2017-09-28 11:21:32 (GMT) |
commit | ec3d34c5b2feb10cb4d7606a10d81c178c3afce3 (patch) | |
tree | cd031bd46f4abcc19e4666c12e00d6cec922956b /Parser | |
parent | befc956acf8ddeb94f000ed081ddec51315429e5 (diff) | |
download | cpython-ec3d34c5b2feb10cb4d7606a10d81c178c3afce3.zip cpython-ec3d34c5b2feb10cb4d7606a10d81c178c3afce3.tar.gz cpython-ec3d34c5b2feb10cb4d7606a10d81c178c3afce3.tar.bz2 |
[3.6] bpo-31536: Avoid wholesale rebuild after `make regen-all` (GH-3678) (#3797)
bpo-31536: Avoid wholesale rebuild after `make regen-all`
Diffstat (limited to 'Parser')
-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 1e5f4d9..6302af6 100644 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -1281,59 +1281,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: |