ProjectExplorer: Rename compiler includes from System to BuiltIn

System include are those used with -isystem keyword, built-in
includes on the other hand come from compiler and always
follow in the end of the include list (after system includes).

Change-Id: I95c2fec36d2e5b43f014fe0a88d59c6769edfa1f
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-09-17 11:29:32 +02:00
parent 3170d05087
commit 0bd095aa45
21 changed files with 89 additions and 80 deletions

View File

@@ -106,7 +106,7 @@ static QString getArch(const QString &triple)
// Paths added here are those that were used by qmake. They were taken from
// *qtsource*/qtbase/mkspecs/common/android-base-head.conf
// Adding them here allows us to use them for all build systems.
static void addSystemHeaderPaths(ProjectExplorer::HeaderPaths &paths,
static void addBuiltInHeaderPaths(ProjectExplorer::HeaderPaths &paths,
const QString &triple, const QString &version)
{
const Utils::FileName ndkPath = AndroidConfigurations::currentConfig().ndkLocation();
@@ -120,24 +120,24 @@ static void addSystemHeaderPaths(ProjectExplorer::HeaderPaths &paths,
Utils::FileName includePath = stdcppPath;
Utils::FileName cppLibsPath = stdcppPath;
cppLibsPath.appendPath("libs/" + getArch(triple) + "/include/");
paths.prepend({cppLibsPath.toString(), ProjectExplorer::HeaderPathType::System});
paths.prepend({cppLibsPath.toString(), ProjectExplorer::HeaderPathType::BuiltIn});
includePath.appendPath("include/");
paths.prepend({includePath.toString(), ProjectExplorer::HeaderPathType::System});
paths.prepend({includePath.toString(), ProjectExplorer::HeaderPathType::BuiltIn});
paths.prepend({ndkPath.toString() + "/sysroot/usr/include/" + triple,
ProjectExplorer::HeaderPathType::System});
ProjectExplorer::HeaderPathType::BuiltIn});
paths.prepend({ndkPath.toString() + "/sysroot/usr/include",
ProjectExplorer::HeaderPathType::System});
ProjectExplorer::HeaderPathType::BuiltIn});
}
AndroidToolChain::SystemHeaderPathsRunner AndroidToolChain::createSystemHeaderPathsRunner() const
AndroidToolChain::BuiltInHeaderPathsRunner AndroidToolChain::createBuiltInHeaderPathsRunner() const
{
const QString triple = originalTargetTriple();
const QString version = this->version();
initExtraHeaderPathsFunction([triple, version] (HeaderPaths &paths) {
addSystemHeaderPaths(paths, triple, version);
addBuiltInHeaderPaths(paths, triple, version);
});
return GccToolChain::createSystemHeaderPathsRunner();
return GccToolChain::createBuiltInHeaderPathsRunner();
}
QString AndroidToolChain::typeDisplayName() const

View File

@@ -58,7 +58,7 @@ public:
bool isSecondaryToolChain() const;
void setSecondaryToolChain(bool b);
SystemHeaderPathsRunner createSystemHeaderPathsRunner() const override;
BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const override;
protected:
DetectedAbisResult detectSupportedAbis() const override;

View File

