diff options
author | Thomas Wouters <thomas@python.org> | 2014-04-16 23:13:29 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2014-04-16 23:13:29 (GMT) |
commit | 67d8dc1f58452063e417b2cb2cfadd2fa12103d5 (patch) | |
tree | b7ea1462ba3ca4c2133ae5d1449279f5242009b7 /Tools | |
parent | 68290f48953340c5ec063cd12e3c37959122f081 (diff) | |
download | cpython-67d8dc1f58452063e417b2cb2cfadd2fa12103d5.zip cpython-67d8dc1f58452063e417b2cb2cfadd2fa12103d5.tar.gz cpython-67d8dc1f58452063e417b2cb2cfadd2fa12103d5.tar.bz2 |
Fix Tools/scripts/generate_opcode_h.py from issue #17861 to work correctly
when building in a separate object tree. More people should build this way.
This may still fail if the source is unwritable, I haven't tested that yet.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/scripts/generate_opcode_h.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py index b315491..a329a40 100644 --- a/Tools/scripts/generate_opcode_h.py +++ b/Tools/scripts/generate_opcode_h.py @@ -1,10 +1,6 @@ # This script generates the opcode.h header file. import sys -if len(sys.argv) > 0: - sys.path.insert(0, sys.argv[1]) -# Importing module from our given src directory. -import opcode header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */ #ifndef Py_OPCODE_H #define Py_OPCODE_H @@ -37,17 +33,20 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, """ -def main(outfile='Include/opcode.h'): +def main(opcode_py, outfile='Include/opcode.h'): + opcode = {} + exec(open(opcode_py).read(), opcode) + opmap = opcode['opmap'] with open(outfile, 'w') as fobj: fobj.write(header) - for name in opcode.opname: - if name in opcode.opmap: - fobj.write("#define %-20s\t%-3s\n" % (name, opcode.opmap[name])) + for name in opcode['opname']: + if name in opmap: + fobj.write("#define %-20s\t%-3s\n" % (name, opmap[name])) if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT fobj.write("#define %-20s\t%-3d\n" % - ('HAVE_ARGUMENT', opcode.HAVE_ARGUMENT)) + ('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT'])) fobj.write(footer) if __name__ == '__main__': - main(sys.argv[2]) + main(sys.argv[1], sys.argv[2]) |