OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-s60 / gccetoolchain.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "gccetoolchain.h"
34 #include "qt4projectmanagerconstants.h"
35 #include "qtversionmanager.h"
36
37 #include <utils/environment.h>
38 #include <utils/synchronousprocess.h>
39 #include <projectexplorer/headerpath.h>
40
41 #include <QtCore/QDir>
42
43 namespace Qt4ProjectManager {
44 namespace Internal {
45
46 static QString gcceVersion(const QString &command)
47 {
48     if (command.isEmpty())
49         return QString();
50
51     QProcess gxx;
52     QStringList arguments;
53     arguments << QLatin1String("-dumpversion");
54     Utils::Environment env = Utils::Environment::systemEnvironment();
55     env.set(QLatin1String("LC_ALL"), QLatin1String("C"));   //override current locale settings
56     gxx.setEnvironment(env.toStringList());
57     gxx.setReadChannelMode(QProcess::MergedChannels);
58     gxx.start(command, arguments);
59     if (!gxx.waitForStarted()) {
60         qWarning("Cannot start '%s': %s", qPrintable(command), qPrintable(gxx.errorString()));
61         return QString();
62     }
63     gxx.closeWriteChannel();
64     if (!gxx.waitForFinished())      {
65         Utils::SynchronousProcess::stopProcess(gxx);
66         qWarning("Timeout running '%s'.", qPrintable(command));
67         return QString();
68     }
69     if (gxx.exitStatus() != QProcess::NormalExit) {
70         qWarning("'%s' crashed.", qPrintable(command));
71         return QString();
72     }
73
74     if (gxx.canReadLine())
75         return gxx.readLine().trimmed();
76
77     return QString();
78 }
79
80
81 // ==========================================================================
82 // GcceToolChain
83 // ==========================================================================
84
85 QString GcceToolChain::typeName() const
86 {
87     return GcceToolChainFactory::tr("GCCE");
88 }
89
90 QByteArray GcceToolChain::predefinedMacros() const
91 {
92     if (m_predefinedMacros.isEmpty()) {
93         ProjectExplorer::GccToolChain::predefinedMacros();
94         m_predefinedMacros += "\n"
95                 "#define __GCCE__\n"
96                 "#define __SYMBIAN32__\n";
97     }
98     return m_predefinedMacros;
99 }
100
101 void GcceToolChain::addToEnvironment(Utils::Environment &env) const
102 {
103     GccToolChain::addToEnvironment(env);
104
105     if (m_gcceVersion.isEmpty())
106         m_gcceVersion = gcceVersion(compilerPath());
107     if (m_gcceVersion.isEmpty())
108         return;
109
110     env.set(QLatin1String("QT_GCCE_VERSION"), m_gcceVersion);
111     QString version = m_gcceVersion;
112     env.set(QString::fromLatin1("SBS_GCCE") + version.remove(QLatin1Char('.'))
113             + QLatin1String("BIN"),
114             QDir::toNativeSeparators(QFileInfo(compilerPath()).absolutePath()));
115     // Required for SBS, which checks the version output from its tools
116     // and gets confused by localized output.
117     env.set(QLatin1String("LANG"), QString(QLatin1Char('C')));
118 }
119
120 QString GcceToolChain::defaultMakeTarget() const
121 {
122     return QLatin1String("gcce");
123 }
124
125 ProjectExplorer::ToolChain *GcceToolChain::clone() const
126 {
127     return new GcceToolChain(*this);
128 }
129
130 GcceToolChain::GcceToolChain(bool autodetected) :
131     GccToolChain(QLatin1String(Constants::GCCE_TOOLCHAIN_ID), autodetected)
132 { }
133
134 // ==========================================================================
135 // GcceToolChainFactory
136 // ==========================================================================
137
138 QString GcceToolChainFactory::displayName() const
139 {
140     return tr("GCCE");
141 }
142
143 QString GcceToolChainFactory::id() const
144 {
145     return QLatin1String(Constants::GCCE_TOOLCHAIN_ID);
146 }
147
148 QList<ProjectExplorer::ToolChain *> GcceToolChainFactory::autoDetect()
149 {
150     QList<ProjectExplorer::ToolChain *> result;
151
152     // Compatibility to pre-2.2:
153     while (true) {
154         const QString path = QtVersionManager::instance()->popPendingGcceUpdate();
155         if (path.isNull())
156             break;
157
158         QFileInfo fi(path + QLatin1String("/bin/arm-none-symbianelf-g++.exe"));
159         if (fi.exists() && fi.isExecutable()) {
160             GcceToolChain *tc = new GcceToolChain(false);
161             tc->setCompilerPath(fi.absoluteFilePath());
162             tc->setDisplayName(tr("GCCE from Qt version"));
163             result.append(tc);
164         }
165     }
166
167     QString fullPath = Utils::Environment::systemEnvironment().searchInPath(QLatin1String("arm-none-symbianelf-gcc"));
168     if (!fullPath.isEmpty()) {
169         GcceToolChain *tc = new GcceToolChain(true);
170         tc->setCompilerPath(fullPath);
171         tc->setDisplayName(tr("GCCE (%1)").arg(gcceVersion(fullPath)));
172         if (tc->targetAbi() == ProjectExplorer::Abi(ProjectExplorer::Abi::ArmArchitecture,
173                                                     ProjectExplorer::Abi::SymbianOS,
174                                                     ProjectExplorer::Abi::SymbianDeviceFlavor,
175                                                     ProjectExplorer::Abi::ElfFormat,
176                                                     32))
177         result.append(tc);
178     }
179     return result;
180 }
181
182 bool GcceToolChainFactory::canCreate()
183 {
184     return true;
185 }
186
187 ProjectExplorer::ToolChain *GcceToolChainFactory::create()
188 {
189     GcceToolChain *tc = new GcceToolChain(false);
190     tc->setDisplayName(tr("GCCE"));
191     return tc;
192 }
193
194 bool GcceToolChainFactory::canRestore(const QVariantMap &data)
195 {
196     return idFromMap(data).startsWith(QLatin1String(Constants::GCCE_TOOLCHAIN_ID));
197 }
198
199 ProjectExplorer::ToolChain *GcceToolChainFactory::restore(const QVariantMap &data)
200 {
201     GcceToolChain *tc = new GcceToolChain(false);
202     if (tc->fromMap(data))
203         return tc;
204
205     delete tc;
206     return 0;
207 }
208
209 } // namespace Internal
210 } // namespace Qt4ProjectManager