@@ -334,7 +334,7 @@ static void processCMakeIncludes(const CMakeBuildTarget &cbt, const ToolChain *t
if (!tc)
return;
foreach (const HeaderPath &hp, tc->systemHeaderPaths(flags, sysroot))
foreach (const HeaderPath &hp, tc->builtInHeaderPaths(flags, sysroot))
tcIncludes.insert(FileName::fromString(hp.path));
foreach (const FileName &i, cbt.includeFiles) {
if (!tcIncludes.contains(i))

View File

@@ -200,7 +200,9 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
{
using ProjectExplorer::HeaderPathType;
QStringList result;
QStringList includes;
QStringList systemIncludes;
QStringList builtInIncludes;
for (const ProjectExplorer::HeaderPath &headerPath : qAsConst(m_projectPart.headerPaths)) {
if (headerPath.path.isEmpty())
@@ -209,29 +211,33 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
if (excludeHeaderPath(headerPath.path))
continue;
QString prefix;
Utils::FileName path;
switch (headerPath.type) {
case HeaderPathType::Framework:
prefix = QLatin1String("-F");
break;
case HeaderPathType::System:
prefix = m_useSystemHeader == UseSystemHeader::No
? QLatin1String("-I")
: QLatin1String("-isystem");
includes.append("-F");
includes.append(QDir::toNativeSeparators(headerPath.path));
break;
default: // This shouldn't happen, but let's be nice..:
// intentional fall-through:
case HeaderPathType::User:
prefix = includeDirOptionForPath(headerPath.path);
includes.append(includeDirOptionForPath(headerPath.path));
includes.append(QDir::toNativeSeparators(headerPath.path));
break;
case HeaderPathType::BuiltIn:
builtInIncludes.append("-isystem");
builtInIncludes.append(QDir::toNativeSeparators(headerPath.path));
break;
case HeaderPathType::System:
systemIncludes.append(m_useSystemHeader == UseSystemHeader::No
? QLatin1String("-I")
: QLatin1String("-isystem"));
systemIncludes.append(QDir::toNativeSeparators(headerPath.path));
break;
}
result.append(prefix);
result.append(QDir::toNativeSeparators(headerPath.path));
}
m_options.append(result);
m_options.append(includes);
m_options.append(systemIncludes);
m_options.append(builtInIncludes);
}
void CompilerOptionsBuilder::addPrecompiledHeaderOptions(PchUsage pchUsage)

View File

@@ -96,6 +96,7 @@ QString Utils::toString(ProjectExplorer::HeaderPathType type)
CASE_LANGUAGEVERSION(User);
CASE_LANGUAGEVERSION(System);
CASE_LANGUAGEVERSION(Framework);
CASE_LANGUAGEVERSION(BuiltIn);
// no default to get a compiler warning if anything is added
}
#undef CASE_LANGUAGEVERSION
@@ -472,6 +473,7 @@ static void printIncludeType(QTextStream &out, ProjectExplorer::HeaderPathType t
case HeaderPathType::User: out << "(user include path)"; break;
case HeaderPathType::System: out << "(system include path)"; break;
case HeaderPathType::Framework: out << "(framework path)"; break;
case HeaderPathType::BuiltIn: out << "(built-in include path)"; break;
}
}

View File

@@ -116,12 +116,12 @@ private:
if (!m_tcInfo.headerPathsRunner)
return; // No compiler set in kit.
const ProjectExplorer::HeaderPaths systemHeaderPaths
const ProjectExplorer::HeaderPaths builtInHeaderPaths
= m_tcInfo.headerPathsRunner(m_flags.commandLineFlags,
m_tcInfo.sysRootPath);
ProjectExplorer::HeaderPaths &headerPaths = m_projectPart.headerPaths;
for (const ProjectExplorer::HeaderPath &header : systemHeaderPaths) {
for (const ProjectExplorer::HeaderPath &header : builtInHeaderPaths) {
const ProjectExplorer::HeaderPath headerPath{header.path, header.type};
if (!headerPaths.contains(headerPath))
headerPaths.push_back(headerPath);

View File

@@ -138,10 +138,10 @@ void CppSourceProcessor::setHeaderPaths(const ProjectExplorer::HeaderPaths &head
for (int i = 0, ei = headerPaths.size(); i < ei; ++i) {
const ProjectExplorer::HeaderPath &path = headerPaths.at(i);
if (path.type == HeaderPathType::User || path.type == HeaderPathType::System)
m_headerPaths.append({cleanPath(path.path), path.type});
else
if (path.type == HeaderPathType::Framework )
addFrameworkPath(path);
else
m_headerPaths.append({cleanPath(path.path), path.type});
}
}

View File

@@ -47,7 +47,7 @@ ToolChainInfo::ToolChainInfo(const ProjectExplorer::ToolChain *toolChain,
// ...and save the potentially expensive operations for later so that
// they can be run from a worker thread.
sysRootPath = ProjectExplorer::SysRootKitInformation::sysRoot(kit).toString();
headerPathsRunner = toolChain->createSystemHeaderPathsRunner();
headerPathsRunner = toolChain->createBuiltInHeaderPathsRunner();
predefinedMacrosRunner = toolChain->createPredefinedMacrosRunner();
}
}

View File

@@ -57,7 +57,7 @@ public:
QStringList extraCodeModelFlags;
QString sysRootPath; // For headerPathsRunner.
ProjectExplorer::ToolChain::SystemHeaderPathsRunner headerPathsRunner;
ProjectExplorer::ToolChain::BuiltInHeaderPathsRunner headerPathsRunner;
ProjectExplorer::ToolChain::PredefinedMacrosRunner predefinedMacrosRunner;
};

View File

