diff --git a/debugger/debugjob.h b/debugger/debugjob.h --- a/debugger/debugjob.h +++ b/debugger/debugjob.h @@ -43,6 +43,7 @@ QString m_interpreter; QStringList m_args; QUrl m_workingDirectory; + QStringList m_environment; private slots: void standardOutputReceived(QStringList lines); diff --git a/debugger/debugjob.cpp b/debugger/debugjob.cpp --- a/debugger/debugjob.cpp +++ b/debugger/debugjob.cpp @@ -39,7 +39,8 @@ QStringList program; QString debuggerUrl = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kdevpythonsupport/debugger", QStandardPaths::LocateDirectory) + "/kdevpdb.py"; program << m_interpreter << "-u" << debuggerUrl << m_scriptUrl.toLocalFile() << m_args; - m_session = new DebugSession(program, m_workingDirectory); + // Inject environment + m_session = new DebugSession(program, m_workingDirectory, m_environment); setStandardToolView(KDevelop::IOutputView::DebugView); setBehaviours(KDevelop::IOutputView::Behaviours(KDevelop::IOutputView::AllowUserClose) | KDevelop::IOutputView::AutoScroll); diff --git a/debugger/debugsession.h b/debugger/debugsession.h --- a/debugger/debugsession.h +++ b/debugger/debugsession.h @@ -42,7 +42,8 @@ { Q_OBJECT public: - DebugSession(QStringList program, const QUrl& workingDirectory); + DebugSession(QStringList program, const QUrl& workingDirectory, + const QStringList& environment); ~DebugSession() override; IBreakpointController* breakpointController() const override; @@ -220,6 +221,7 @@ QStringList m_program; QList m_commandQueue; const QUrl& m_workingDirectory; + const QStringList& m_environment; private: /// objects to notify next QPointer m_nextNotifyObject; diff --git a/debugger/debugsession.cpp b/debugger/debugsession.cpp --- a/debugger/debugsession.cpp +++ b/debugger/debugsession.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -52,12 +53,14 @@ namespace Python { -DebugSession::DebugSession(QStringList program, const QUrl &workingDirectory) : +DebugSession::DebugSession(QStringList program, const QUrl &workingDirectory, + const QStringList& environment) : IDebugSession() , m_breakpointController(nullptr) , m_variableController(nullptr) , m_frameStackModel(nullptr) , m_workingDirectory(workingDirectory) + , m_environment(environment) , m_nextNotifyMethod(nullptr) , m_inDebuggerData(0) { @@ -91,6 +94,17 @@ m_debuggerProcess->setOutputChannelMode(KProcess::SeparateChannels); m_debuggerProcess->blockSignals(true); m_debuggerProcess->setWorkingDirectory(m_workingDirectory.path()); + + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + for(const auto &e : m_environment) + { + const QString key = e.section('=',0,0); + const QString value = e.section('=',1); + + env.insert(key, value); + } + m_debuggerProcess->setProcessEnvironment(env); + connect(m_debuggerProcess, &QProcess::readyReadStandardOutput, this, &DebugSession::dataAvailable); connect(m_debuggerProcess, SIGNAL(finished(int)), this, SLOT(debuggerQuit(int))); connect(this, &DebugSession::debuggerReady, this, &DebugSession::checkCommandQueue); diff --git a/debugger/pdblauncher.cpp b/debugger/pdblauncher.cpp --- a/debugger/pdblauncher.cpp +++ b/debugger/pdblauncher.cpp @@ -38,6 +38,7 @@ #include #include "debuggerdebug.h" +#include namespace Python { @@ -115,6 +116,27 @@ job->m_interpreter = interpreter; job->m_args = iface->arguments(cfg, err); job->m_workingDirectory = wd; + + const KDevelop::EnvironmentProfileList environmentProfiles(KSharedConfig::openConfig()); + QString envProfileName = iface->environmentProfileName(cfg); + + if (envProfileName.isEmpty()) { + qCWarning(KDEV_PYTHON_DEBUGGER) << i18n("No environment profile specified, looks like a broken " + "configuration, please check run configuration '%1'. " + "Using default environment profile.", cfg->name()); + envProfileName = environmentProfiles.defaultProfileName(); + } + + auto environment = environmentProfiles.variables(envProfileName); + + QMap::const_iterator i; + + for(i = environment.begin(); i != environment.end(); ++i) + { + QString oneEnvVariable = i.key() + "=" + i.value(); + job->m_environment << oneEnvVariable; + } + QList l; l << job; return new KDevelop::ExecuteCompositeJob( KDevelop::ICore::self()->runController(), l );