Commit a36dc1d4 authored by dt's avatar dt

Qt4ProjectManager: Support Makefile variable

Pass on the makefile to make, check the right makefile for importing.

Task-Nr: QTCREATORBUG-102
parent 51bfe658
......@@ -149,7 +149,19 @@ bool MakeStep::init()
// we should stop the clean queue
// That is mostly so that rebuild works on a already clean project
setIgnoreReturnValue(m_clean);
QStringList args = m_userArgs;
QStringList args;
ProjectExplorer::ToolChain *toolchain = bc->toolChain();
if (bc->subNodeBuild()){
if(!bc->subNodeBuild()->makefile().isEmpty()) {
args << "-f" << bc->subNodeBuild()->makefile();
}
} else if (!bc->makefile().isEmpty()) {
args << "-f" << bc->makefile();
}
args.append(m_userArgs);
if (!m_clean) {
if (!bc->defaultMakeTarget().isEmpty())
args << bc->defaultMakeTarget();
......@@ -159,7 +171,6 @@ bool MakeStep::init()
// FIXME doing this without the user having a way to override this is rather bad
// so we only do it for unix and if the user didn't override the make command
// but for now this is the least invasive change
ProjectExplorer::ToolChain *toolchain = bc->toolChain();
if (toolchain) {
if (toolchain->type() != ProjectExplorer::ToolChain::MSVC &&
......
......@@ -165,6 +165,7 @@ bool QMakeStep::init()
QStringList args = allArguments();
QString workingDirectory;
if (qt4bc->subNodeBuild())
workingDirectory = qt4bc->subNodeBuild()->buildDir();
else
......@@ -174,10 +175,24 @@ bool QMakeStep::init()
// Check whether we need to run qmake
m_needToRunQMake = true;
if (QDir(workingDirectory).exists(QLatin1String("Makefile"))) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(workingDirectory);
QString makefile = workingDirectory;
if (qt4bc->subNodeBuild()) {
if (!qt4bc->subNodeBuild()->makefile().isEmpty()) {
makefile.append(qt4bc->subNodeBuild()->makefile());
} else {
makefile.append("/Makefile");
}
} else if (!qt4bc->makefile().isEmpty()) {
makefile.append(qt4bc->makefile());
} else {
makefile.append("/Makefile");
}
if (QFileInfo(makefile).exists()) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(makefile);
if (qtVersion->qmakeCommand() == qmakePath) {
m_needToRunQMake = !qt4bc->compareToImportFrom(workingDirectory);
m_needToRunQMake = !qt4bc->compareToImportFrom(makefile);
}
}
......
......@@ -317,6 +317,13 @@ QString Qt4BuildConfiguration::defaultMakeTarget() const
return QString();
}
QString Qt4BuildConfiguration::makefile() const
{
if (qt4Target()->id() == Constants::S60_DEVICE_TARGET_ID)
return QString();
return qt4Target()->qt4Project()->rootProjectNode()->makefile();
}
QtVersion *Qt4BuildConfiguration::qtVersion() const
{
QtVersionManager *vm = QtVersionManager::instance();
......@@ -455,21 +462,22 @@ void Qt4BuildConfiguration::qtVersionsChanged(const QList<int> &changedVersions)
}
// returns true if both are equal
bool Qt4BuildConfiguration::compareToImportFrom(const QString &workingDirectory)
bool Qt4BuildConfiguration::compareToImportFrom(const QString &makefile)
{
QMakeStep *qs = qmakeStep();
if (QDir(workingDirectory).exists(QLatin1String("Makefile")) && qs) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(workingDirectory);
if (QFileInfo(makefile).exists() && qs) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(makefile);
QtVersion *version = qtVersion();
if (version->qmakeCommand() == qmakePath) {
// same qtversion
QPair<QtVersion::QmakeBuildConfigs, QStringList> result =
QtVersionManager::scanMakeFile(workingDirectory, version->defaultBuildConfig());
QtVersionManager::scanMakeFile(makefile, version->defaultBuildConfig());
if (qmakeBuildConfiguration() == result.first) {
// The qmake Build Configuration are the same,
// now compare arguments lists
// we have to compare without the spec/platform cmd argument
// and compare that on its own
QString workingDirectory = QFileInfo(makefile).absolutePath();
QString actualSpec = extractSpecFromArgumentList(qs->userArguments(), workingDirectory, version);
if (actualSpec.isEmpty()) {
// Easy one: the user has chosen not to override the settings
......
......@@ -102,8 +102,9 @@ public:
QString makeCommand() const;
QString defaultMakeTarget() const;
QString makefile() const;
bool compareToImportFrom(const QString &workingDirectory);
bool compareToImportFrom(const QString &makefile);
static QStringList removeQMLInspectorFromArgumentList(const QStringList &old);
static QStringList removeSpecFromArgumentList(const QStringList &old);
static QString extractSpecFromArgumentList(const QStringList &list, QString directory, QtVersion *version);
......
......@@ -1208,6 +1208,13 @@ TargetInformation Qt4ProFileNode::targetInformation(const QString &fileName) con
return qt4ProFileNode->targetInformation();
}
QString Qt4ProFileNode::makefile() const
{
if (m_varValues[Makefile].isEmpty())
return QString();
return m_varValues[Makefile].first();
}
/*!
\class Qt4ProFileNode
Implements abstract ProjectNode class
......@@ -1593,6 +1600,7 @@ void Qt4ProFileNode::applyEvaluate(bool parseResult, bool async)
newVarValues[ConfigVar] = m_readerExact->values(QLatin1String("CONFIG"));
newVarValues[QmlImportPathVar] = m_readerExact->absolutePathValues(
QLatin1String("QML_IMPORT_PATH"), m_projectDir);
newVarValues[Makefile] = m_readerExact->values("MAKEFILE");
if (m_varValues != newVarValues) {
m_varValues = newVarValues;
......
......@@ -95,7 +95,8 @@ enum Qt4Variable {
PrecompiledHeaderVar,
LibDirectoriesVar,
ConfigVar,
QmlImportPathVar
QmlImportPathVar,
Makefile
};
class Qt4PriFileNode;
......@@ -278,6 +279,8 @@ public:
TargetInformation targetInformation(const QString &fileName) const;
TargetInformation targetInformation() const;
QString makefile() const;
void update();
void scheduleUpdate();
......
......@@ -299,7 +299,13 @@ void Qt4ProjectConfigWidget::updateImportLabel()
QtVersionManager *vm = QtVersionManager::instance();
// we only show if we actually have a qmake and makestep
if (m_buildConfiguration->qmakeStep() && m_buildConfiguration->makeStep()) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(m_buildConfiguration->buildDirectory());
QString makefile = m_buildConfiguration->buildDirectory();
if (m_buildConfiguration->makefile().isEmpty())
makefile.append("/Makefile");
else
makefile.append(m_buildConfiguration->makefile());
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(makefile);
QtVersion *version = m_buildConfiguration->qtVersion();
// check that there's a makefile
if (!qmakePath.isEmpty()) {
......@@ -318,7 +324,7 @@ void Qt4ProjectConfigWidget::updateImportLabel()
delete newVersion;
} else {
// check that the qmake flags, arguments match
visible = !m_buildConfiguration->compareToImportFrom(m_buildConfiguration->buildDirectory());
visible = !m_buildConfiguration->compareToImportFrom(makefile);
targetMatches = true;
}
} else {
......@@ -377,7 +383,13 @@ void Qt4ProjectConfigWidget::importLabelClicked()
return;
QString directory = m_buildConfiguration->buildDirectory();
if (!directory.isEmpty()) {
QString qmakePath = QtVersionManager::findQMakeBinaryFromMakefile(directory);
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);
......
......@@ -803,12 +803,12 @@ void QtVersion::updateSourcePath()
// That is returns the directory
// To find out whether we already have a qtversion for that directory call
// QtVersion *QtVersionManager::qtVersionForDirectory(const QString directory);
QString QtVersionManager::findQMakeBinaryFromMakefile(const QString &directory)
QString QtVersionManager::findQMakeBinaryFromMakefile(const QString &makefile)
{
bool debugAdding = false;
QFile makefile(directory + "/Makefile" );
if (makefile.exists() && makefile.open(QFile::ReadOnly)) {
QTextStream ts(&makefile);
QFile fi(makefile);
if (fi.exists() && fi.open(QFile::ReadOnly)) {
QTextStream ts(&fi);
QRegExp r1("QMAKE\\s*=(.*)");
while (!ts.atEnd()) {
QString line = ts.readLine();
......@@ -854,32 +854,31 @@ void dumpQMakeAssignments(const QList<QMakeAssignment> &list)
}
}
bool QtVersionManager::makefileIsFor(const QString &directory, const QString &proFile)
bool QtVersionManager::makefileIsFor(const QString &makefile, const QString &proFile)
{
if (proFile.isEmpty())
return true;
QString line = findQMakeLine(directory, QLatin1String("# Project:")).trimmed();
QString line = findQMakeLine(makefile, QLatin1String("# Project:")).trimmed();
if (line.isEmpty())
return false;
line = line.mid(line.indexOf(QChar(':')) + 1);
line = line.trimmed();
QFileInfo srcFileInfo(QDir(directory), line);
QFileInfo srcFileInfo(QFileInfo(makefile).absoluteDir(), line);
QFileInfo proFileInfo(proFile);
return srcFileInfo == proFileInfo;
}
QPair<QtVersion::QmakeBuildConfigs, QStringList> QtVersionManager::scanMakeFile(const QString &directory, QtVersion::QmakeBuildConfigs defaultBuildConfig)
QPair<QtVersion::QmakeBuildConfigs, QStringList> QtVersionManager::scanMakeFile(const QString &makefile, QtVersion::QmakeBuildConfigs defaultBuildConfig)
{
if (debug)
qDebug()<<"ScanMakeFile, the gory details:";
QtVersion::QmakeBuildConfigs result = defaultBuildConfig;
QStringList result2;
QString line = findQMakeLine(directory, QLatin1String("# Command:"));
QString line = findQMakeLine(makefile, QLatin1String("# Command:"));
if (!line.isEmpty()) {
if (debug)
qDebug()<<"Found line"<<line;
......@@ -930,11 +929,11 @@ QPair<QtVersion::QmakeBuildConfigs, QStringList> QtVersionManager::scanMakeFile(
return qMakePair(result, result2);
}
QString QtVersionManager::findQMakeLine(const QString &directory, const QString &key)
QString QtVersionManager::findQMakeLine(const QString &makefile, const QString &key)
{
QFile makefile(directory + QLatin1String("/Makefile" ));
if (makefile.exists() && makefile.open(QFile::ReadOnly)) {
QTextStream ts(&makefile);
QFile fi(makefile);
if (fi.exists() && fi.open(QFile::ReadOnly)) {
QTextStream ts(&fi);
while (!ts.atEnd()) {
const QString line = ts.readLine();
if (line.startsWith(key))
......
......@@ -250,10 +250,10 @@ public:
QSet<QString> supportedTargetIds() const;
// Static Methods
static bool makefileIsFor(const QString &directory, const QString &proFile);
static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &directory,
static bool makefileIsFor(const QString &makefile, const QString &proFile);
static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &makefile,
QtVersion::QmakeBuildConfigs defaultBuildConfig);
static QString findQMakeBinaryFromMakefile(const QString &directory);
static QString findQMakeBinaryFromMakefile(const QString &makefile);
bool isValidId(int id) const;
signals:
......
......@@ -379,11 +379,11 @@ TargetSetupPage::recursivelyCheckDirectoryForBuild(const QString &directory, con
return results;
// Check for in-source builds first:
QString qmakeBinary = QtVersionManager::findQMakeBinaryFromMakefile(directory);
QString qmakeBinary = QtVersionManager::findQMakeBinaryFromMakefile(directory + "/Makefile");
QDir dir(directory);
// Recurse into subdirectories:
if (qmakeBinary.isNull() || !QtVersionManager::makefileIsFor(directory, proFile)) {
if (qmakeBinary.isNull() || !QtVersionManager::makefileIsFor(directory + "/Makefile", proFile)) {
QStringList subDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach (QString subDir, subDirs)
results.append(recursivelyCheckDirectoryForBuild(dir.absoluteFilePath(subDir),
......@@ -409,7 +409,7 @@ TargetSetupPage::recursivelyCheckDirectoryForBuild(const QString &directory, con
}
QPair<QtVersion::QmakeBuildConfigs, QStringList> result =
QtVersionManager::scanMakeFile(directory, info.version->defaultBuildConfig());
QtVersionManager::scanMakeFile(directory + "/Makefile", info.version->defaultBuildConfig());
info.buildConfig = result.first;
info.additionalArguments = Qt4BuildConfiguration::removeSpecFromArgumentList(result.second);
......
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