Commit ef65ce48 authored by Sergey Shambir's avatar Sergey Shambir Committed by Tobias Hunger
Browse files

Fixed caching when reading gcc predefined macros



Predefined macro set will be renewed correctly in qmake subprojects
or when flags was changed and project file resaved

Change-Id: Iffba9176083f5d8e5fbb39d2c02d48cef4a28e71
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 072c3109
......@@ -149,6 +149,8 @@ static QByteArray gccPredefinedMacros(const FileName &gcc, const QStringList &ar
return predefinedMacros;
}
const int GccToolChain::PREDEFINED_MACROS_CACHE_SIZE = 16;
QList<HeaderPath> GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList &args,
const QStringList &env, const FileName &sysrootPath)
{
......@@ -381,15 +383,42 @@ bool GccToolChain::isValid() const
return !m_compilerCommand.isNull();
}
/**
* @brief Asks compiler for set of predefined macros
* @param cxxflags - compiler flags collected from project settings
* @return defines list, one per line, e.g. "#define __GXX_WEAK__ 1"
*
* @note changing compiler flags sometimes changes macros set, e.g. -fopenmp
* adds _OPENMP macro, for full list of macro search by word "when" on this page:
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
*/
QByteArray GccToolChain::predefinedMacros(const QStringList &cxxflags) const
{
if (m_predefinedMacros.isEmpty()) {
// Using a clean environment breaks ccache/distcc/etc.
Environment env = Environment::systemEnvironment();
addToEnvironment(env);
m_predefinedMacros = gccPredefinedMacros(m_compilerCommand, cxxflags, env.toStringList());
}
return m_predefinedMacros;
typedef QPair<QStringList, QByteArray> CacheItem;
for (GccCache::iterator it = m_predefinedMacros.begin(); it != m_predefinedMacros.end(); ++it)
if (it->first == cxxflags) {
// Increase cached item priority
CacheItem pair = *it;
m_predefinedMacros.erase(it);
m_predefinedMacros.push_back(pair);
return pair.second;
}
CacheItem runResults;
runResults.first = cxxflags;
// Using a clean environment breaks ccache/distcc/etc.
Environment env = Environment::systemEnvironment();
addToEnvironment(env);
runResults.second = gccPredefinedMacros(m_compilerCommand, cxxflags, env.toStringList());
m_predefinedMacros.push_back(runResults);
if (m_predefinedMacros.size() > PREDEFINED_MACROS_CACHE_SIZE)
m_predefinedMacros.pop_front();
return runResults.second;
}
ToolChain::CompilerFlags GccToolChain::compilerFlags(const QStringList &cxxflags) const
......
......@@ -82,6 +82,8 @@ public:
ToolChain *clone() const;
protected:
typedef QList<QPair<QStringList, QByteArray> > GccCache;
GccToolChain(const QString &id, bool autodetect);
GccToolChain(const GccToolChain &);
......@@ -92,7 +94,8 @@ protected:
static QList<HeaderPath> gccHeaderPaths(const Utils::FileName &gcc, const QStringList &args, const QStringList &env, const Utils::FileName &sysrootPath);
mutable QByteArray m_predefinedMacros;
static const int PREDEFINED_MACROS_CACHE_SIZE;
mutable GccCache m_predefinedMacros;
private:
GccToolChain(bool autodetect);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment