Skip to content

Commit

Permalink
Fix Tools/scripts/generate_opcode_h.py from issue python#17861 to wor…
Browse files Browse the repository at this point in the history
…k 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.
  • Loading branch information
Yhg1s committed Apr 16, 2014
1 parent 68290f4 commit 67d8dc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ PGENOBJS= $(POBJS) $(PGOBJS)

##########################################################################
# opcode.h generation
OPCODE_H_DIR= Include
OPCODE_H_SCRIPT= Tools/scripts/generate_opcode_h.py
OPCODE_H= $(srcdir)/$(OPCODE_H_DIR)/opcode.h
OPCODE_H_GEN= @OPCODEHGEN@ $(OPCODE_H_SCRIPT) Lib/ $(OPCODE_H)
OPCODE_H_DIR= $(srcdir)/Include
OPCODE_H_SCRIPT= $(srcdir)/Tools/scripts/generate_opcode_h.py
OPCODE_H= $(OPCODE_H_DIR)/opcode.h
OPCODE_H_GEN= @OPCODEHGEN@ $(OPCODE_H_SCRIPT) $(srcdir)/Lib/opcode.py $(OPCODE_H)
#
##########################################################################
# AST
Expand Down
19 changes: 9 additions & 10 deletions Tools/scripts/generate_opcode_h.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,17 +33,20 @@
"""


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])

0 comments on commit 67d8dc1

Please sign in to comment.