Clean up Python embedding to build on zizzer (where python2.4

is currently in /usr/local instead of /usr).

SConstruct:
    Use information from the Python interpreter used to run scons
    to find the version & paths for include & library files.
    This means that linking with a different interpreter requires
    invoking scons with that interpreter... add comment to that effect.
src/sim/main.cc:
    Check return codes of Python interpreter calls for errors.
    Get rid of include of obsolete header.

--HG--
extra : convert_revision : 90916bd8690fe1e6c9afdb0dfa1aa0d352a73a46
This commit is contained in:
Steve Reinhardt 2006-05-30 19:44:57 -04:00
parent 0337db3388
commit e371dc32a9
2 changed files with 33 additions and 14 deletions

View file

@ -62,8 +62,13 @@
import sys import sys
import os import os
# Check for recent-enough Python and SCons versions # Check for recent-enough Python and SCons versions. If your system's
EnsurePythonVersion(2,3) # default installation of Python is not recent enough, you can use a
# non-default installation of the Python interpreter by either (1)
# rearranging your PATH so that scons finds the non-default 'python'
# first or (2) explicitly invoking an alternative interpreter on the
# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
EnsurePythonVersion(2,4)
# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a # Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
# 3-element version number. # 3-element version number.
@ -169,11 +174,22 @@ if sys.platform == 'cygwin':
env.Append(CCFLAGS=Split("-Wno-uninitialized")) env.Append(CCFLAGS=Split("-Wno-uninitialized"))
env.Append(CPPPATH=[Dir('ext/dnet')]) env.Append(CPPPATH=[Dir('ext/dnet')])
# Environment args for linking in Python interpreter. # Find Python include and library directories for embedding the
# Should really have an option for setting the version instead of # interpreter. For consistency, we will use the same Python
# having 2.4 hardwired in here... # installation used to run scons (and thus this script). If you want
env.Append(CPPPATH='/usr/include/python2.4') # to link in an alternate version, see above for instructions on how
env.Append(LIBS='python2.4') # to invoke scons with a different copy of the Python interpreter.
# Get brief Python version name (e.g., "python2.4") for locating
# include & library files
py_version_name = 'python' + sys.version[:3]
# include path, e.g. /usr/local/include/python2.4
env.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
env.Append(LIBS = py_version_name)
# add library path too if it's not in the default place
if sys.exec_prefix != '/usr':
env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
# Other default libraries # Other default libraries
env.Append(LIBS=['z']) env.Append(LIBS=['z'])

View file

@ -146,8 +146,6 @@ echoCommandLine(int argc, char **argv, ostream &out)
out << endl << endl; out << endl << endl;
} }
#include "config/python_build_env.hh"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -171,20 +169,25 @@ main(int argc, char **argv)
// Set Python module path to include current file to find embedded // Set Python module path to include current file to find embedded
// zip archive // zip archive
PyRun_SimpleString("import sys"); if (PyRun_SimpleString("import sys") != 0)
panic("Python error importing 'sys' module\n");
string pathCmd = csprintf("sys.path[1:1] = ['%s']", fileName); string pathCmd = csprintf("sys.path[1:1] = ['%s']", fileName);
PyRun_SimpleString(pathCmd.c_str()); if (PyRun_SimpleString(pathCmd.c_str()) != 0)
panic("Python error setting sys.path\n");
// Pass compile timestamp string to Python // Pass compile timestamp string to Python
extern const char *compileDate; // from date.cc extern const char *compileDate; // from date.cc
string setCompileDate = csprintf("compileDate = '%s'", compileDate); string setCompileDate = csprintf("compileDate = '%s'", compileDate);
PyRun_SimpleString(setCompileDate.c_str()); if (PyRun_SimpleString(setCompileDate.c_str()) != 0)
panic("Python error setting compileDate\n");
// PyRun_InteractiveLoop(stdin, "stdin"); // PyRun_InteractiveLoop(stdin, "stdin");
// m5/__init__.py currently contains main argv parsing loop etc., // m5/__init__.py currently contains main argv parsing loop etc.,
// and will write out config.ini file before returning. // and will write out config.ini file before returning.
PyImport_ImportModule("defines"); if (PyImport_ImportModule("defines") == NULL)
PyImport_ImportModule("m5"); panic("Python error importing 'defines.py'\n");
if (PyImport_ImportModule("m5") == NULL)
panic("Python error importing 'm5' module\n");
Py_Finalize(); Py_Finalize();
configStream = simout.find("config.out"); configStream = simout.find("config.out");