@@ -97,12 +97,12 @@ WarningFlags NimToolChain::warningFlags(const QStringList &) const
return WarningFlags::NoWarnings;
}
ToolChain::SystemHeaderPathsRunner NimToolChain::createSystemHeaderPathsRunner() const
ToolChain::BuiltInHeaderPathsRunner NimToolChain::createBuiltInHeaderPathsRunner() const
{
return ToolChain::SystemHeaderPathsRunner();
return ToolChain::BuiltInHeaderPathsRunner();
}
HeaderPaths NimToolChain::systemHeaderPaths(const QStringList &, const FileName &) const
HeaderPaths NimToolChain::builtInHeaderPaths(const QStringList &, const FileName &) const
{
return {};
}

View File

@@ -45,8 +45,8 @@ public:
CompilerFlags compilerFlags(const QStringList &flags) const final;
ProjectExplorer::WarningFlags warningFlags(const QStringList &flags) const final;
SystemHeaderPathsRunner createSystemHeaderPathsRunner() const override;
ProjectExplorer::HeaderPaths systemHeaderPaths(const QStringList &flags,
BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const override;
ProjectExplorer::HeaderPaths builtInHeaderPaths(const QStringList &flags,
const Utils::FileName &sysRoot) const final;
void addToEnvironment(Utils::Environment &env) const final;
QString makeCommand(const Utils::Environment &env) const final;

View File

@@ -210,7 +210,7 @@ WarningFlags AbstractMsvcToolChain::warningFlags(const QStringList &cflags) cons
return flags;
}
ToolChain::SystemHeaderPathsRunner AbstractMsvcToolChain::createSystemHeaderPathsRunner() const
ToolChain::BuiltInHeaderPathsRunner AbstractMsvcToolChain::createBuiltInHeaderPathsRunner() const
{
Utils::Environment env(m_lastEnvironment);
addToEnvironment(env);
@@ -219,16 +219,16 @@ ToolChain::SystemHeaderPathsRunner AbstractMsvcToolChain::createSystemHeaderPath
QMutexLocker locker(m_headerPathsMutex);
if (m_headerPaths.isEmpty()) {
foreach (const QString &path, env.value(QLatin1String("INCLUDE")).split(QLatin1Char(';')))
m_headerPaths.append({path, HeaderPathType::System});
m_headerPaths.append({path, HeaderPathType::BuiltIn});
}
return m_headerPaths;
};
}
HeaderPaths AbstractMsvcToolChain::systemHeaderPaths(const QStringList &cxxflags,
HeaderPaths AbstractMsvcToolChain::builtInHeaderPaths(const QStringList &cxxflags,
const Utils::FileName &sysRoot) const
{
return createSystemHeaderPathsRunner()(cxxflags, sysRoot.toString());
return createBuiltInHeaderPathsRunner()(cxxflags, sysRoot.toString());
}
void AbstractMsvcToolChain::addToEnvironment(Utils::Environment &env) const

View File

@@ -57,8 +57,8 @@ public:
Macros predefinedMacros(const QStringList &cxxflags) const override;
CompilerFlags compilerFlags(const QStringList &cxxflags) const override;
WarningFlags warningFlags(const QStringList &cflags) const override;
SystemHeaderPathsRunner createSystemHeaderPathsRunner() const override;
HeaderPaths systemHeaderPaths(const QStringList &cxxflags,
BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const override;
HeaderPaths builtInHeaderPaths(const QStringList &cxxflags,
const Utils::FileName &sysRoot) const override;
void addToEnvironment(Utils::Environment &env) const override;

View File

@@ -166,27 +166,27 @@ void CustomToolChain::setPredefinedMacros(const Macros &macros)
toolChainUpdated();
}
ToolChain::SystemHeaderPathsRunner CustomToolChain::createSystemHeaderPathsRunner() const
ToolChain::BuiltInHeaderPathsRunner CustomToolChain::createBuiltInHeaderPathsRunner() const
{
const HeaderPaths systemHeaderPaths = m_systemHeaderPaths;
const HeaderPaths builtInHeaderPaths = m_builtInHeaderPaths;
// This runner must be thread-safe!
return [systemHeaderPaths](const QStringList &cxxFlags, const QString &) {
return [builtInHeaderPaths](const QStringList &cxxFlags, const QString &) {
HeaderPaths flagHeaderPaths;
for (const QString &cxxFlag : cxxFlags) {
if (cxxFlag.startsWith(QLatin1String("-I"))) {
flagHeaderPaths.push_back({cxxFlag.mid(2).trimmed(), HeaderPathType::System});
flagHeaderPaths.push_back({cxxFlag.mid(2).trimmed(), HeaderPathType::BuiltIn});
}
}
return systemHeaderPaths + flagHeaderPaths;
return builtInHeaderPaths + flagHeaderPaths;
};
}
HeaderPaths CustomToolChain::systemHeaderPaths(const QStringList &cxxFlags,
HeaderPaths CustomToolChain::builtInHeaderPaths(const QStringList &cxxFlags,
const FileName &fileName) const
{
return createSystemHeaderPathsRunner()(cxxFlags, fileName.toString());
return createBuiltInHeaderPathsRunner()(cxxFlags, fileName.toString());
}
void CustomToolChain::addToEnvironment(Environment &env) const
@@ -222,18 +222,18 @@ IOutputParser *CustomToolChain::outputParser() const
QStringList CustomToolChain::headerPathsList() const
{
return Utils::transform<QList>(m_systemHeaderPaths, &HeaderPath::path);
return Utils::transform<QList>(m_builtInHeaderPaths, &HeaderPath::path);
}
void CustomToolChain::setHeaderPaths(const QStringList &list)
{
HeaderPaths tmp = Utils::transform<QVector>(list, [](const QString &headerPath) {
return HeaderPath(headerPath.trimmed(), HeaderPathType::System);
return HeaderPath(headerPath.trimmed(), HeaderPathType::BuiltIn);
});
if (m_systemHeaderPaths == tmp)
if (m_builtInHeaderPaths == tmp)
return;
m_systemHeaderPaths = tmp;
m_builtInHeaderPaths = tmp;
toolChainUpdated();
}
@@ -372,7 +372,7 @@ bool CustomToolChain::operator ==(const ToolChain &other) const
&& m_makeCommand == customTc->m_makeCommand
&& m_targetAbi == customTc->m_targetAbi
&& m_predefinedMacros == customTc->m_predefinedMacros
&& m_systemHeaderPaths == customTc->m_systemHeaderPaths;
&& m_builtInHeaderPaths == customTc->m_builtInHeaderPaths;
}
Core::Id CustomToolChain::outputParserId() const

View File

@@ -78,8 +78,8 @@ public:
const Macros &rawPredefinedMacros() const;
void setPredefinedMacros(const Macros &macros);
SystemHeaderPathsRunner createSystemHeaderPathsRunner() const override;
HeaderPaths systemHeaderPaths(const QStringList &cxxFlags,
BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const override;
HeaderPaths builtInHeaderPaths(const QStringList &cxxFlags,
const Utils::FileName &) const override;
void addToEnvironment(Utils::Environment &env) const override;
Utils::FileNameList suggestedMkspecList() const override;
@@ -125,7 +125,7 @@ private:
Abi m_targetAbi;
Macros m_predefinedMacros;
HeaderPaths m_systemHeaderPaths;
HeaderPaths m_builtInHeaderPaths;
QStringList m_cxx11Flags;
Utils::FileNameList m_mkspecs;

View File

@@ -139,7 +139,7 @@ static ProjectExplorer::Macros gccPredefinedMacros(const FileName &gcc,
HeaderPaths GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList &arguments,
const QStringList &env)
{
HeaderPaths systemHeaderPaths;
HeaderPaths builtInHeaderPaths;
QByteArray line;
QByteArray data = runGcc(gcc, arguments, env);
QBuffer cpp(&data);
@@ -155,7 +155,7 @@ HeaderPaths GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList
while (cpp.canReadLine()) {
line = cpp.readLine();
if (line.startsWith("#include")) {
kind = HeaderPathType::System;
kind = HeaderPathType::BuiltIn;
} else if (! line.isEmpty() && QChar(line.at(0)).isSpace()) {
HeaderPathType thisHeaderKind = kind;
@@ -168,7 +168,7 @@ HeaderPaths GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList
}
const QString headerPath = QFileInfo(QFile::decodeName(line)).canonicalFilePath();
systemHeaderPaths.append({headerPath, thisHeaderKind});
builtInHeaderPaths.append({headerPath, thisHeaderKind});
} else if (line.startsWith("End of search list.")) {
break;
} else {
@@ -176,7 +176,7 @@ HeaderPaths GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList
}
}
}
return systemHeaderPaths;
return builtInHeaderPaths;
}
void GccToolChain::toolChainUpdated()
@@ -621,7 +621,7 @@ void GccToolChain::initExtraHeaderPathsFunction(ExtraHeaderPathsFunction &&extra
m_extraHeaderPathsFunction = std::move(extraHeaderPathsFunction);
}
ToolChain::SystemHeaderPathsRunner GccToolChain::createSystemHeaderPathsRunner() const
ToolChain::BuiltInHeaderPathsRunner GccToolChain::createBuiltInHeaderPathsRunner() const
{
// Using a clean environment breaks ccache/distcc/etc.
Environment env = Environment::systemEnvironment();
@@ -663,10 +663,10 @@ ToolChain::SystemHeaderPathsRunner GccToolChain::createSystemHeaderPathsRunner()
};
}
HeaderPaths GccToolChain::systemHeaderPaths(const QStringList &flags,
HeaderPaths GccToolChain::builtInHeaderPaths(const QStringList &flags,
const FileName &sysRoot) const
{
return createSystemHeaderPathsRunner()(flags, sysRoot.toString());
return createBuiltInHeaderPathsRunner()(flags, sysRoot.toString());
}
void GccToolChain::addCommandPathToEnvironment(const FileName &command, Environment &env)

View File

@@ -146,8 +146,8 @@ public:
PredefinedMacrosRunner createPredefinedMacrosRunner() const override;
Macros predefinedMacros(const QStringList &cxxflags) const override;
SystemHeaderPathsRunner createSystemHeaderPathsRunner() const override;
HeaderPaths systemHeaderPaths(const QStringList &flags,
BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const override;
HeaderPaths builtInHeaderPaths(const QStringList &flags,
const Utils::FileName &sysRoot) const override;
void addToEnvironment(Utils::Environment &env) const override;

View File

@@ -32,8 +32,9 @@ namespace ProjectExplorer {
enum class HeaderPathType {
User,
BuiltIn,
System,
Framework
Framework,
};
class HeaderPath

View File

@@ -131,11 +131,11 @@ public:
virtual PredefinedMacrosRunner createPredefinedMacrosRunner() const = 0;
virtual Macros predefinedMacros(const QStringList &cxxflags) const = 0;
// A SystemHeaderPathsRunner is created in the ui thread and runs in another thread.
using SystemHeaderPathsRunner = std::function<HeaderPaths(const QStringList &cxxflags,
// A BuiltInHeaderPathsRunner is created in the ui thread and runs in another thread.
using BuiltInHeaderPathsRunner = std::function<HeaderPaths(const QStringList &cxxflags,
const QString &sysRoot)>;
virtual SystemHeaderPathsRunner createSystemHeaderPathsRunner() const = 0;
virtual HeaderPaths systemHeaderPaths(const QStringList &cxxflags,
virtual BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const = 0;
virtual HeaderPaths builtInHeaderPaths(const QStringList &cxxflags,
const Utils::FileName &sysRoot) const = 0;
virtual void addToEnvironment(Utils::Environment &env) const = 0;
virtual QString makeCommand(const Utils::Environment &env) const = 0;

View File

@@ -312,8 +312,8 @@ public:
Macros predefinedMacros(const QStringList &cxxflags) const override { Q_UNUSED(cxxflags); return Macros(); }
CompilerFlags compilerFlags(const QStringList &cxxflags) const override { Q_UNUSED(cxxflags); return NoFlags; }
WarningFlags warningFlags(const QStringList &cflags) const override { Q_UNUSED(cflags); return WarningFlags::NoWarnings; }
SystemHeaderPathsRunner createSystemHeaderPathsRunner() const override { return SystemHeaderPathsRunner(); }
HeaderPaths systemHeaderPaths(const QStringList &cxxflags, const FileName &sysRoot) const override
BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const override { return BuiltInHeaderPathsRunner(); }
HeaderPaths builtInHeaderPaths(const QStringList &cxxflags, const FileName &sysRoot) const override
{ Q_UNUSED(cxxflags); Q_UNUSED(sysRoot); return {}; }
void addToEnvironment(Environment &env) const override { Q_UNUSED(env); }
QString makeCommand(const Environment &env) const override { Q_UNUSED(env); return QString("make"); }

View File

@@ -57,8 +57,8 @@ public:
Abi targetAbi() const { return Abi(); }
using SystemHeaderPathsRunner = std::function<HeaderPaths(const QStringList &cxxflags, const QString &sysRoot)>;
virtual SystemHeaderPathsRunner createSystemHeaderPathsRunner() const { return SystemHeaderPathsRunner(); }
using BuiltInHeaderPathsRunner = std::function<HeaderPaths(const QStringList &cxxflags, const QString &sysRoot)>;
virtual BuiltInHeaderPathsRunner createBuiltInHeaderPathsRunner() const { return BuiltInHeaderPathsRunner(); }
using PredefinedMacrosRunner = std::function<Macros(const QStringList &cxxflags)>;
virtual PredefinedMacrosRunner createPredefinedMacrosRunner() const { return PredefinedMacrosRunner(); }