diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp index 60827b7d24e1c9a278586d073ef6b305dab8c6cc..c101b7cb3cc619f0c1aa35e03ee2cd33810755df 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemorunconfiguration.cpp @@ -565,65 +565,25 @@ void MaemoRunConfiguration::updateTarget() m_executable = QString::null; m_cachedTargetInformationValid = true; - if (Qt4Project *qt4Project = project()) { - Qt4BuildConfiguration *qt4bc = qt4Project->activeQt4BuildConfiguration(); - Qt4ProFileNode *proFileNode = qt4Project->rootProjectNode()->findProFileFor(m_proFilePath); - if (!proFileNode) { - emit targetInformationChanged(); - return; - } - - ProFileReader *reader = qt4Project->createProFileReader(proFileNode); - reader->setCumulative(false); - - // Find out what flags we pass on to qmake - QStringList addedUserConfigArguments; - QStringList removedUserConfigArguments; - qt4bc->getConfigCommandLineArguments(&addedUserConfigArguments, &removedUserConfigArguments); - reader->setConfigCommandLineArguments(addedUserConfigArguments, removedUserConfigArguments); - - if (!reader->readProFile(m_proFilePath)) { - qt4Project->destroyProFileReader(reader); + Qt4TargetInformation info = project()->targetInformation(project()->activeQt4BuildConfiguration(), + m_proFilePath); + if (info.error != Qt4TargetInformation::NoError) { + if (info.error == Qt4TargetInformation::ProParserError) { Core::ICore::instance()->messageManager()->printToOutputPane(tr( "Could not parse %1. The Maemo run configuration %2 " "can not be started.").arg(m_proFilePath).arg(name())); - emit targetInformationChanged(); - return; - } - - // Extract data - QDir baseProjectDirectory = - QFileInfo(project()->file()->fileName()).absoluteDir(); - QString relSubDir = - baseProjectDirectory.relativeFilePath(QFileInfo(m_proFilePath).path()); - QDir baseBuildDirectory = qt4bc->buildDirectory(); - QString baseDir = baseBuildDirectory.absoluteFilePath(relSubDir); - - if (!reader->contains("DESTDIR")) { -#if 0 // TODO: fix this, seems to be wrong on windows - if (reader->values("CONFIG").contains("debug_and_release_target")) { - QString qmakeBuildConfig = "release"; - if (projectBuildConfiguration & QtVersion::DebugBuild) - qmakeBuildConfig = "debug"; - baseDir += QLatin1Char('/') + qmakeBuildConfig; - } -#endif - } else { - const QString &destDir = reader->value("DESTDIR"); - if (QDir::isRelativePath(destDir)) - baseDir += QLatin1Char('/') + destDir; - else - baseDir = destDir; } - - QString target = reader->value("TARGET"); - if (target.isEmpty()) - target = QFileInfo(m_proFilePath).baseName(); - - m_executable = QDir::cleanPath(baseDir + QLatin1Char('/') + target); - qt4Project->destroyProFileReader(reader); + emit targetInformationChanged(); + return; } + QString baseDir; + if (info.hasCustomDestDir) + baseDir = info.workingDir; + else + baseDir = info.baseDestDir; + m_executable = QDir::cleanPath(baseDir + QLatin1Char('/') + info.target); + emit targetInformationChanged(); } diff --git a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp index bcff5409a0b50e046c9e1c776ffe414b60b43cbe..4d10173ad7c1f6de93d67cd99877df6eca551184 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60devicerunconfiguration.cpp @@ -280,54 +280,33 @@ void S60DeviceRunConfiguration::updateTarget() { if (m_cachedTargetInformationValid) return; - Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); - Qt4ProFileNode *proFileNode = qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath); - if (!proFileNode) { + Qt4TargetInformation info = qt4Project()->targetInformation(qt4Project()->activeQt4BuildConfiguration(), + m_proFilePath); + if (info.error != Qt4TargetInformation::NoError) { + if (info.error == Qt4TargetInformation::ProParserError) { + Core::ICore::instance()->messageManager()->printToOutputPane( + tr("Could not parse %1. The QtS60 Device run configuration %2 can not be started.") + .arg(m_proFilePath).arg(name())); + } + m_targetName = QString::null; m_baseFileName = QString::null; + m_packageTemplateFileName = QString::null; + m_platform = QString::null; m_cachedTargetInformationValid = true; emit targetInformationChanged(); return; } - ProFileReader *reader = qt4Project()->createProFileReader(proFileNode); - reader->setCumulative(false); - - // Find out what flags we pass on to qmake - QStringList addedUserConfigArguments; - QStringList removedUserConfigArguments; - qt4bc->getConfigCommandLineArguments(&addedUserConfigArguments, &removedUserConfigArguments); - reader->setConfigCommandLineArguments(addedUserConfigArguments, removedUserConfigArguments); - - if (!reader->readProFile(m_proFilePath)) { - qt4Project()->destroyProFileReader(reader); - Core::ICore::instance()->messageManager()->printToOutputPane(tr("Could not parse %1. The QtS60 Device run configuration %2 can not be started.").arg(m_proFilePath).arg(name())); - return; - } - - // Extract data - const QDir baseProjectDirectory = QFileInfo(project()->file()->fileName()).absoluteDir(); - const QString relSubDir = baseProjectDirectory.relativeFilePath(QFileInfo(m_proFilePath).path()); - const QDir baseBuildDirectory = qt4bc->buildDirectory(); - const QString baseDir = baseBuildDirectory.absoluteFilePath(relSubDir); - - // Directory - QString m_workingDir; - if (reader->contains("DESTDIR")) { - m_workingDir = reader->value("DESTDIR"); - if (QDir::isRelativePath(m_workingDir)) { - m_workingDir = baseDir + QLatin1Char('/') + m_workingDir; - } - } else { - m_workingDir = baseDir; - } - - m_targetName = reader->value("TARGET"); - if (m_targetName.isEmpty()) - m_targetName = QFileInfo(m_proFilePath).baseName(); + QString workingDir; + if (info.hasCustomDestDir) + workingDir = info.workingDir; + else + workingDir = info.baseDestDir; + m_targetName = info.target; - m_baseFileName = QDir::cleanPath(m_workingDir + QLatin1Char('/') + m_targetName); - m_packageTemplateFileName = QDir::cleanPath( - m_workingDir + QLatin1Char('/') + m_targetName + QLatin1String("_template.pkg")); + m_baseFileName = workingDir + QLatin1Char('/') + m_targetName; + m_packageTemplateFileName = m_baseFileName + QLatin1String("_template.pkg"); + Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); switch (qt4bc->toolChainType()) { case ToolChain::GCCE: case ToolChain::GCCE_GNUPOC: @@ -345,7 +324,7 @@ void S60DeviceRunConfiguration::updateTarget() else m_target = QLatin1String("urel"); m_baseFileName += QLatin1Char('_') + m_platform + QLatin1Char('_') + m_target; - qt4Project()->destroyProFileReader(reader); + m_cachedTargetInformationValid = true; emit targetInformationChanged(); } diff --git a/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp index dd565d164e205c71adedafdd0a2b7c2586753b5a..2672e54c5ed7c570d1f4dd891747f268e3e455b8 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60emulatorrunconfiguration.cpp @@ -127,29 +127,21 @@ void S60EmulatorRunConfiguration::updateTarget() { if (m_cachedTargetInformationValid) return; - Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); - Qt4ProFileNode *proFileNode = qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath); - if (!proFileNode) { + Qt4TargetInformation info = qt4Project()->targetInformation(qt4Project()->activeQt4BuildConfiguration(), + m_proFilePath); + if (info.error != Qt4TargetInformation::NoError) { + if (info.error == Qt4TargetInformation::ProParserError) { + Core::ICore::instance()->messageManager()->printToOutputPane( + tr("Could not parse %1. The Qt for Symbian emulator run configuration %2 can not be started.") + .arg(m_proFilePath).arg(name())); + } m_executable = QString::null; m_cachedTargetInformationValid = true; emit targetInformationChanged(); return; } - ProFileReader *reader = qt4Project()->createProFileReader(proFileNode); - reader->setCumulative(false); - - // Find out what flags we pass on to qmake - QStringList addedUserConfigArguments; - QStringList removedUserConfigArguments; - qt4bc->getConfigCommandLineArguments(&addedUserConfigArguments, &removedUserConfigArguments); - reader->setConfigCommandLineArguments(addedUserConfigArguments, removedUserConfigArguments); - - if (!reader->readProFile(m_proFilePath)) { - qt4Project()->destroyProFileReader(reader); - Core::ICore::instance()->messageManager()->printToOutputPane(tr("Could not parse %1. The Qt for Symbian emulator run configuration %2 can not be started.").arg(m_proFilePath).arg(name())); - return; - } + Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); QtVersion *qtVersion = qt4bc->qtVersion(); QString baseDir = S60Manager::instance()->deviceForQtVersion(qtVersion).epocRoot; QString qmakeBuildConfig = "urel"; @@ -157,15 +149,10 @@ void S60EmulatorRunConfiguration::updateTarget() qmakeBuildConfig = "udeb"; baseDir += "/epoc32/release/winscw/" + qmakeBuildConfig; - QString target = reader->value("TARGET"); - if (target.isEmpty()) - target = QFileInfo(m_proFilePath).baseName(); - m_executable = QDir::toNativeSeparators( - QDir::cleanPath(baseDir + QLatin1Char('/') + target)); + QDir::cleanPath(baseDir + QLatin1Char('/') + info.target)); m_executable += QLatin1String(".exe"); - qt4Project()->destroyProFileReader(reader); m_cachedTargetInformationValid = true; emit targetInformationChanged(); } diff --git a/src/plugins/qt4projectmanager/qt4project.cpp b/src/plugins/qt4projectmanager/qt4project.cpp index 03ebbebd408b87d5fd538db7948e601ad0711f44..2f6a668ce6ce199be1c69495605de093d24e2157 100644 --- a/src/plugins/qt4projectmanager/qt4project.cpp +++ b/src/plugins/qt4projectmanager/qt4project.cpp @@ -896,6 +896,85 @@ void Qt4Project::destroyProFileReader(ProFileReader *reader) } } +Qt4TargetInformation Qt4Project::targetInformation(Qt4BuildConfiguration *buildConfiguration, + const QString &proFilePath) +{ + Qt4TargetInformation info; + Qt4ProFileNode *proFileNode = rootProjectNode()->findProFileFor(proFilePath); + if (!proFileNode) { + info.error = Qt4TargetInformation::InvalidProjectError; + return info; + } + ProFileReader *reader = createProFileReader(proFileNode); + reader->setCumulative(false); + + // Find out what flags we pass on to qmake + QStringList addedUserConfigArguments; + QStringList removedUserConfigArguments; + buildConfiguration->getConfigCommandLineArguments(&addedUserConfigArguments, &removedUserConfigArguments); + reader->setConfigCommandLineArguments(addedUserConfigArguments, removedUserConfigArguments); + + if (!reader->readProFile(proFilePath)) { + destroyProFileReader(reader); + info.error = Qt4TargetInformation::ProParserError; + return info; + } + + // Extract data + const QDir baseProjectDirectory = QFileInfo(file()->fileName()).absoluteDir(); + const QString relSubDir = baseProjectDirectory.relativeFilePath(QFileInfo(proFilePath).path()); + const QDir baseBuildDirectory = buildConfiguration->buildDirectory(); + const QString baseDir = baseBuildDirectory.absoluteFilePath(relSubDir); + info.baseDestDir = QDir::cleanPath(baseDir); + //qDebug()<<relSubDir<<baseDir; + + // Working Directory + if (reader->contains("DESTDIR")) { + info.hasCustomDestDir = true; + //qDebug() << "reader contains destdir:" << reader->value("DESTDIR"); + info.workingDir = reader->value("DESTDIR"); + if (QDir::isRelativePath(info.workingDir)) { + info.workingDir = baseDir + QLatin1Char('/') + info.workingDir; + //qDebug() << "was relative and expanded to" << info.workingDir; + } + } else { + info.hasCustomDestDir = false; + //qDebug() << "reader didn't contain DESTDIR, setting to " << baseDir; + info.workingDir = baseDir; + if (reader->values("CONFIG").contains("debug_and_release_target")) { + //qDebug() << "reader has debug_and_release_target"; + QString qmakeBuildConfig = "release"; + if (buildConfiguration->qmakeBuildConfiguration() & QtVersion::DebugBuild) + qmakeBuildConfig = "debug"; + info.workingDir += QLatin1Char('/') + qmakeBuildConfig; + } + } + + info.target = reader->value("TARGET"); + if (info.target.isEmpty()) + info.target = QFileInfo(proFilePath).baseName(); + +#if defined (Q_OS_MAC) + if (reader->values("CONFIG").contains("app_bundle")) { + info.workingDir += QLatin1Char('/') + + info.target + + QLatin1String(".app/Contents/MacOS"); + } +#endif + + info.workingDir = QDir::cleanPath(info.workingDir); + info.executable = QDir::cleanPath(info.workingDir + QLatin1Char('/') + info.target); + //qDebug() << "##### updateTarget sets:" << info.workingDir << info.executable; + +#if defined (Q_OS_WIN) + info.executable += QLatin1String(".exe"); +#endif + + destroyProFileReader(reader); + info.error = Qt4TargetInformation::NoError; + return info; +} + Qt4ProFileNode *Qt4Project::rootProjectNode() const { return m_rootProjectNode; diff --git a/src/plugins/qt4projectmanager/qt4project.h b/src/plugins/qt4projectmanager/qt4project.h index 88bf0a2932a0b0c6ae06deaafe528c9bb0ce56af..f0a280f0aec9de09c328ed7dde0225af47ad2e7a 100644 --- a/src/plugins/qt4projectmanager/qt4project.h +++ b/src/plugins/qt4projectmanager/qt4project.h @@ -148,6 +148,22 @@ private: QMap<QString, VersionInfo> m_versions; }; +struct Qt4TargetInformation +{ + enum ErrorCode { + NoError, + InvalidProjectError, + ProParserError + }; + + ErrorCode error; + bool hasCustomDestDir; + QString baseDestDir; + QString workingDir; + QString target; + QString executable; +}; + class Qt4Project : public ProjectExplorer::Project { Q_OBJECT @@ -196,6 +212,9 @@ public: Internal::ProFileReader *createProFileReader(Internal::Qt4ProFileNode *qt4ProFileNode); void destroyProFileReader(Internal::ProFileReader *reader); + Qt4TargetInformation targetInformation(Internal::Qt4BuildConfiguration *buildConfiguration, + const QString &proFilePath); + signals: /// convenience signal, emitted if either the active buildconfiguration emits /// targetInformationChanged() or if the active build configuration changes diff --git a/src/plugins/qt4projectmanager/qt4runconfiguration.cpp b/src/plugins/qt4projectmanager/qt4runconfiguration.cpp index d39ff7edc0fc7145c6da78134916c9ca53666ef4..e038ac55726a8a4ea05f1a9358ac6069b95016d4 100644 --- a/src/plugins/qt4projectmanager/qt4runconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt4runconfiguration.cpp @@ -570,81 +570,22 @@ void Qt4RunConfiguration::updateTarget() { if (m_cachedTargetInformationValid) return; - //qDebug()<<"updateTarget"; - Qt4BuildConfiguration *qt4bc = qt4Project()->activeQt4BuildConfiguration(); - Qt4ProFileNode *proFileNode = qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath); - if (!proFileNode) { + Qt4TargetInformation info = qt4Project()->targetInformation(qt4Project()->activeQt4BuildConfiguration(), + m_proFilePath); + if (info.error != Qt4TargetInformation::NoError) { + if (info.error == Qt4TargetInformation::ProParserError) { + Core::ICore::instance()->messageManager()->printToOutputPane( + tr("Could not parse %1. The Qt4 run configuration %2 can not be started.") + .arg(m_proFilePath).arg(name())); + } m_workingDir = QString::null; m_executable = QString::null; m_cachedTargetInformationValid = true; emit effectiveTargetInformationChanged(); return; } - ProFileReader *reader = qt4Project()->createProFileReader(proFileNode); - reader->setCumulative(false); - - // Find out what flags we pass on to qmake - QStringList addedUserConfigArguments; - QStringList removedUserConfigArguments; - qt4bc->getConfigCommandLineArguments(&addedUserConfigArguments, &removedUserConfigArguments); - reader->setConfigCommandLineArguments(addedUserConfigArguments, removedUserConfigArguments); - - if (!reader->readProFile(m_proFilePath)) { - qt4Project()->destroyProFileReader(reader); - Core::ICore::instance()->messageManager()->printToOutputPane(tr("Could not parse %1. The Qt4 run configuration %2 can not be started.").arg(m_proFilePath).arg(name())); - return; - } - - // Extract data - QDir baseProjectDirectory = QFileInfo(project()->file()->fileName()).absoluteDir(); - QString relSubDir = baseProjectDirectory.relativeFilePath(QFileInfo(m_proFilePath).path()); - QDir baseBuildDirectory = project()->activeBuildConfiguration()->buildDirectory(); - QString baseDir = baseBuildDirectory.absoluteFilePath(relSubDir); - - //qDebug()<<relSubDir<<baseDir; - - // Working Directory - if (reader->contains("DESTDIR")) { - //qDebug()<<"reader contains destdir:"<<reader->value("DESTDIR"); - m_workingDir = reader->value("DESTDIR"); - if (QDir::isRelativePath(m_workingDir)) { - m_workingDir = baseDir + QLatin1Char('/') + m_workingDir; - //qDebug()<<"was relative and expanded to"<<m_workingDir; - } - } else { - //qDebug()<<"reader didn't contain DESTDIR, setting to "<<baseDir; - m_workingDir = baseDir; - if (reader->values("CONFIG").contains("debug_and_release_target")) { - //qDebug()<<"reader has debug_and_release_target"; - QString qmakeBuildConfig = "release"; - if (qt4bc->qmakeBuildConfiguration() & QtVersion::DebugBuild) - qmakeBuildConfig = "debug"; - if (!reader->contains("DESTDIR")) - m_workingDir += QLatin1Char('/') + qmakeBuildConfig; - } - } - - QString target = reader->value("TARGET"); - if (target.isEmpty()) - target = QFileInfo(m_proFilePath).baseName(); - -#if defined (Q_OS_MAC) - if (reader->values("CONFIG").contains("app_bundle")) { - m_workingDir += QLatin1Char('/') - + target - + QLatin1String(".app/Contents/MacOS"); - } -#endif - - m_workingDir = QDir::cleanPath(m_workingDir); - m_executable = QDir::cleanPath(m_workingDir + QLatin1Char('/') + target); - //qDebug()<<"##### updateTarget sets:"<<m_workingDir<<m_executable; - -#if defined (Q_OS_WIN) - m_executable += QLatin1String(".exe"); -#endif - - qt4Project()->destroyProFileReader(reader); + m_workingDir = info.workingDir; + m_executable = info.executable; m_cachedTargetInformationValid = true;