Commit 7dc88639 authored by Kai Koehne's avatar Kai Koehne

QmlProfiler: Allow user to specify a sysroot for "Attach to Port"

Change-Id: I943255e5a501610195e3758f9fbb42d127f15524
Reviewed-on: http://codereview.qt-project.org/6451
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarAurindam Jana <aurindam.jana@nokia.com>
parent 7ed717ca
......@@ -86,15 +86,27 @@ void FileInProjectFinder::setProjectFiles(const QStringList &projectFiles)
m_cache.clear();
}
void FileInProjectFinder::setSysroot(const QString &sysroot)
{
QString newsys = sysroot;
while (newsys.endsWith(QLatin1Char('/')))
newsys.remove(newsys.length() - 1, 1);
if (m_sysroot == newsys)
return;
m_sysroot = newsys;
m_cache.clear();
}
/**
Returns the best match for the given file url in the project directory.
The method first checks whether the file inside the project directory exists.
If not, the leading directory in the path is stripped, and the - now shorter - path is
checked for existence. This continues until either the file is found, or the relative path
does not contain any directories any more: In this case the path of the url is returned.
Second, we walk the list of project files, and search for a file name match there.
checked for existence, and so on. Second, it tries to locate the file in the sysroot
folder specified. Third, we walk the list of project files, and search for a file name match
there. If all fails, it returns the original path from the file url.
*/
QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
{
......@@ -167,6 +179,18 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
}
}
// check if absolute path is found in sysroot
if (!m_sysroot.isEmpty()) {
const QString sysrootPath = m_sysroot + QLatin1Char('/') + originalPath;
if (QFileInfo(sysrootPath).exists() && QFileInfo(sysrootPath).isFile()) {
if (success)
*success = true;
m_cache.insert(originalPath, sysrootPath);
return sysrootPath;
}
}
// finally, find solely by filename in project files
const QString fileName = QFileInfo(originalPath).fileName();
foreach (const QString &f, m_projectFiles) {
if (QFileInfo(f).fileName() == fileName) {
......
......@@ -51,11 +51,13 @@ public:
QString projectDirectory() const;
void setProjectFiles(const QStringList &projectFiles);
void setSysroot(const QString &sysroot);
QString findFile(const QUrl &fileUrl, bool *success = 0) const;
private:
QString m_projectDir;
QString m_sysroot;
QStringList m_projectFiles;
mutable QHash<QString,QString> m_cache;
};
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>185</width>
<height>115</height>
<width>212</width>
<height>136</height>
</rect>
</property>
<property name="windowTitle">
......@@ -16,9 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="hostLabel">
<property name="text">
......@@ -56,6 +53,19 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="sysrootLabel">
<property name="text">
<string>Sys&amp;root:</string>
</property>
<property name="buddy">
<cstring>sysRootChooser</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Utils::PathChooser" name="sysRootChooser" native="true"/>
</item>
</layout>
</item>
<item>
......@@ -70,6 +80,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -864,6 +864,16 @@ int AttachToQmlPortDialog::port() const
return m_ui->portSpinBox->value();
}
QString AttachToQmlPortDialog::sysroot() const
{
return m_ui->sysRootChooser->path();
}
void AttachToQmlPortDialog::setSysroot(const QString &sysroot)
{
m_ui->sysRootChooser->setPath(sysroot);
}
// --------- StartRemoteCdbDialog
static inline QString cdbRemoteHelp()
{
......
......@@ -234,6 +234,9 @@ public:
int port() const;
void setPort(const int port);
QString sysroot() const;
void setSysroot(const QString &sysroot);
private:
Ui::AttachToQmlPortDialog *m_ui;
};
......
......@@ -1673,14 +1673,20 @@ void DebuggerPluginPrivate::attachToQmlPort()
dlg.setPort(sp.qmlServerPort);
}
const QVariant sysrootPath = configValue(_("LastSysroot"));
if (sysrootPath.isValid())
dlg.setSysroot(sysrootPath.toString());
if (dlg.exec() != QDialog::Accepted)
return;
setConfigValue(_("LastQmlServerAddress"), dlg.host());
setConfigValue(_("LastQmlServerPort"), dlg.port());
setConfigValue(_("LastSysroot"), dlg.sysroot());
sp.qmlServerAddress = dlg.host();
sp.qmlServerPort = dlg.port();
sp.sysroot = dlg.sysroot();
sp.startMode = AttachToQmlPort;
if (RunControl *rc = createDebugger(sp))
......
......@@ -755,12 +755,10 @@ unsigned QmlEngine::debuggerCapabilities() const
QString QmlEngine::toFileInProject(const QUrl &fileUrl)
{
if (startParameters().startMode != AttachToQmlPort) {
if (d->fileFinder.projectDirectory().isEmpty()) {
d->fileFinder.setProjectDirectory(startParameters().projectSourceDirectory);
d->fileFinder.setProjectFiles(startParameters().projectSourceFiles);
}
}
// make sure file finder is properly initialized
d->fileFinder.setProjectDirectory(startParameters().projectSourceDirectory);
d->fileFinder.setProjectFiles(startParameters().projectSourceFiles);
d->fileFinder.setSysroot(startParameters().sysroot);
return d->fileFinder.findFile(fileUrl);
}
......
Markdown is supported
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