Commit ea36927c authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlDebug: Simplify logic to find the source file for a stack frame

Get rid of custom logic to handle shadow builds (which didn't work
anyway if the qml files are from a different directory than expected).
Instead, just search for the file name in the list of files from the
project.

Reviewed-by: Christiaan Janssen
parent 5b521e2d
......@@ -2343,10 +2343,10 @@ static QString formatStartParameters(DebuggerStartParameters &sp)
str << "Core: " << QDir::toNativeSeparators(sp.coreFile) << '\n';
if (sp.attachPID > 0)
str << "PID: " << sp.attachPID << ' ' << sp.crashParameter << '\n';
if (!sp.projectDir.isEmpty()) {
str << "Project: " << QDir::toNativeSeparators(sp.projectDir);
if (!sp.projectBuildDir.isEmpty())
str << " (built: " << QDir::toNativeSeparators(sp.projectBuildDir) << ')';
if (!sp.projectSourceDirectory.isEmpty()) {
str << "Project: " << QDir::toNativeSeparators(sp.projectSourceDirectory);
if (!sp.projectBuildDirectory.isEmpty())
str << " (built: " << QDir::toNativeSeparators(sp.projectBuildDirectory) << ')';
str << '\n';
}
if (!sp.qtInstallPath.isEmpty())
......
......@@ -707,12 +707,13 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
sp.qtInstallPath = findQtInstallPath(qmake);
}
if (const ProjectExplorer::Project *project = target->project()) {
sp.projectDir = project->projectDirectory();
if (const ProjectExplorer::BuildConfiguration *buildConfig = target->activeBuildConfiguration()) {
sp.projectBuildDir = buildConfig->buildDirectory();
if (const ProjectExplorer::ToolChain *tc = buildConfig->toolChain())
sp.projectSourceDirectory = project->projectDirectory();
if (const ProjectExplorer::BuildConfiguration *buildConfig = target->activeBuildConfiguration()) {
sp.projectBuildDirectory = buildConfig->buildDirectory();
if (const ProjectExplorer::ToolChain *tc = buildConfig->toolChain())
sp.debuggerCommand = tc->debuggerCommand();
}
}
sp.projectSourceFiles = project->files(Project::ExcludeGeneratedFiles);
}
}
......
......@@ -92,8 +92,9 @@ public:
// Used by Qml debugging.
QString qmlServerAddress;
quint16 qmlServerPort;
QString projectBuildDir;
QString projectDir;
QString projectSourceDirectory;
QString projectBuildDirectory;
QStringList projectSourceFiles;
QString qtInstallPath;
// Used by remote debugging.
......
......@@ -772,29 +772,18 @@ QString QmlEngine::toFileInProject(const QString &fileUrl)
if (path.isEmpty())
return fileUrl;
// Try to find shadow-build file in source dir first
if (isShadowBuildProject()) {
const QString sourcePath = fromShadowBuildFilename(path);
if (QFileInfo(sourcePath).exists())
return sourcePath;
if (d->fileFinder.projectDirectory().isEmpty()) {
d->fileFinder.setProjectDirectory(startParameters().projectSourceDirectory);
d->fileFinder.setProjectFiles(startParameters().projectSourceFiles);
}
if (d->fileFinder.projectDirectory().isEmpty())
d->fileFinder.setProjectDirectory(startParameters().projectDir);
// Try to find file with biggest common path in source directory
bool fileFound = false;
QString fileInProject = d->fileFinder.findFile(path, &fileFound);
if (fileFound)
return fileInProject;
// Try whether file is absolute & exists
if (QFileInfo(path).isAbsolute()
&& QFileInfo(path).exists()) {
return path;
}
return fileUrl;
return path;
}
void QmlEngine::messageReceived(const QByteArray &message)
......@@ -1029,61 +1018,12 @@ void QmlEngine::executeDebuggerCommand(const QString& command)
sendMessage(reply);
}
bool QmlEngine::isShadowBuildProject() const
{
return !startParameters().projectBuildDir.isEmpty()
&& startParameters().projectDir != startParameters().projectBuildDir;
}
QString QmlEngine::qmlImportPath() const
{
return startParameters().environment.value("QML_IMPORT_PATH");
}
QString QmlEngine::mangleFilenamePaths(const QString &filename,
const QString &oldBasePath, const QString &newBasePath) const
{
QDir oldBaseDir(oldBasePath);
QDir newBaseDir(newBasePath);
QFileInfo fileInfo(filename);
if (oldBaseDir.exists() && newBaseDir.exists() && fileInfo.exists()) {
Qt::CaseSensitivity caseSensitive = Qt::CaseSensitive;
#ifdef Q_OS_WIN
caseSensitive = Qt::CaseInsensitive;
#endif
if (fileInfo.absoluteFilePath().startsWith(oldBaseDir.canonicalPath(), caseSensitive)) {
QString fileRelativePath = fileInfo.canonicalFilePath().mid(oldBaseDir.canonicalPath().length());
QFileInfo projectFile(newBaseDir.canonicalPath() + QLatin1Char('/') + fileRelativePath);
if (projectFile.exists())
return projectFile.canonicalFilePath();
}
}
return filename;
}
QString QmlEngine::fromShadowBuildFilename(const QString &filename) const
{
QString newFilename = filename;
QString importPath = qmlImportPath();
#ifdef Q_OS_MACX
// Qt Quick Applications by default copy the qml directory
// to buildDir()/X.app/Contents/Resources.
const QString applicationBundleDir
= QFileInfo(startParameters().executable).absolutePath() + "/../..";
newFilename = mangleFilenamePaths(newFilename, applicationBundleDir + "/Contents/Resources", startParameters().projectDir);
#endif
newFilename = mangleFilenamePaths(newFilename, startParameters().projectBuildDir, startParameters().projectDir);
if (newFilename == filename && !importPath.isEmpty()) {
newFilename = mangleFilenamePaths(filename, startParameters().projectBuildDir, importPath);
}
return newFilename;
}
void QmlEngine::logMessage(LogDirection direction, const QString &message)
{
QString msg = "JSDebugger";
......
......@@ -206,7 +206,8 @@ RunControl *QmlRunControlFactory::createDebugRunControl(QmlProjectRunConfigurati
params.workingDirectory = runConfig->workingDirectory();
params.environment = runConfig->environment();
params.displayName = runConfig->displayName();
params.projectDir = runConfig->target()->project()->projectDirectory();
params.projectSourceDirectory = runConfig->target()->project()->projectDirectory();
params.projectSourceFiles = runConfig->target()->project()->files(Project::ExcludeGeneratedFiles);
if (params.executable.isEmpty()) {
showQmlObserverToolWarning();
......
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