Fix TestImport for Windows by ensuring backslashes in the directory paths are properly escaped in Python.
The Python import works by ensuring the directory of the module or package is in sys.path, and then it does a Python `import foo`. The original code was not escaping the backslashes in the directory path, so this wasn't working. Differential Revision: http://reviews.llvm.org/D18873 llvm-svn: 265738
This commit is contained in:
@@ -2548,7 +2548,7 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
|
||||
|
||||
StreamString command_stream;
|
||||
|
||||
// Before executing Pyton code, lock the GIL.
|
||||
// Before executing Python code, lock the GIL.
|
||||
Locker py_lock (this,
|
||||
Locker::AcquireLock | (init_session ? Locker::InitSession : 0) | Locker::NoSTDIN,
|
||||
Locker::FreeAcquiredLock | (init_session ? Locker::TearDownSession : 0));
|
||||
@@ -2569,9 +2569,10 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
|
||||
target_file.GetFileType() == FileSpec::eFileTypeRegular ||
|
||||
target_file.GetFileType() == FileSpec::eFileTypeSymbolicLink)
|
||||
{
|
||||
std::string directory(target_file.GetDirectory().GetCString());
|
||||
replace_all(directory,"'","\\'");
|
||||
|
||||
std::string directory = target_file.GetDirectory().GetCString();
|
||||
replace_all(directory, "\\", "\\\\");
|
||||
replace_all(directory, "'", "\\'");
|
||||
|
||||
// now make sure that Python has "directory" in the search path
|
||||
StreamString command_stream;
|
||||
command_stream.Printf("if not (sys.path.__contains__('%s')):\n sys.path.insert(1,'%s');\n\n",
|
||||
@@ -2583,7 +2584,7 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
|
||||
error.SetErrorString("Python sys.path handling failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// strip .py or .pyc extension
|
||||
ConstString extension = target_file.GetFileNameExtension();
|
||||
if (extension)
|
||||
@@ -2634,8 +2635,8 @@ ScriptInterpreterPython::LoadScriptingModule(const char *pathname, bool can_relo
|
||||
command_stream.Printf("reload_module(%s)",basename.c_str());
|
||||
}
|
||||
else
|
||||
command_stream.Printf("import %s",basename.c_str());
|
||||
|
||||
command_stream.Printf("import %s", basename.c_str());
|
||||
|
||||
error = ExecuteMultipleLines(command_stream.GetData(), ScriptInterpreter::ExecuteScriptOptions().SetEnableIO(false).SetSetLLDBGlobals(false));
|
||||
if (error.Fail())
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user