forked from qt-creator/qt-creator
GccToolChain: Improve findLocalCompiler
Improve findLocalCompiler to better match the semantics of icecc/distcc. Task-number: QTCREATORBUG-18902 Change-Id: I06e7957d37bff449ce0188dd5d19e88d25f8e459 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -431,14 +431,32 @@ bool GccToolChain::isValid() const
|
|||||||
static Utils::FileName findLocalCompiler(const Utils::FileName &compilerPath,
|
static Utils::FileName findLocalCompiler(const Utils::FileName &compilerPath,
|
||||||
const Environment &env)
|
const Environment &env)
|
||||||
{
|
{
|
||||||
const Utils::FileName path = env.searchInPath(compilerPath.fileName(), QStringList(),
|
// Find the "real" compiler if icecc, distcc or similar are in use. Ignore ccache, since that
|
||||||
[](const QString &pathEntry) {
|
// is local already.
|
||||||
return !pathEntry.contains("icecc")
|
|
||||||
&& !pathEntry.contains("distcc");
|
|
||||||
});
|
|
||||||
|
|
||||||
QTC_ASSERT(!path.isEmpty(), return compilerPath);
|
// Get the path to the compiler, ignoring direct calls to icecc and distcc as we can not
|
||||||
return path;
|
// do anything about those.
|
||||||
|
const Utils::FileName compilerDir = compilerPath.parentDir();
|
||||||
|
const QString compilerDirString = compilerDir.toString();
|
||||||
|
if (!compilerDirString.contains("icecc") && !compilerDirString.contains("distcc"))
|
||||||
|
return compilerPath;
|
||||||
|
|
||||||
|
QStringList pathComponents = env.path();
|
||||||
|
auto it = std::find_if(pathComponents.begin(), pathComponents.end(),
|
||||||
|
[compilerDir](const QString &p) {
|
||||||
|
return Utils::FileName::fromString(p) == compilerDir;
|
||||||
|
});
|
||||||
|
if (it != pathComponents.end()) {
|
||||||
|
std::rotate(pathComponents.begin(), it, pathComponents.end());
|
||||||
|
pathComponents.removeFirst(); // remove directory of compilerPath
|
||||||
|
// No need to put it at the end again, it is in PATH anyway...
|
||||||
|
}
|
||||||
|
|
||||||
|
// This effectively searches the PATH twice, once via pathComponents and once via PATH itself:
|
||||||
|
// searchInPath filters duplicates, so that will not hurt.
|
||||||
|
const Utils::FileName path = env.searchInPath(compilerPath.fileName(), pathComponents);
|
||||||
|
|
||||||
|
return path.isEmpty() ? compilerPath : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolChain::PredefinedMacrosRunner GccToolChain::createPredefinedMacrosRunner() const
|
ToolChain::PredefinedMacrosRunner GccToolChain::createPredefinedMacrosRunner() const
|
||||||
|
Reference in New Issue
Block a user