As noted in this forum thread: https://forums.codeblocks.org/index.php/topic,25217.msg172116/topicseen.html#msg172116
if you have a project with different compilers in targets, or switch compiler of the project, or have multiple projects with different compilers, the PATH variable gets spoiled with compiler paths.
The reason is that on every compiler switch the "old" PATH variable is read and the new compiler path is pre appended. On the first project loading everything is fine, because the PATH is still virgin, but after the second compiler loading, reading the PATH will result in a path with the old compiler pre appended to the actual path. This goes on and on.
my proposed solution is to store the PATH on codeblocks start and use this path on compiler switches. But i have no idea if this interferes with the environment variable plugin:
diff --git a/src/include/manager.h b/src/include/manager.h
index 3898ecb4a..2fd9e1be6 100644
--- a/src/include/manager.h
+++ b/src/include/manager.h
@@ -158,6 +158,9 @@ public:
/// @return The scale factor of the specified UI component.
double GetUIScaleFactor(UIComponent component) const;
+ wxString GetOriginPath() const;
+ void SetOriginPath(const wxString& path);
+
static wxCmdLineParser* GetCmdLineParser();
// event sinks
@@ -181,6 +184,8 @@ private:
static wxCmdLineParser m_CmdLineParser;
static wxToolBarAddOnXmlHandler *m_ToolbarHandler;
+ wxString m_originPath;
+
int m_ImageSizes[UIComponent::Last];
double m_UIScaleFactor[UIComponent::Last];
diff --git a/src/plugins/compilergcc/compilergcc.cpp b/src/plugins/compilergcc/compilergcc.cpp
index 6e219d2f5..af94e6ed3 100644
--- a/src/plugins/compilergcc/compilergcc.cpp
+++ b/src/plugins/compilergcc/compilergcc.cpp
@@ -23,6 +23,7 @@
#include <wx/ffile.h>
#include <wx/utils.h>
+
#include "prep.h"
#include "manager.h"
#include "sdk_events.h"
@@ -43,6 +44,7 @@
#include <wx/uri.h>
#include <wx/xml/xml.h>
+#include <wx/tokenzr.h>
#include "annoyingdialog.h"
#include "debuggermanager.h"
@@ -759,8 +761,8 @@ void CompilerGCC::SetupEnvironment()
if (!compiler)
return;
- wxString currentPath;
- if ( !wxGetEnv(_T("PATH"), ¤tPath) )
+ wxString currentPath = Manager::Get()->GetOriginPath();
+ if ( currentPath.IsEmpty() )
{
InfoWindow::Display(_("Environment error"),
_("Could not read the PATH environment variable!\n"
@@ -771,8 +773,8 @@ void CompilerGCC::SetupEnvironment()
return;
}
-// Manager::Get()->GetLogManager()->DebugLogError(_T("PATH environment:"));
-// Manager::Get()->GetLogManager()->DebugLogError(currentPath);
+ Manager::Get()->GetLogManager()->DebugLogError(_T("PATH environment:"));
+ Manager::Get()->GetLogManager()->DebugLogError(currentPath);
const wxString pathApp = platform::windows ? _T(";") : _T(":");
const wxString pathSep = wxFileName::GetPathSeparator(); // "\" or "/"
@@ -824,7 +826,8 @@ void CompilerGCC::SetupEnvironment()
// [3] Append what has already been in the PATH envvar...
// If we do it this way, paths are automatically normalized and doubles are removed
wxPathList pathArray;
- pathArray.AddEnvList(_T("PATH"));
+ //pathArray.AddEnvList(_T("PATH"));
+ pathArray.Add( wxStringTokenize(currentPath, pathApp));
pathList.Add(pathArray);
// Try to locate the path to the C compiler:
diff --git a/src/sdk/manager.cpp b/src/sdk/manager.cpp
index fc6ab0858..855f130f3 100644
--- a/src/sdk/manager.cpp
+++ b/src/sdk/manager.cpp
@@ -348,6 +348,16 @@ bool Manager::IsAppStartedUp()
return m_AppStartedUp;
}
+wxString Manager::GetOriginPath() const
+{
+ return m_originPath;
+}
+
+void Manager::SetOriginPath(const wxString& path)
+{
+ m_originPath = path;
+}
+
void Manager::LoadXRC(wxString relpath)
{
LoadResource(relpath);
diff --git a/src/src/app.cpp b/src/src/app.cpp
index 9bb04d1cd..9bcdcb2d7 100644
--- a/src/src/app.cpp
+++ b/src/src/app.cpp
@@ -622,6 +622,10 @@ bool CodeBlocksApp::OnInit()
wxInitAllImageHandlers();
wxXmlResource::Get()->InitAllHandlers();
+ wxString m_originPATH;
+ wxGetEnv("PATH", &m_originPATH);
+ Manager::Get()->SetOriginPath(m_originPATH);
+
Manager::SetToolbarHandler(toolbarAddonHandler);
LogManager *log = Manager::Get()->GetLogManager();
take care: in the above patch some logging is enabled that could be disabled when applying in production
In general this should not create problems, because the new path is always pre appended and for this seen first. But i still think that this is not the expected behaviour
Well, It does create problems like I reported in https://sourceforge.net/p/codeblocks/tickets/1263/
Are you able to test my patch? (self compile codeblocks)
Fixing this screams for this xkcd https://xkcd.com/1172/ (one of my favourite :) )
I will try to! maybe next week.