forked from qt-creator/qt-creator
ProjectExplorer: Use more Utils::Environment in GccToolChain
Change-Id: I46b1990b30e8086dfc7b59ff5bcdb8081c443eee Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -76,7 +76,7 @@ static const char supportedAbisKeyC[] = "ProjectExplorer.GccToolChain.SupportedA
|
|||||||
static const char parentToolChainIdKeyC[] = "ProjectExplorer.ClangToolChain.ParentToolChainId";
|
static const char parentToolChainIdKeyC[] = "ProjectExplorer.ClangToolChain.ParentToolChainId";
|
||||||
static const char binaryRegexp[] = "(?:^|-|\\b)(?:gcc|g\\+\\+|clang(?:\\+\\+)?)(?:-([\\d.]+))?$";
|
static const char binaryRegexp[] = "(?:^|-|\\b)(?:gcc|g\\+\\+|clang(?:\\+\\+)?)(?:-([\\d.]+))?$";
|
||||||
|
|
||||||
static QByteArray runGcc(const FilePath &gcc, const QStringList &arguments, const QStringList &env)
|
static QByteArray runGcc(const FilePath &gcc, const QStringList &arguments, const Environment &env)
|
||||||
{
|
{
|
||||||
if (!gcc.isExecutableFile())
|
if (!gcc.isExecutableFile())
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
@@ -101,7 +101,7 @@ static QByteArray runGcc(const FilePath &gcc, const QStringList &arguments, cons
|
|||||||
|
|
||||||
static ProjectExplorer::Macros gccPredefinedMacros(const FilePath &gcc,
|
static ProjectExplorer::Macros gccPredefinedMacros(const FilePath &gcc,
|
||||||
const QStringList &args,
|
const QStringList &args,
|
||||||
const QStringList &env)
|
const Environment &env)
|
||||||
{
|
{
|
||||||
QStringList arguments = args;
|
QStringList arguments = args;
|
||||||
arguments << "-";
|
arguments << "-";
|
||||||
@@ -125,8 +125,9 @@ static ProjectExplorer::Macros gccPredefinedMacros(const FilePath &gcc,
|
|||||||
return predefinedMacros;
|
return predefinedMacros;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderPaths GccToolChain::gccHeaderPaths(const FilePath &gcc, const QStringList &arguments,
|
HeaderPaths GccToolChain::gccHeaderPaths(const FilePath &gcc,
|
||||||
const QStringList &env)
|
const QStringList &arguments,
|
||||||
|
const Environment &env)
|
||||||
{
|
{
|
||||||
HeaderPaths builtInHeaderPaths;
|
HeaderPaths builtInHeaderPaths;
|
||||||
QByteArray line;
|
QByteArray line;
|
||||||
@@ -208,9 +209,10 @@ static Abis guessGccAbi(const QString &m, const ProjectExplorer::Macros ¯os)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GccToolChain::DetectedAbisResult guessGccAbi(const FilePath &path, const QStringList &env,
|
static GccToolChain::DetectedAbisResult guessGccAbi(const FilePath &path,
|
||||||
const ProjectExplorer::Macros ¯os,
|
const Environment &env,
|
||||||
const QStringList &extraArgs = QStringList())
|
const Macros ¯os,
|
||||||
|
const QStringList &extraArgs = {})
|
||||||
{
|
{
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return GccToolChain::DetectedAbisResult();
|
return GccToolChain::DetectedAbisResult();
|
||||||
@@ -227,7 +229,8 @@ static GccToolChain::DetectedAbisResult guessGccAbi(const FilePath &path, const
|
|||||||
return GccToolChain::DetectedAbisResult(guessGccAbi(machine, macros), machine);
|
return GccToolChain::DetectedAbisResult(guessGccAbi(machine, macros), machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString gccVersion(const FilePath &path, const QStringList &env,
|
static QString gccVersion(const FilePath &path,
|
||||||
|
const Environment &env,
|
||||||
const QStringList &extraArgs)
|
const QStringList &extraArgs)
|
||||||
{
|
{
|
||||||
QStringList arguments = extraArgs;
|
QStringList arguments = extraArgs;
|
||||||
@@ -235,8 +238,9 @@ static QString gccVersion(const FilePath &path, const QStringList &env,
|
|||||||
return QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed();
|
return QString::fromLocal8Bit(runGcc(path, arguments, env)).trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::FilePath gccInstallDir(const FilePath &path, const QStringList &env,
|
static FilePath gccInstallDir(const FilePath &path,
|
||||||
const QStringList &extraArgs = {})
|
const Environment &env,
|
||||||
|
const QStringList &extraArgs = {})
|
||||||
{
|
{
|
||||||
QStringList arguments = extraArgs;
|
QStringList arguments = extraArgs;
|
||||||
arguments << "-print-search-dirs";
|
arguments << "-print-search-dirs";
|
||||||
@@ -437,7 +441,7 @@ ToolChain::MacroInspectionRunner GccToolChain::createMacroInspectionRunner() con
|
|||||||
|
|
||||||
const Macros macros = gccPredefinedMacros(findLocalCompiler(compilerCommand, env),
|
const Macros macros = gccPredefinedMacros(findLocalCompiler(compilerCommand, env),
|
||||||
arguments,
|
arguments,
|
||||||
env.toStringList());
|
env);
|
||||||
|
|
||||||
const auto report = MacroInspectionReport{macros, languageVersion(lang, macros)};
|
const auto report = MacroInspectionReport{macros, languageVersion(lang, macros)};
|
||||||
macroCache->insert(arguments, report);
|
macroCache->insert(arguments, report);
|
||||||
@@ -583,7 +587,7 @@ HeaderPaths GccToolChain::builtInHeaderPaths(const Utils::Environment &env,
|
|||||||
|
|
||||||
HeaderPaths paths = gccHeaderPaths(findLocalCompiler(compilerCommand, env),
|
HeaderPaths paths = gccHeaderPaths(findLocalCompiler(compilerCommand, env),
|
||||||
arguments,
|
arguments,
|
||||||
env.toStringList());
|
env);
|
||||||
extraHeaderPathsFunction(paths);
|
extraHeaderPathsFunction(paths);
|
||||||
headerCache->insert(qMakePair(env, arguments), paths);
|
headerCache->insert(qMakePair(env, arguments), paths);
|
||||||
|
|
||||||
@@ -819,7 +823,7 @@ GccToolChain::DetectedAbisResult GccToolChain::detectSupportedAbis() const
|
|||||||
addToEnvironment(env);
|
addToEnvironment(env);
|
||||||
ProjectExplorer::Macros macros = createMacroInspectionRunner()({}).macros;
|
ProjectExplorer::Macros macros = createMacroInspectionRunner()({}).macros;
|
||||||
return guessGccAbi(findLocalCompiler(compilerCommand(), env),
|
return guessGccAbi(findLocalCompiler(compilerCommand(), env),
|
||||||
env.toStringList(),
|
env,
|
||||||
macros,
|
macros,
|
||||||
platformCodeGenFlags());
|
platformCodeGenFlags());
|
||||||
}
|
}
|
||||||
@@ -828,7 +832,7 @@ QString GccToolChain::detectVersion() const
|
|||||||
{
|
{
|
||||||
Environment env = Environment::systemEnvironment();
|
Environment env = Environment::systemEnvironment();
|
||||||
addToEnvironment(env);
|
addToEnvironment(env);
|
||||||
return gccVersion(findLocalCompiler(compilerCommand(), env), env.toStringList(),
|
return gccVersion(findLocalCompiler(compilerCommand(), env), env,
|
||||||
filteredFlags(platformCodeGenFlags(), true));
|
filteredFlags(platformCodeGenFlags(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,7 +840,7 @@ Utils::FilePath GccToolChain::detectInstallDir() const
|
|||||||
{
|
{
|
||||||
Environment env = Environment::systemEnvironment();
|
Environment env = Environment::systemEnvironment();
|
||||||
addToEnvironment(env);
|
addToEnvironment(env);
|
||||||
return gccInstallDir(findLocalCompiler(compilerCommand(), env), env.toStringList(),
|
return gccInstallDir(findLocalCompiler(compilerCommand(), env), env,
|
||||||
filteredFlags(platformCodeGenFlags(), true));
|
filteredFlags(platformCodeGenFlags(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1149,14 +1153,14 @@ QList<ToolChain *> GccToolChainFactory::autoDetectToolChain(const ToolChainDescr
|
|||||||
const FilePath localCompilerPath = findLocalCompiler(tcd.compilerPath, systemEnvironment);
|
const FilePath localCompilerPath = findLocalCompiler(tcd.compilerPath, systemEnvironment);
|
||||||
Macros macros
|
Macros macros
|
||||||
= gccPredefinedMacros(localCompilerPath, gccPredefinedMacrosOptions(tcd.language),
|
= gccPredefinedMacros(localCompilerPath, gccPredefinedMacrosOptions(tcd.language),
|
||||||
systemEnvironment.toStringList());
|
systemEnvironment);
|
||||||
if (macros.isEmpty())
|
if (macros.isEmpty())
|
||||||
return result;
|
return result;
|
||||||
const GccToolChain::DetectedAbisResult detectedAbis = guessGccAbi(localCompilerPath,
|
const GccToolChain::DetectedAbisResult detectedAbis = guessGccAbi(localCompilerPath,
|
||||||
systemEnvironment.toStringList(),
|
systemEnvironment,
|
||||||
macros);
|
macros);
|
||||||
const Utils::FilePath installDir = gccInstallDir(localCompilerPath,
|
const Utils::FilePath installDir = gccInstallDir(localCompilerPath,
|
||||||
systemEnvironment.toStringList());
|
systemEnvironment);
|
||||||
|
|
||||||
for (const Abi &abi : detectedAbis.supportedAbis) {
|
for (const Abi &abi : detectedAbis.supportedAbis) {
|
||||||
std::unique_ptr<GccToolChain> tc(dynamic_cast<GccToolChain *>(create()));
|
std::unique_ptr<GccToolChain> tc(dynamic_cast<GccToolChain *>(create()));
|
||||||
@@ -1306,8 +1310,8 @@ void GccToolChainConfigWidget::handleCompilerCommandChange()
|
|||||||
QStringList args = gccPredefinedMacrosOptions(Constants::CXX_LANGUAGE_ID)
|
QStringList args = gccPredefinedMacrosOptions(Constants::CXX_LANGUAGE_ID)
|
||||||
+ splitString(m_platformCodeGenFlagsLineEdit->text());
|
+ splitString(m_platformCodeGenFlagsLineEdit->text());
|
||||||
const FilePath localCompilerPath = findLocalCompiler(path, env);
|
const FilePath localCompilerPath = findLocalCompiler(path, env);
|
||||||
m_macros = gccPredefinedMacros(localCompilerPath, args, env.toStringList());
|
m_macros = gccPredefinedMacros(localCompilerPath, args, env);
|
||||||
abiList = guessGccAbi(localCompilerPath, env.toStringList(), m_macros,
|
abiList = guessGccAbi(localCompilerPath, env, m_macros,
|
||||||
splitString(m_platformCodeGenFlagsLineEdit->text())).supportedAbis;
|
splitString(m_platformCodeGenFlagsLineEdit->text())).supportedAbis;
|
||||||
}
|
}
|
||||||
m_abiWidget->setEnabled(haveCompiler);
|
m_abiWidget->setEnabled(haveCompiler);
|
||||||
|
@@ -153,8 +153,9 @@ protected:
|
|||||||
const QString &sysRoot,
|
const QString &sysRoot,
|
||||||
const QString &originalTargetTriple);
|
const QString &originalTargetTriple);
|
||||||
|
|
||||||
static HeaderPaths gccHeaderPaths(const Utils::FilePath &gcc, const QStringList &args,
|
static HeaderPaths gccHeaderPaths(const Utils::FilePath &gcc,
|
||||||
const QStringList &env);
|
const QStringList &args,
|
||||||
|
const Utils::Environment &env);
|
||||||
|
|
||||||
class WarningFlagAdder
|
class WarningFlagAdder
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user