Commit 7f2c4c9b authored by dt's avatar dt
Browse files

Qt4ProjectManager: Fix crash on importing builds

Task-Nr: QTCREATORBUG-2723
parent 6b92bc3d
......@@ -799,3 +799,73 @@ BuildConfiguration *Qt4BuildConfigurationFactory::restore(Target *parent, const
delete bc;
return 0;
}
void Qt4BuildConfiguration::importFromBuildDirectory()
{
QString directory = buildDirectory();
if (!directory.isEmpty()) {
QString mkfile = directory;
if (makefile().isEmpty())
mkfile.append("/Makefile");
else
mkfile.append(makefile());
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(mkfile);
if (!qmakePath.isEmpty()) {
QtVersionManager *vm = QtVersionManager::instance();
QtVersion *version = vm->qtVersionForQMakeBinary(qmakePath);
if (!version) {
version = new QtVersion(qmakePath);
vm->addVersion(version);
}
QPair<QtVersion::QmakeBuildConfigs, QString> result =
QtVersionManager::scanMakeFile(directory, version->defaultBuildConfig());
QtVersion::QmakeBuildConfigs qmakeBuildConfig = result.first;
QString aa = result.second;
QString parsedSpec = Qt4BuildConfiguration::extractSpecFromArguments(&aa, directory, version);
QString versionSpec = version->mkspec();
QString additionalArguments;
if (parsedSpec.isEmpty() || parsedSpec == versionSpec || parsedSpec == "default") {
// using the default spec, don't modify additional arguments
} else {
additionalArguments = "-spec " + Utils::QtcProcess::quoteArg(parsedSpec);
}
Utils::QtcProcess::addArgs(&additionalArguments, aa);
Qt4BuildConfiguration::removeQMLInspectorFromArguments(&additionalArguments);
// So we got all the information now apply it...
setQtVersion(version);
qmakeStep()->setUserArguments(additionalArguments);
setQMakeBuildConfiguration(qmakeBuildConfig);
// Adjust command line arguments, this is ugly as hell
// If we are switching to BuildAll we want "release" in there and no "debug"
// or "debug" in there and no "release"
// If we are switching to not BuildAl we want neither "release" nor "debug" in there
bool debug = qmakeBuildConfig & QtVersion::DebugBuild;
bool haveTag = !(qmakeBuildConfig & QtVersion::BuildAll);
QString makeCmdArguments = makeStep()->userArguments();
Utils::QtcProcess::ArgIterator ait(&makeCmdArguments);
while (ait.next()) {
if (ait.value() == QLatin1String("debug")) {
if (!haveTag && debug)
haveTag = true;
else
ait.deleteArg();
} else if (ait.value() == QLatin1String("release")) {
if (!haveTag && !debug)
haveTag = true;
else
ait.deleteArg();
}
}
if (!haveTag)
ait.appendArg(QLatin1String(debug ? "debug" : "release"));
makeStep()->setUserArguments(makeCmdArguments);
}
}
}
......@@ -123,6 +123,9 @@ public:
ProjectExplorer::IOutputParser *createOutputParser() const;
public slots:
void importFromBuildDirectory();
signals:
/// emitted if the qt version changes (either directly, or because the default qt version changed
/// or because the user changed the settings for the qt version
......
......@@ -404,77 +404,12 @@ void Qt4ProjectConfigWidget::importLabelClicked()
{
if (!m_buildConfiguration->qmakeStep() || !m_buildConfiguration->makeStep())
return;
QString directory = m_buildConfiguration->buildDirectory();
if (!directory.isEmpty()) {
QString makefile = directory;
if (m_buildConfiguration->makefile().isEmpty())
makefile.append("/Makefile");
else
makefile.append(m_buildConfiguration->makefile());
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(makefile);
if (!qmakePath.isEmpty()) {
QtVersionManager *vm = QtVersionManager::instance();
QtVersion *version = vm->qtVersionForQMakeBinary(qmakePath);
if (!version) {
version = new QtVersion(qmakePath);
vm->addVersion(version);
}
QPair<QtVersion::QmakeBuildConfigs, QString> result =
QtVersionManager::scanMakeFile(directory, version->defaultBuildConfig());
QtVersion::QmakeBuildConfigs qmakeBuildConfig = result.first;
QString aa = result.second;
QString parsedSpec = Qt4BuildConfiguration::extractSpecFromArguments(&aa, directory, version);
QString versionSpec = version->mkspec();
QString additionalArguments;
if (parsedSpec.isEmpty() || parsedSpec == versionSpec || parsedSpec == "default") {
// using the default spec, don't modify additional arguments
} else {
additionalArguments = "-spec " + Utils::QtcProcess::quoteArg(parsedSpec);
}
Utils::QtcProcess::addArgs(&additionalArguments, aa);
Qt4BuildConfiguration::removeQMLInspectorFromArguments(&additionalArguments);
// So we got all the information now apply it...
m_buildConfiguration->setQtVersion(version);
QMakeStep *qmakeStep = m_buildConfiguration->qmakeStep();
qmakeStep->setUserArguments(additionalArguments);
MakeStep *makeStep = m_buildConfiguration->makeStep();
m_buildConfiguration->setQMakeBuildConfiguration(qmakeBuildConfig);
// Adjust command line arguments, this is ugly as hell
// If we are switching to BuildAll we want "release" in there and no "debug"
// or "debug" in there and no "release"
// If we are switching to not BuildAl we want neither "release" nor "debug" in there
bool debug = qmakeBuildConfig & QtVersion::DebugBuild;
bool haveTag = !(qmakeBuildConfig & QtVersion::BuildAll);
QString makeCmdArguments = makeStep->userArguments();
Utils::QtcProcess::ArgIterator ait(&makeCmdArguments);
while (ait.next()) {
if (ait.value() == QLatin1String("debug")) {
if (!haveTag && debug)
haveTag = true;
else
ait.deleteArg();
} else if (ait.value() == QLatin1String("release")) {
if (!haveTag && !debug)
haveTag = true;
else
ait.deleteArg();
}
}
if (!haveTag)
ait.appendArg(QLatin1String(debug ? "debug" : "release"));
makeStep->setUserArguments(makeCmdArguments);
}
}
// All our widgets are updated by signals from the buildconfiguration
// if not, there's either a signal missing
// or we don't respond to it correctly
// We do the importing via a single shot timer due to QTCREATORBUG-2723
// Adding a qtversion might trigger a supportedTargetIds changed signal
// which results in a recreation of all the widgets on the page
// That means also "this" gets deleted
QTimer::singleShot(0, m_buildConfiguration, SLOT(importFromBuildDirectory()));
}
void Qt4ProjectConfigWidget::qtVersionSelected(const QString &)
......
Supports Markdown
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