diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2019-03-13 14:40:12 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2019-03-13 13:02:00 +0000 |
commit | 852fad87df558c1d08e6c8c83ebb2a26ff8f15e0 (patch) | |
tree | 1cc18a67cb024844996e70215b9e5d129593a214 /src/plugins/baremetal | |
parent | 827e0d56b693371d36f95ed4943fd00fcd335fc0 (diff) |
bare-metal: Search the include paths of KEIL toolchain
Seems, the KEIL compiler has not an explicitly options to show
a list of system include paths. So, we just enumerate the exists
include paths inside of an installed toolkit directory.
Change-Id: Ib088a80de9dbc3646238cb5e1a2dc47d25521790
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/baremetal')
-rw-r--r-- | src/plugins/baremetal/keiltoolchain.cpp | 71 | ||||
-rw-r--r-- | src/plugins/baremetal/keiltoolchain.h | 4 |
2 files changed, 65 insertions, 10 deletions
diff --git a/src/plugins/baremetal/keiltoolchain.cpp b/src/plugins/baremetal/keiltoolchain.cpp index 2bc3e0fd1cb..94cb1b56bab 100644 --- a/src/plugins/baremetal/keiltoolchain.cpp +++ b/src/plugins/baremetal/keiltoolchain.cpp @@ -66,6 +66,17 @@ static bool isCompilerExists(const FileName &compilerPath) return fi.exists() && fi.isExecutable() && fi.isFile(); } +static Abi::Architecture guessArchitecture(const FileName &compilerPath) +{ + const QFileInfo fi = compilerPath.toFileInfo(); + const QString bn = fi.baseName().toLower(); + if (bn == "c51" || bn == "cx51") + return Abi::Architecture::Mcs51Architecture; + if (bn == "armcc") + return Abi::Architecture::ArmArchitecture; + return Abi::Architecture::UnknownArchitecture; +} + // Note: The KEIL 8051 compiler does not support the predefined // macros dumping. So, we do it with following trick where we try // to compile a temporary file and to parse the console output. @@ -138,13 +149,40 @@ static Macros dumpPredefinedMacros(const FileName &compiler, const QStringList & if (compiler.isEmpty() || !compiler.toFileInfo().isExecutable()) return {}; - const QFileInfo fi(compiler.toString()); - const QString bn = fi.baseName().toLower(); - // Check for C51 compiler first. - if (bn.contains("c51") || bn.contains("cx51")) + const Abi::Architecture arch = guessArchitecture(compiler); + switch (arch) { + case Abi::Architecture::Mcs51Architecture: return dumpC51PredefinedMacros(compiler, env); + case Abi::Architecture::ArmArchitecture: + return dumpArmPredefinedMacros(compiler, env); + default: + return {}; + } +} + +static HeaderPaths dumpHeaderPaths(const FileName &compiler) +{ + if (!compiler.exists()) + return {}; - return dumpArmPredefinedMacros(compiler, env); + QDir toolkitDir(compiler.parentDir().toString()); + if (!toolkitDir.cdUp()) + return {}; + + HeaderPaths headerPaths; + + const Abi::Architecture arch = guessArchitecture(compiler); + if (arch == Abi::Architecture::Mcs51Architecture) { + QDir includeDir(toolkitDir); + if (includeDir.cd("inc")) + headerPaths.push_back({includeDir.canonicalPath(), HeaderPathType::BuiltIn}); + } else if (arch == Abi::Architecture::ArmArchitecture) { + QDir includeDir(toolkitDir); + if (includeDir.cd("include")) + headerPaths.push_back({includeDir.canonicalPath(), HeaderPathType::BuiltIn}); + } + + return headerPaths; } static Abi::Architecture guessArchitecture(const Macros ¯os) @@ -199,7 +237,8 @@ static QString buildDisplayName(Abi::Architecture arch, Core::Id language, KeilToolchain::KeilToolchain(Detection d) : ToolChain(Constants::KEIL_TOOLCHAIN_TYPEID, d), - m_predefinedMacrosCache(std::make_shared<Cache<MacroInspectionReport, 64>>()) + m_predefinedMacrosCache(std::make_shared<Cache<MacroInspectionReport, 64>>()), + m_headerPathsCache(std::make_shared<HeaderPathsCache>()) { } KeilToolchain::KeilToolchain(Core::Id language, Detection d) : @@ -271,15 +310,26 @@ WarningFlags KeilToolchain::warningFlags(const QStringList &cxxflags) const ToolChain::BuiltInHeaderPathsRunner KeilToolchain::createBuiltInHeaderPathsRunner() const { - return {}; + const Utils::FileName compilerCommand = m_compilerCommand; + + HeaderPathsCachePtr headerPathsCache = m_headerPathsCache; + + return [compilerCommand, headerPathsCache] + (const QStringList &flags, const QString &fileName) { + Q_UNUSED(flags) + Q_UNUSED(fileName) + + const HeaderPaths paths = dumpHeaderPaths(compilerCommand); + headerPathsCache->insert({}, paths); + + return paths; + }; } HeaderPaths KeilToolchain::builtInHeaderPaths(const QStringList &cxxFlags, const FileName &fileName) const { - Q_UNUSED(cxxFlags) - Q_UNUSED(fileName) - return {}; + return createBuiltInHeaderPathsRunner()(cxxFlags, fileName.toString()); } void KeilToolchain::addToEnvironment(Environment &env) const @@ -355,6 +405,7 @@ ToolChain *KeilToolchain::clone() const void KeilToolchain::toolChainUpdated() { m_predefinedMacrosCache->invalidate(); + m_headerPathsCache->invalidate(); ToolChain::toolChainUpdated(); } diff --git a/src/plugins/baremetal/keiltoolchain.h b/src/plugins/baremetal/keiltoolchain.h index f71c8d1e803..5ffb66a5b96 100644 --- a/src/plugins/baremetal/keiltoolchain.h +++ b/src/plugins/baremetal/keiltoolchain.h @@ -101,6 +101,10 @@ private: using MacrosCache = std::shared_ptr<ProjectExplorer::Cache<MacroInspectionReport, 64>>; mutable MacrosCache m_predefinedMacrosCache; + using HeaderPathsCache = ProjectExplorer::Cache<ProjectExplorer::HeaderPaths>; + using HeaderPathsCachePtr = std::shared_ptr<HeaderPathsCache>; + mutable HeaderPathsCachePtr m_headerPathsCache; + friend class KeilToolchainFactory; friend class KeilToolchainConfigWidget; }; |