pkrcel: Can you try with the latest nightly build?In addition: Can you enable the ennvars "debug log" (Settings -> Environment -> Envvars) and C::B's "debug log" (by starting C::NB with the command line option --debug-log) and post what the plugin does here? It's written to the debug log then.
Attached the debug log. :)OK, If I look at this:
Good, I'll stay tuned...and thanks for all this C::B goodness anyway :)Should be fixed in trunk. Feel free to try...
Since I'm not all that accustomed with SVN/git and the like...you mean I shall retrieve all TRUNK and build Code::Blocks or I can do only the plugin?...depends: If you link against a nightly, a checkout / build of the envvars plugin will be enough. If you are using an old version of C::B you'll have to wait for the next nightly. But I am sure it won't take long until then...
EDIT: having gone (again) through the Wiki you linked me, seems that the envvvars plugin is specifically designed to dabble with system EnvVars, as I deducted reading here (http://wiki.codeblocks.org/index.php?title=Code::Blocks_variable_types_synthesis)
Alpha: You are wrong here. It sets system env variables and at least on linux it works as expected.Apologies for the incorrect information... it looks like I have mislead myself based on a previous edit I did to the plugin's page (http://wiki.codeblocks.org/index.php?title=Environment_Variables_plugin) :-[. (I have now changed it to be more accurate.)
attached you can find the debug-log. ..if that is of any help.Hmmm, I don't see what could go wrong now. Can you strip down you project to a minimalistic example and provide me with exact steps what you do to achieve this "error"? Also, please attach your (zipped) default.conf file - at least the ennvars section, starting with:
<envvars>
<sets>
<default>
[...]
Attached is the project zip file, I haven't stripped any info (except objs and exes!), and there is also the default.conf file.You do have one, trust me, you find it either under ~/.codeblocks (Linux) or in %APPDATA%\codeblocks on Windows. Notice that you don't need to provide the whole file, just the envvars section (you can open it with a XML capable editor like Code::Blocks). But remember DO NOT MODIFY THIS FILE!!! Just extract the content requested to a new file.
<envvars>
<sets>
<default />
<liballeg>
<ENVVAR0>
<str>
<![CDATA[1|PATH|%PATH%;C:\Users\Provasi\_user\Coding\Libraries\allegro-5.0.5-mingw-4.5.2\bin;C:\MingW\bin]]>
</str>
</ENVVAR0>
</liballeg>
</sets>
<ACTIVE_SET>
<str>
<![CDATA[liballeg]]>
</str>
</ACTIVE_SET>
<DEBUG_LOG bool="1" />
</envvars>
- select a Dyn target (either one), and press "run"....usually the first time all goes fine and you shoul receive a "it's all good" messageboxWorks fine here. However, your project settings are really screwed. you hard-code path, path's to libs and use full path's for the names of the libs. So I had to completely modify what you did to use relative path's and (compiler / linker) include path's.
- press "build", you should get a "target up to date" message in the build log window.
- press "run" again, now you should get the "cannot find allegro monolith dll" error message.
Question: is there a way to see the value of PATH at any time inside C::B focus?
PATH=C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Fi
les\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Fil
es\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\Syste
m32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Comm
on Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Share
d\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\
;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program
Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\
Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\T
ortoiseSVN\bin;C:\Mingw32\bin;C:\Users\Provasi\_user\Coding\Libraries\allegro-5.
0.5-mingw-4.5.2\bin
Process returned 0 (0x0) execution time : 0.033 s
Press any key to continue.
PATH=C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Fi
les\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Fil
es\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\Syste
m32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Comm
on Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Share
d\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\
;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program
Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\
Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\T
ortoiseSVN\bin;C:\Mingw32\bin
Process returned 0 (0x0) execution time : 0.023 s
Press any key to continue.
PATH=C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Fi
les\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Fil
es\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\Syste
m32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Comm
on Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Share
d\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\
;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program
Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\
Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\T
ortoiseSVN\bin;C:\Mingw32\bin;C:\Users\Provasi\_user\Coding\Libraries\allegro-5.
0.5-mingw-4.5.2\bin
Process returned 0 (0x0) execution time : 0.021 s
Press any key to continue.
Any ideas? ???OK, I think I know why and this is not "nice". You said you compile C::B yourself. Can you do me a favour and search for the following in the compiler plugins's compilergcc.cpp file (should be in CompilerGCC::SetupEnvironment()):
if (!m_OriginalPath.IsEmpty())
wxSetEnv(_T("PATH"), m_OriginalPath);
if (!m_OriginalPath.IsEmpty())
{
Manager::Get()->GetLogManager()->DebugLog(_T("Setting up compiler PATH environment..."));
wxSetEnv(_T("PATH"), m_OriginalPath);
}
envPath = envPath + GetStringFromArray(envPathArr, path_sep, false);
wxSetEnv(_T("PATH"), envPath);
envPath = envPath + GetStringFromArray(envPathArr, path_sep, false);
Manager::Get()->GetLogManager()->DebugLog(_T("Updating compiler PATH environment..."));
wxSetEnv(_T("PATH"), envPath);
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="MyCmd" />
<Option compiler="gcc" />
<Build>
<Target title="default">
<Option type="4" />
<Option compiler="gcc" />
<ExtraCommands>
<Add before="echo <PRE_BUILD>" />
<Add before="echo %PATH%" />
<Add before="echo </PRE_BUILD>" />
<Add after="echo <POST_BUILD>" />
<Add after="echo %PATH%" />
<Add after="echo </POST_BUILD>" />
<Mode after="always" />
</ExtraCommands>
</Target>
</Build>
<Extensions>
<envvars set="dummy" />
</Extensions>
</Project>
</CodeBlocks_project_file>
[....]
EnvVars: Searching for envvars in path '/sets/default'.
EnvVars: Read 1/1 envvars in path '/sets/default'.
EnvVars: Trying to set environment variable 'PATH' to value 'C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Mingw32\bin;C:\Users\Provasi\_user\Coding\Libraries\allegro-5.0.5-mingw-4.5.2\bin'...
EnvVars: 1/1 envvars applied within C::B focus.
Passing list of files to batch-parser.
Header to parse with priority: 'C:\MinGW\lib\gcc\mingw32\4.6.1\include\c++\cstddef'
Header to parse with priority: 'C:\MinGW\include\w32api.h'
Add 2 priority parsing file(s) for project 'AllegText'...
Added 1 file(s) for project 'AllegText' to batch-parser...
Create new parser for project 'AllegText'
Updating class browser...
Class browser updated.
Starting batch parsing for project 'AllegText'...
Project 'AllegText' parsing stage done!
Project 'AllegText' parsing stage done (53 total parsed files, 1657 tokens in 0 minute(s), 0.589 seconds).
Updating class browser...
Class browser updated.
Setting up compiler PATH environment...
Updating compiler PATH environment...
Scanned 0 files for #includes, cache used 0, cache updated 0
Scanned 0 files for #includes, cache used 0, cache updated 0
Scanned 0 files for #includes, cache used 47, cache updated 0
Scanned 0 files for #includes, cache used 0, cache updated 0
Scanned 0 files for #includes, cache used 0, cache updated 0
Scanned 0 files for #includes, cache used 0, cache updated 0
Setting up compiler PATH environment...
Updating compiler PATH environment...
Scanned 0 files for #includes, cache used 0, cache updated 0
Setting up compiler PATH environment...
Updating compiler PATH environment...
Scanned 0 files for #includes, cache used 0, cache updated 0
Running target pre-build steps
cmd /c echo PRE_BUILD
PRE_BUILD
cmd /c echo C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Mingw32\bin
C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Mingw32\bin
-------------- Build: default in MyCmd ---------------
Linking stage skipped (build target has no object files to link)
Running target post-build steps
cmd /c echo POST_BUILD
POST_BUILD
cmd /c echo C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Mingw32\bin
C:\MinGW\bin;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ZipGenius 6\;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Mingw32\bin
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
I think the additions you made me push in ended up in this:So, it seems I was right: Setting up the PATH envvar using the EnvVars plugin interferes with the compiler plugin that uses the PATH envvar, too for settings up additional path's as setup by the user in the compiler's tool chain settings. Unfortunately it uses a cached PATH anvvar - so the one before the EnvVars plugin updated it. Interesting to see: It depends on the priority of the plugin, so if you were able to setup a higher priority for the EnvVars plugin it would probably work...
I think it should be save to remove the caching at all, and probably put both functions together to one.Careful: Assume you have a project which uses e.g. GCC3 and GCC4 compiler. In that case having an old PATH in front (GCC3) may result in an error if you just /prepend the new (GCC4) one and probably missed some some additional PATH's. Even worse with VC compilers: They usually need a lot additional PATH's (to SDK tools, for example). So if the compiler you want to use is mis-configured, but a compiler you did use pointed to a path with executables of the same name (but wrong version) you end up screwed. I guess the errors in such a case would be really hard to track.
I guess instead off caching, a better solution would be:
- you read what's currently in the PATH
- you check what needs to be prepended (so it is the folder looked into first)
- if it's not already in the PATH (at front) you put it there in front
So, assume you path is as follows:
C:\LALA
Your projects uses MinGW, so you need to prepend C:\MinGW\bin and C:\Tools\Bin, you end up in:
C:\MinGW\bin;C:\Tools\Bin;C:\LALA
Next time, you use MSVC, so you need to prepend C:\MSVC\bin and C:\WinSDK\Bin you end up in:
C:\MSVC\bin;C:\WinSDK\Bin;C:\MinGW\bin;C:\Tools\Bin;C:\LALA
Next time, you use MinGW again, you end up in:
C:\MinGW\bin;C:\Tools\Bin;C:\MSVC\bin;C:\WinSDK\Bin;C:\MinGW\bin;C:\Tools\Bin;C:\LALA
A clean-up step could remove any obsolete / path's appearing twice. I think there is even a nice wxWidgets class for this, namely wxPathList that helps a lot with the dirty work.
EDIT: One thing to consider for us are macros here btw!
That should be more or less what is done at the moment, see:Yes, I've seen that already... But the current code is (sorry to say that, but...) a mess. :(
http://svn.berlios.de/wsvn/codeblocks/?op=revision&rev=5344&peg=5344 (http://svn.berlios.de/wsvn/codeblocks/?op=revision&rev=5344&peg=5344)
Actually we should get a path that looks like:Working on that... got it soon... will post here... ;-)
masterpath;extrapaths(s);currentpath_without_masterpath_and_extrapath(s)
That's correct, it's grown over some years and was never cleaned up.That should be more or less what is done at the moment, see:Yes, I've seen that already... But the current code is (sorry to say that, but...) a mess. :(
http://svn.berlios.de/wsvn/codeblocks/?op=revision&rev=5344&peg=5344 (http://svn.berlios.de/wsvn/codeblocks/?op=revision&rev=5344&peg=5344)
It should work exactly like this at the moment, and it should be platform independent due to the use of wxPathList (without the need for us to care about different PATH-specs).Actually we should get a path that looks like:Working on that... got it soon... will post here... ;-)
masterpath;extrapaths(s);currentpath_without_masterpath_and_extrapath(s)
But the main question was/is:No, we don't - that's the root of the original issue.
do we really need to cache the systempath.
Can it be harmful not to do it (besides a probably misconfiguration by the user) ?
void CompilerGCC::SetupEnvironment()
{
if (!CompilerFactory::GetCompiler(m_CompilerId))
return;
m_EnvironmentMsg.Clear();
// look for valid compiler in path
wxString pathDummy;
if ( !wxGetEnv(_T("PATH"), &pathDummy) )
{
m_EnvironmentMsg = _("Could not read the PATH environment variable!\n"
"This can't be good. There may be problems running "
"system commands and the application might not behave "
"the way it was designed to...");
return;
}
Manager::Get()->GetLogManager()->DebugLog(_T("PATH environment:"));
Manager::Get()->GetLogManager()->DebugLog(pathDummy);
const wxString pathSep = wxFileName::GetPathSeparator(); // "\\" or "/"
// Pre-pend the compiler's master path
Compiler* compiler = CompilerFactory::GetCompiler(m_CompilerId);
if (!compiler)
return;
wxString masterPath = compiler->GetMasterPath();
Manager::Get()->GetMacrosManager()->ReplaceMacros(masterPath);
while (masterPath.Last() == '\\' || masterPath.Last() == '/')
masterPath.RemoveLast();
wxString cApp = compiler->GetPrograms().C;
wxArrayString extraPaths = compiler->GetExtraPaths();
wxString extraPathsBinPath(wxEmptyString);
// compile new PATH list:
wxPathList pathList;
if ( !masterPath.Trim().IsEmpty() ) // would be very bad, if it *is* empty
{
// pre-pend "master path", "master path\bin" and "extra path's"
pathList.Add(masterPath); // in case there is no "bin" sub-folder
pathList.Add(masterPath + pathSep + _T("bin"));
}
for (unsigned int i=0; i<extraPaths.GetCount(); ++i)
{
wxString extraPath = extraPaths[i];
Manager::Get()->GetMacrosManager()->ReplaceMacros(extraPath);
while (extraPath.Last() == '\\' || extraPath.Last() == '/')
extraPath.RemoveLast();
if (!extraPath.Trim().IsEmpty())
{
// Remember, if we found the C application in the extra path's:
if ( extraPathsBinPath.IsEmpty()
&& wxFileExists(extraPath + pathSep + cApp ) )
extraPathsBinPath = extraPath;
pathList.Add(extraPath);
}
}
// append what has already been in the PATH envvar
pathList.AddEnvList(_T("PATH"));
bool caseSens = !(platform::windows);
// try to locate the path to the C compiler:
// it seems, under Win32, the above command doesn't search in paths with spaces...
// look directly for the file in question in masterPath
wxString binPath = pathList.FindAbsoluteValidPath(cApp);
if ( binPath.IsEmpty()
|| (pathList.Index(wxPathOnly(binPath), caseSens) == wxNOT_FOUND) )
{
if (wxFileExists(masterPath + pathSep + _T("bin") + pathSep + cApp))
binPath = masterPath + pathSep + _T("bin");
else if (wxFileExists(masterPath + pathSep + cApp))
binPath = masterPath;
else if (!extraPathsBinPath.IsEmpty())
binPath = extraPathsBinPath;
}
else
binPath = wxPathOnly(binPath);
// Try again...
if ( binPath.IsEmpty()
|| (pathList.Index(wxPathOnly(binPath), caseSens)==wxNOT_FOUND) )
{
m_EnvironmentMsg << _("Can't find compiler executable in your search path's for ") << compiler->GetName() << _T('\n');
Manager::Get()->GetLogManager()->DebugLog(F(_T("Can't find compiler executable in your search path's (for %s)..."), compiler->GetName().wx_str()));
return; // failed to locate compiler executable in path's as provided
}
// Clean-up step: Locate duplicate entries and remove them
wxArrayString envPathArr;
for (size_t i=0; i<pathList.GetCount(); ++i)
{
wxString path = pathList[i].Trim();
while (path.Last() == '\\' || path.Last() == '/')
path.RemoveLast();
if ( !path.IsEmpty() )
{
path += pathSep;
if ( envPathArr.Index(path, caseSens)==wxNOT_FOUND )
envPathArr.Add(path);
}
}
// Compile the separator used to separate path's in envvars:
wxString path_app; // used in envvar to separate path's
if (platform::windows) path_app = _T(";"); else path_app = _T(":");
// Convert the PATH variable array into a string to apply.
wxString envPath(binPath + pathSep + path_app); // make sure the bin-path we found is in front
for (size_t i=0; i<envPathArr.GetCount(); ++i)
{
// Skip path to binary we added in front already:
if ( !envPathArr[i].IsSameAs(binPath + pathSep) )
envPath += (envPathArr[i] + path_app);
}
Manager::Get()->GetLogManager()->DebugLog(_T("Updating compiler PATH environment:"));
Manager::Get()->GetLogManager()->DebugLog(envPath);
wxSetEnv(_T("PATH"), envPath);
}
Comments?
// Style zealot hat onThese debug messages will (of-course) be commented later before commit. And then, if you want to see only one of these, you'll need this Manager::Get()->GetXXXManager() stuff... :-)
Calling Manager::Get()->GetXXXManager() on multiple lines looks wrong and ugly to me
// Style zealot hat off
If you want to do that, why don't you define some marco? :)I recall you have been the one that said macros are ugly. ;-)
I recall you have been the one that said macros are ugly. ;-)In that particular case it was pretty ugly :)
Using per file macros is the better way to do it:)Again: In this case the compiler has many functions and I usually don't want to debug all of them.
Leaving commented code is pretty ambiguous,I think it should be clear by:
because the reader of the code doesn't know the true intentions of the writer of the code.
I'll try myself, feel free to inspect and try, too...
Comments?
void CompilerGCC::SetupEnvironment()
{
Compiler* compiler = CompilerFactory::GetCompiler(m_CompilerId);
if (!compiler)
return;
wxString currentPath;
if ( !wxGetEnv(_T("PATH"), ¤tPath) )
{
InfoWindow::Display(_("Environment error"),
_("Could not read the PATH environment variable!\n"
"This can't be good. There may be problems running\n"
"system commands and the application might not behave\n"
"the way it was designed to..."),
15000, 3000);
return;
}
Manager::Get()->GetLogManager()->DebugLogError(_T("PATH environment:"));
Manager::Get()->GetLogManager()->DebugLogError(currentPath);
const wxString sep=platform::windows?_T(";"):_T(":");
const wxString pathSep = wxFileName::GetPathSeparator(); // "\\" or "/"
wxString cApp = compiler->GetPrograms().C;
wxArrayString extraPaths = compiler->GetExtraPaths();
wxString extraPathsBinPath(wxEmptyString);
// Get configured masterpath, expand macros and remove trailing seperators
wxString masterPath = compiler->GetMasterPath();
Manager::Get()->GetMacrosManager()->ReplaceMacros(masterPath);
while (masterPath.Last() == '\\' || masterPath.Last() == '/')
masterPath.RemoveLast();
// Prepend "masterpath/bin" and "masterpath"
wxPathList pathList;
if ( !masterPath.Trim().IsEmpty() ) // would be very bad, if it *is* empty
{
pathList.Add(masterPath + pathSep + _T("bin"));
pathList.Add(masterPath); // in case there is no "bin" sub-folder
}
// Get configured extrapath(s), expand macros and remove trailing seperators
for (size_t i=0; i<extraPaths.GetCount(); ++i)
{
wxString extraPath = extraPaths[i];
Manager::Get()->GetMacrosManager()->ReplaceMacros(extraPath);
while (extraPath.Last() == '\\' || extraPath.Last() == '/')
extraPath.RemoveLast();
if (!extraPath.Trim().IsEmpty())
{
// Remember, if we found the C application in the extra path's:
if ( extraPathsBinPath.IsEmpty()
&& wxFileExists(extraPath + pathSep + cApp ) )
extraPathsBinPath = extraPath;
pathList.Add(extraPath);
}
}
// 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"));
pathList.Add(pathArray);
bool caseSense = !(platform::windows);
// try to locate the path to the C compiler:
wxString binPath = pathList.FindAbsoluteValidPath(cApp);
// it seems, under Win32, the above command doesn't search in paths with spaces...
// look directly for the file in question in masterPath if it is not already found
if (binPath.IsEmpty()
|| (pathList.Index(wxPathOnly(binPath), caseSense) == wxNOT_FOUND) )
{
if (wxFileExists(masterPath + pathSep + _T("bin") + pathSep + cApp))
binPath = masterPath + pathSep + _T("bin");
else if (wxFileExists(masterPath + pathSep + cApp))
binPath = masterPath;
else if (!extraPathsBinPath.IsEmpty())
binPath = extraPathsBinPath;
}
else
binPath = wxPathOnly(binPath);
/* TODO (jens#1#): Is the above correct ?
Or should we search in the whole systempath (pathList in this case) for the executable ?*/
// Try again...
if ( binPath.IsEmpty() ||
(pathList.Index(wxPathOnly(binPath), caseSense) == wxNOT_FOUND) )
{
InfoWindow::Display(_("Environment error"),
_("Can't find compiler executable in your configured search path's for ") + compiler->GetName() + _T('\n'));
Manager::Get()->GetLogManager()->DebugLogError(F(_T("Can't find compiler executable in your configured search path's (for %s)..."), compiler->GetName().wx_str()));
return; // failed to locate compiler executable in path's as provided
}
// Convert the pathList into a string to apply.
wxString envPath(binPath); // make sure the bin-path we found is in front
// and remove it from pathList
pathList.Remove(binPath);
for (size_t i=0; i<pathList.GetCount(); ++i)
{
envPath += (sep + pathList[i] );
}
Manager::Get()->GetLogManager()->DebugLogError(_T("Updating compiler PATH environment:"));
Manager::Get()->GetLogManager()->DebugLogError(envPath);
wxSetEnv(_T("PATH"), envPath);
}
wxPathList pathArray;
pathArray.AddEnvList(_T("PATH"));
wxArrayString pathArray = GetArrayFromString(currentPath, sep);
Another one to test:Looks fine to me, too.
By the way (and off-topic here):Certainly tru. And (in fact) I did this already in my local copy literally since ages. I have a rather cleaned-up compiler plugin basically ready to commit for that purpose (that's also, why I can hardly provide true patches). So if there are no objections, I could step-by-step commit the changes.
I think we should remove all the makefile generation stuff from our sources, because it is not used anymore.
Yes, I think its correct. We should enforce that the user does a correct setup of the compiler. Otherwise we don't know, if we picked the right compiler if we search the whole system path. We may even find a wrong one, probably for another platform (avr) which we pick then as "correct". This can only go wrong and we will have a lot of trouble question in the forums hard to track.Code/* TODO (jens#1#): Is the above correct ?
Or should we search in the whole systempath (pathList in this case) for the executable? */