diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-08-09 21:28:58 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-08-09 21:28:58 (GMT) |
commit | 398256b230cb2d890910c8b6d981f73bbbffa26d (patch) | |
tree | 55d94ee88ce412052b5ee4603fe9e2b5c7cdb7d7 /Parser | |
parent | 71ce8970cf7115bc344de1fc2e0205868925ce54 (diff) | |
download | cpython-398256b230cb2d890910c8b6d981f73bbbffa26d.zip cpython-398256b230cb2d890910c8b6d981f73bbbffa26d.tar.gz cpython-398256b230cb2d890910c8b6d981f73bbbffa26d.tar.bz2 |
don't rewrite the header file if it hasn't changed; this reduces development build time
Diffstat (limited to 'Parser')
-rwxr-xr-x | Parser/asdl_c.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 0b95aaa..d9d7662 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -4,7 +4,9 @@ # TO DO # handle fields that have a type but no name -import os, sys +import os +import sys +import StringIO import subprocess import asdl @@ -1155,7 +1157,7 @@ def main(srcfile): sys.exit(1) if INC_DIR: p = "%s/%s-ast.h" % (INC_DIR, mod.name) - f = open(p, "w") + f = StringIO.StringIO() f.write(auto_gen_msg) f.write('#include "asdl.h"\n\n') c = ChainOfVisitors(TypeDefVisitor(f), @@ -1166,7 +1168,12 @@ def main(srcfile): 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() + s = f.getvalue() + with open(p, "r") as fp: + write = fp.read() != s + if write: + with open(p, "w") as fp: + f.write(s) if SRC_DIR: p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c") |