Construct a correct value of PYTHONHOME from the interpreter

running SCons, make it into a sticky option that can be
overridden at build time, and set it up before the interpreter
is started.  Also, fix the code that turns sticky options into
config/*.hh so that it works with types other than bool.

--HG--
extra : convert_revision : 602398b35d4da4e813f78865678ed348fdea7270
This commit is contained in:
Nathan Binkert 2006-10-20 11:37:59 -07:00
parent ad783962c5
commit 6c6b78126a
2 changed files with 18 additions and 4 deletions

View file

@ -347,7 +347,10 @@ sticky_opts.AddOptions(
('CC', 'C compiler', os.environ.get('CC', env['CC'])),
('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
BoolOption('BATCH', 'Use batch pool for build and tests', False),
('BATCH_CMD', 'Batch pool submission command name', 'qdo')
('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
('PYTHONHOME',
'Override the default PYTHONHOME for this system (use with caution)',
'%s:%s' % (sys.prefix, sys.exec_prefix))
)
# Non-sticky options only apply to the current build.
@ -359,7 +362,7 @@ nonsticky_opts.AddOptions(
# These options get exported to #defines in config/*.hh (see src/SConscript).
env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
'USE_CHECKER']
'USE_CHECKER', 'PYTHONHOME']
# Define a handy 'no-op' action
def no_action(target, source, env):
@ -399,8 +402,13 @@ def config_emitter(target, source, env):
option = str(target[0])
# True target is config header file
target = os.path.join('config', option.lower() + '.hh')
# Force value to 0/1 even if it's a Python bool
val = int(eval(str(env[option])))
val = env[option]
if isinstance(val, bool):
# Force value to 0/1
val = int(val)
elif isinstance(val, str):
val = '"' + val + '"'
# Sources are option name & value (packaged in SCons Value nodes)
return ([target], [Value(option), Value(val)])

View file

@ -55,6 +55,7 @@
#include "base/statistics.hh"
#include "base/str.hh"
#include "base/time.hh"
#include "config/pythonhome.hh"
#include "cpu/base.hh"
#include "cpu/smt.hh"
#include "mem/mem_object.hh"
@ -145,6 +146,11 @@ main(int argc, char **argv)
if (setenv("PYTHONPATH", pythonpath.c_str(), true) == -1)
fatal("setenv: %s\n", strerror(errno));
char *python_home = getenv("PYTHONHOME");
if (!python_home)
python_home = PYTHONHOME;
Py_SetPythonHome(python_home);
// initialize embedded Python interpreter
Py_Initialize();
PySys_SetArgv(argc, argv);