tizentoolchain.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Jarek Pelczar <jpelczar@gmail.com>
  4. ** Copyright (C) 2014 Tomasz Olszak <olszak.tomasz@gmail.com>
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Digia. For licensing terms and
  13. ** conditions see http://qt.digia.com/licensing. For further information
  14. ** use the contact form at http://qt.digia.com/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 as published by the Free Software
  19. ** Foundation and appearing in the file LICENSE.LGPL included in the
  20. ** packaging of this file. Please review the following information to
  21. ** ensure the GNU Lesser General Public License version 2.1 requirements
  22. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  23. **
  24. ** In addition, as a special exception, Digia gives you certain additional
  25. ** rights. These rights are described in the Digia Qt LGPL Exception
  26. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  27. **
  28. ****************************************************************************/
  29. #include "tizendebug.h"
  30. #include "tizentoolchain.h"
  31. #include "tizenqtversion.h"
  32. #include "tizenconstants.h"
  33. #include "tizenconfigurations.h"
  34. #include <utils/hostosinfo.h>
  35. #include <projectexplorer/gcctoolchainfactories.h>
  36. #include <QDirIterator>
  37. #include <QProcess>
  38. namespace {
  39. const QLatin1String SDKGccVersionRegExp("-\\d[\\.\\d]+");
  40. const QLatin1String SDKGccVersionStrRegExp("-gcc-\\d[\\.\\d]+");
  41. const QLatin1String GBSGccArmArchRegExp("^arm.*");
  42. const QLatin1String GBSGccX86ArchRegExp("^i.86.*");
  43. }
  44. namespace Tizen {
  45. namespace Internal {
  46. namespace {
  47. const QLatin1String tizen_emulator_mkspec("devices/linux-g++-tizen-emulator");
  48. const QLatin1String tizen_mobile_mkspec("devices/linux-g++-tizen-mobile");
  49. const QLatin1String tizen_ivi_mkspec("devices/linux-g++-tizen-ivi");
  50. const QLatin1String tizen_mkspec("devices/linux-g++-tizen");
  51. }
  52. TizenGccToolChain::~TizenGccToolChain()
  53. {
  54. }
  55. QString TizenGccToolChain::type() const
  56. {
  57. return QLatin1String(Constants::TIZEN_TOOLCHAIN_GCC_TYPE);
  58. }
  59. QString TizenGccToolChain::typeDisplayName() const
  60. {
  61. return TizenToolChainFactory::tr("Tizen GCC");
  62. }
  63. bool TizenGccToolChain::isValid() const
  64. {
  65. return GccToolChain::isValid() &&
  66. targetAbi().isValid();
  67. }
  68. void TizenGccToolChain::addToEnvironment(Utils::Environment &env) const
  69. {
  70. GccToolChain::addToEnvironment(env);
  71. }
  72. bool TizenGccToolChain::operator ==(const ProjectExplorer::ToolChain & other) const
  73. {
  74. if(!GccToolChain::operator ==(other))
  75. return false;
  76. return true;
  77. }
  78. ProjectExplorer::ToolChainConfigWidget * TizenGccToolChain::configurationWidget()
  79. {
  80. return GccToolChain::configurationWidget();
  81. }
  82. Utils::FileName TizenGccToolChain::suggestedDebugger() const
  83. {
  84. return GccToolChain::suggestedDebugger();
  85. }
  86. QVariantMap TizenGccToolChain::toMap() const
  87. {
  88. QVariantMap vm = GccToolChain::toMap();
  89. return vm;
  90. }
  91. bool TizenGccToolChain::fromMap(const QVariantMap &data)
  92. {
  93. if(!GccToolChain::fromMap(data))
  94. return false;
  95. return isValid();
  96. }
  97. QString TizenGccToolChain::makeCommand(const Utils::Environment &environment) const
  98. {
  99. if(gbsBuildRoot().isEmpty())
  100. return GccToolChain::makeCommand(environment);
  101. else {
  102. Utils::FileName makeBinary = m_gbsBuildRoot;
  103. makeBinary.appendPath(QLatin1Literal("usr/bin/make-gbs-host"));
  104. return makeBinary.toString();
  105. }
  106. }
  107. QList<Utils::FileName> TizenGccToolChain::suggestedMkspecList() const
  108. {
  109. return QList<Utils::FileName>() << Utils::FileName::fromString(tizen_emulator_mkspec)
  110. << Utils::FileName::fromString(tizen_mobile_mkspec)
  111. << Utils::FileName::fromString(tizen_ivi_mkspec)
  112. << Utils::FileName::fromString(tizen_mkspec);
  113. }
  114. QList<ProjectExplorer::Abi> TizenGccToolChain::detectSupportedAbis() const
  115. {
  116. return QList<ProjectExplorer::Abi>() << targetAbi();
  117. }
  118. TizenGccToolChain::TizenGccToolChain() :
  119. GccToolChain(QLatin1String(Constants::TIZEN_TOOLCHAIN_ID), ManualDetection)
  120. {
  121. }
  122. TizenGccToolChain::TizenGccToolChain(const ProjectExplorer::Abi::Architecture arch, Detection detection, Utils::FileName gbsBuildRoot) :
  123. GccToolChain(QLatin1String(Constants::TIZEN_TOOLCHAIN_ID), detection), m_gbsBuildRoot(gbsBuildRoot)
  124. {
  125. qCDebug(QTC_TIZEN) << "Creating Tizen toolchain:" << gbsBuildRoot.toString();
  126. ProjectExplorer::Abi abi = ProjectExplorer::Abi(arch,
  127. ProjectExplorer::Abi::LinuxOS,
  128. ProjectExplorer::Abi::GenericLinuxFlavor,
  129. ProjectExplorer::Abi::ElfFormat,
  130. 32);
  131. setTargetAbi(abi);
  132. if (m_gbsBuildRoot.isEmpty())
  133. setDisplayName(QString::fromLatin1("Tizen GCC (%1)")
  134. .arg(ProjectExplorer::Abi::toString(abi.architecture())));
  135. else
  136. setDisplayName(QString::fromLatin1("Tizen GCC (%1) GBS")
  137. .arg(ProjectExplorer::Abi::toString(abi.architecture())));
  138. }
  139. TizenGccToolChain::TizenGccToolChain(const TizenGccToolChain& other) :
  140. GccToolChain(other)
  141. {
  142. }
  143. TizenToolChainFactory::TizenToolChainFactory()
  144. {
  145. }
  146. QString TizenToolChainFactory::displayName() const
  147. {
  148. return tr("Tizen GCC");
  149. }
  150. QList<ProjectExplorer::ToolChain *> TizenToolChainFactory::autoDetect()
  151. {
  152. return createToolChainsForSdk(TizenConfigurations::currentConfig().sdkLocation().toString());
  153. }
  154. bool TizenToolChainFactory::canRestore(const QVariantMap &data)
  155. {
  156. return idFromMap(data).startsWith(QLatin1String(Constants::TIZEN_TOOLCHAIN_ID) + QLatin1Char(':'));
  157. }
  158. ProjectExplorer::ToolChain *TizenToolChainFactory::restore(const QVariantMap &data)
  159. {
  160. TizenGccToolChain * tc = new TizenGccToolChain();
  161. if(tc->fromMap(data))
  162. return tc;
  163. delete tc;
  164. return NULL;
  165. }
  166. QList<ProjectExplorer::ToolChain *> TizenToolChainFactory::createToolChainsForSdk(const QString& sdkPath)
  167. {
  168. QList<ProjectExplorer::ToolChain *> result;
  169. if(sdkPath.isEmpty())
  170. return result;
  171. Utils::FileName path = Utils::FileName::fromString(sdkPath);
  172. QDirIterator it(path.appendPath(QLatin1String("tools")).toString(),
  173. QStringList() << QLatin1String("*gcc*"),
  174. QDir::Dirs);
  175. const QLatin1String bin_dir("bin");
  176. QRegExp versionRegExp(SDKGccVersionRegExp);
  177. QRegExp versionStrRegExp(SDKGccVersionStrRegExp);
  178. while(it.hasNext()) {
  179. it.next();
  180. Utils::FileName gccPath = Utils::FileName::fromString(it.filePath()).appendPath(bin_dir);
  181. QDirIterator gcc_paths(gccPath.toString(),
  182. QStringList() << QLatin1String("*gcc"),
  183. QDir::Files|QDir::Executable);
  184. if(gcc_paths.hasNext()) {
  185. gcc_paths.next();
  186. QString compilerAndVersionInfo = it.fileName();
  187. int idx = versionRegExp.indexIn(compilerAndVersionInfo);
  188. QString version = compilerAndVersionInfo.mid(idx + 1);
  189. idx = versionStrRegExp.indexIn(compilerAndVersionInfo);
  190. QString platform = compilerAndVersionInfo.left(idx);
  191. ProjectExplorer::Abi::Architecture abiArchitecture = TizenConfig::architectureForToolChainPrefix(platform);
  192. if (abiArchitecture == ProjectExplorer::Abi::UnknownArchitecture) // e.g. mipsel which is not yet supported
  193. continue;
  194. TizenGccToolChain *tc = new TizenGccToolChain(abiArchitecture, ProjectExplorer::ToolChain::AutoDetection);
  195. Utils::FileName compilerPath = Utils::FileName::fromString(gcc_paths.filePath());
  196. tc->setCompilerCommand(compilerPath);
  197. result.append(tc);
  198. qCDebug(QTC_TIZEN) << "Found " << ProjectExplorer::Abi::toString(abiArchitecture) << " compiler: " << compilerPath.toString();
  199. }
  200. }
  201. return result;
  202. }
  203. ProjectExplorer::ToolChain *TizenToolChainFactory::createToolChainForGbs(const QString &gbsBuildRoot)
  204. {
  205. qCDebug(QTC_TIZEN);
  206. ProjectExplorer::GccToolChain *result(0);
  207. if(gbsBuildRoot.isEmpty())
  208. return result;
  209. Utils::FileName compilerPath = Utils::FileName::fromString(gbsBuildRoot)
  210. .appendPath(QLatin1Literal("usr/bin/gcc"));
  211. QProcess compiler;
  212. compiler.setProgram(compilerPath.toString());
  213. compiler.setArguments(QStringList() << QLatin1Literal("-dumpmachine"));
  214. compiler.start();
  215. if (!compiler.waitForStarted()) {
  216. qWarning() << QStringLiteral("can't start %1 with -dumpmachine parameter:").arg(compilerPath.toString()) << compiler.readAll();
  217. return result;
  218. }
  219. if (!compiler.waitForFinished()) {
  220. qWarning() << QStringLiteral("%1 with -dumpmachine parameter timed out:").arg(compilerPath.toString()) << compiler.readAll();
  221. return result;
  222. }
  223. if (compiler.exitCode()) {
  224. qWarning() << QStringLiteral("%1 returned non 0 exit code:").arg(compilerPath.toString()) << compiler.readAll();
  225. return result;
  226. }
  227. QString dumpMachineVersion = QString::fromLatin1(compiler.readAll());
  228. qCDebug(QTC_TIZEN) << "dumpMachineVersion:" << dumpMachineVersion;
  229. QRegExp armVersionRegExp(GBSGccArmArchRegExp);
  230. QRegExp x86VersionRegExp(GBSGccX86ArchRegExp);
  231. ProjectExplorer::Abi::Architecture abiArchitecture = ProjectExplorer::Abi::UnknownArchitecture;
  232. if (armVersionRegExp.indexIn(dumpMachineVersion) != -1)
  233. abiArchitecture = ProjectExplorer::Abi::ArmArchitecture;
  234. else if (x86VersionRegExp.indexIn(dumpMachineVersion) != -1)
  235. abiArchitecture = ProjectExplorer::Abi::X86Architecture;
  236. qCDebug(QTC_TIZEN) << "Before creating tc";
  237. result = new TizenGccToolChain(abiArchitecture,
  238. ProjectExplorer::ToolChain::AutoDetection,
  239. Utils::FileName::fromString(gbsBuildRoot));
  240. result->setCompilerCommand(compilerPath);
  241. return result;
  242. }
  243. bool TizenToolChainFactory::canCreate()
  244. {
  245. return false;
  246. }
  247. ProjectExplorer::ToolChain * TizenToolChainFactory::create()
  248. {
  249. return new TizenGccToolChain();
  250. }
  251. } // namespace Internal
  252. } // namespace Tizen