bpo-31536: Avoid wholesale rebuild after `make regen-all` (#3678) · pythoncapi/cpython@b091bec · GitHub
Skip to content

Commit b091bec

Browse files
pitrouvstinner
authored andcommitted
bpo-31536: Avoid wholesale rebuild after make regen-all (python#3678)
* bpo-31536: Avoid wholesale rebuild after `make regen-all` * Add NEWS
1 parent aaf6fc0 commit b091bec

4 files changed

Lines changed: 86 additions & 51 deletions

File tree

Makefile.pre.in

Lines changed: 19 additions & 9 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid wholesale rebuild after `make regen-all` if nothing changed.

Parser/asdl_c.py

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,59 +1285,55 @@ def main(srcfile, dump_module=False):
12851285
print(mod)
12861286
if not asdl.check(mod):
12871287
sys.exit(1)
1288-
if INC_DIR:
1289-
p = "%s/%s-ast.h" % (INC_DIR, mod.name)
1290-
f = open(p, "w")
1291-
f.write(auto_gen_msg)
1292-
f.write('#include "asdl.h"\n\n')
1293-
c = ChainOfVisitors(TypeDefVisitor(f),
1294-
StructVisitor(f),
1295-
PrototypeVisitor(f),
1296-
)
1297-
c.visit(mod)
1298-
f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
1299-
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
1300-
f.write("int PyAST_Check(PyObject* obj);\n")
1301-
f.close()
1302-
1303-
if SRC_DIR:
1304-
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
1305-
f = open(p, "w")
1306-
f.write(auto_gen_msg)
1307-
f.write('#include <stddef.h>\n')
1308-
f.write('\n')
1309-
f.write('#include "Python.h"\n')
1310-
f.write('#include "%s-ast.h"\n' % mod.name)
1311-
f.write('\n')
1312-
f.write("static PyTypeObject AST_type;\n")
1313-
v = ChainOfVisitors(
1314-
PyTypesDeclareVisitor(f),
1315-
PyTypesVisitor(f),
1316-
Obj2ModPrototypeVisitor(f),
1317-
FunctionVisitor(f),
1318-
ObjVisitor(f),
1319-
Obj2ModVisitor(f),
1320-
ASTModuleVisitor(f),
1321-
PartingShots(f),
1322-
)
1323-
v.visit(mod)
1324-
f.close()
1288+
if H_FILE:
1289+
with open(H_FILE, "w") as f:
1290+
f.write(auto_gen_msg)
1291+
f.write('#include "asdl.h"\n\n')
1292+
c = ChainOfVisitors(TypeDefVisitor(f),
1293+
StructVisitor(f),
1294+
PrototypeVisitor(f),
1295+
)
1296+
c.visit(mod)
1297+
f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
1298+
f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
1299+
f.write("int PyAST_Check(PyObject* obj);\n")
1300+
1301+
if C_FILE:
1302+
with open(C_FILE, "w") as f:
1303+
f.write(auto_gen_msg)
1304+
f.write('#include <stddef.h>\n')
1305+
f.write('\n')
1306+
f.write('#include "Python.h"\n')
1307+
f.write('#include "%s-ast.h"\n' % mod.name)
1308+
f.write('\n')
1309+
f.write("static PyTypeObject AST_type;\n")
1310+
v = ChainOfVisitors(
1311+
PyTypesDeclareVisitor(f),
1312+
PyTypesVisitor(f),
1313+
Obj2ModPrototypeVisitor(f),
1314+
FunctionVisitor(f),
1315+
ObjVisitor(f),
1316+
Obj2ModVisitor(f),
1317+
ASTModuleVisitor(f),
1318+
PartingShots(f),
1319+
)
1320+
v.visit(mod)
13251321

13261322
if __name__ == "__main__":
13271323
import getopt
13281324

1329-
INC_DIR = ''
1330-
SRC_DIR = ''
1325+
H_FILE = ''
1326+
C_FILE = ''
13311327
dump_module = False
13321328
opts, args = getopt.getopt(sys.argv[1:], "dh:c:")
13331329
for o, v in opts:
13341330
if o == '-h':
1335-
INC_DIR = v
1331+
H_FILE = v
13361332
if o == '-c':
1337-
SRC_DIR = v
1333+
C_FILE = v
13381334
if o == '-d':
13391335
dump_module = True
1340-
if INC_DIR and SRC_DIR:
1336+
if H_FILE and C_FILE:
13411337
print('Must specify exactly one output file')
13421338
sys.exit(1)
13431339
elif len(args) != 1:

Tools/scripts/update_file.py

Lines changed: 28 additions & 0 deletions

0 commit comments

Comments
 (0)