Fixed loading of build configurations.

Change-Id: Ib9c7924c503440982455b5fc58c8fa2decd9301a
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Radovan Zivkovic
2014-03-28 09:47:06 +01:00
parent 5232f29157
commit 9596a9d79c
10 changed files with 265 additions and 153 deletions

View File

@@ -0,0 +1,132 @@
/**************************************************************************
**
** Copyright (c) 2014 Bojan Petrovic
** Copyright (c) 2014 Radovan Zivkovic
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "utils.h"
#include "vcschemamanager.h"
#include <QFile>
#include <QXmlSchema>
#include <QXmlSchemaValidator>
namespace VcProjectManager {
namespace Internal {
namespace Utils {
bool checkIfVersion2003(const QString &filePath)
{
VcSchemaManager *schemaMgr = VcSchemaManager::instance();
QString vc2003Schema = schemaMgr->documentSchema(Constants::SV_2003);
if (vc2003Schema.isEmpty()) {
return false;
}
QFile schemaFile(vc2003Schema);
schemaFile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&schemaFile, QUrl::fromLocalFile(schemaFile.fileName()));
if (schema.isValid()) {
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
return true;
}
return false;
}
bool checkIfVersion2005(const QString &filePath)
{
VcSchemaManager *schemaMgr = VcSchemaManager::instance();
QString vc2005Schema = schemaMgr->documentSchema(Constants::SV_2005);
if (vc2005Schema.isEmpty())
return false;
QFile schemaFile(vc2005Schema);
schemaFile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&schemaFile, QUrl::fromLocalFile(schemaFile.fileName()));
if (schema.isValid()) {
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
return true;
}
return false;
}
bool checkIfVersion2008(const QString &filePath)
{
VcSchemaManager *schemaMgr = VcSchemaManager::instance();
QString vc2008Schema = schemaMgr->documentSchema(Constants::SV_2008);
if (vc2008Schema.isEmpty())
return false;
QFile schemaFile(vc2008Schema);
schemaFile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&schemaFile, QUrl::fromLocalFile(schemaFile.fileName()));
if (schema.isValid()) {
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
return true;
}
return false;
}
VcDocConstants::DocumentVersion getProjectVersion(const QString &projectPath)
{
if (checkIfVersion2003(projectPath))
return VcDocConstants::DV_MSVC_2003;
else if (checkIfVersion2005(projectPath))
return VcDocConstants::DV_MSVC_2005;
else if (checkIfVersion2008(projectPath))
return VcDocConstants::DV_MSVC_2008;
return VcDocConstants::DV_UNRECOGNIZED;
}
} // namespace Utils
} // namespace Internal
} // namespace VcProjectManager

View File

@@ -0,0 +1,47 @@
/**************************************************************************
**
** Copyright (c) 2014 Bojan Petrovic
** Copyright (c) 2014 Radovan Zivkovic
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef VCPROJECTMANAGER_INTERNAL_UTILS_H
#define VCPROJECTMANAGER_INTERNAL_UTILS_H
#include "vcprojectmodel/vcprojectdocument_constants.h"
#include <QString>
namespace VcProjectManager {
namespace Internal {
namespace Utils {
VcDocConstants::DocumentVersion getProjectVersion(const QString &projectPath);
} // namespace Utils
} // namespace Internal
} // namespace VcProjectManager
#endif // VCPROJECTMANAGER_INTERNAL_UTILS_H

View File

@@ -196,14 +196,10 @@ QString VcMakeStepConfigWidget::displayName() const
QString VcMakeStepConfigWidget::summaryText() const
{
VcProjectBuildConfiguration *bc = m_makeStep->vcProjectBuildConfiguration();
ProjectExplorer::Project *project = bc->target()->project();
VcProjectFile* document = static_cast<VcProjectFile *>(project->document());
MsBuildInformation *msBuild = VcProjectKitInformation::msBuildInfo(m_makeStep->target()->kit());
QFileInfo fileInfo(msBuild->m_executable);
return QString(QLatin1String("<b>MsBuild:</b> %1 %2 %3")).arg(fileInfo.fileName())
.arg(document->filePath())
return QString(QLatin1String("<b>MsBuild:</b> %1 %2")).arg(fileInfo.fileName())
.arg(m_makeStep->buildArgumentsToString());
}

View File

@@ -28,6 +28,8 @@
**
****************************************************************************/
#include "vcproject.h"
#include "vcmakestep.h"
#include "vcprojectbuildconfiguration.h"
#include "vcprojectfile.h"
#include "vcprojectkitinformation.h"
@@ -53,6 +55,8 @@
#include <coreplugin/icontext.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <projectexplorer/buildinfo.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/headerpath.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
@@ -135,17 +139,6 @@ QStringList VcProject::files(Project::FilesMode fileMode) const
return sl;
}
QString VcProject::defaultBuildDirectory() const
{
VcProjectFile* vcFile = static_cast<VcProjectFile *>(document());
return defaultBuildDirectory(vcFile->filePath());
}
QString VcProject::defaultBuildDirectory(const QString &fileName)
{
return QFileInfo(fileName).absolutePath() /* + QLatin1String("-build")*/;
}
bool VcProject::needsConfiguration() const
{
return targets().isEmpty() || !activeTarget() || activeTarget()->buildConfigurations().isEmpty();
@@ -221,14 +214,6 @@ bool VcProject::fromMap(const QVariantMap &map)
return true;
}
bool VcProject::setupTarget(ProjectExplorer::Target *t)
{
t->updateDefaultBuildConfigurations();
t->updateDefaultDeployConfigurations();
return true;
}
/**
* @brief Visit folder node recursive and accumulate Source and Header files
*/
@@ -331,21 +316,6 @@ void VcProject::importBuildConfigurations()
addTarget(createTarget(kit));
}
VcProjectBuildConfiguration *VcProject::findBuildConfiguration(Target *target, const QString &buildConfigurationName) const
{
if (target) {
QList<ProjectExplorer::BuildConfiguration *> buildConfigurationList = target->buildConfigurations();
foreach (ProjectExplorer::BuildConfiguration *bc, buildConfigurationList) {
VcProjectBuildConfiguration *vcBc = qobject_cast<VcProjectBuildConfiguration *>(bc);
if (vcBc && vcBc->displayName() == buildConfigurationName)
return vcBc;
}
}
return 0;
}
void VcProject::allProjectFile(QStringList &allFiles) const
{
if (m_projectFile && m_projectFile->documentModel() && m_projectFile->documentModel()->vcProjectDocument()) {

View File

@@ -63,8 +63,6 @@ public:
ProjectExplorer::IProjectManager *projectManager() const;
ProjectExplorer::ProjectNode *rootProjectNode() const;
QStringList files(FilesMode fileMode) const;
QString defaultBuildDirectory() const;
static QString defaultBuildDirectory(const QString &fileName);
bool needsConfiguration() const;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const;
@@ -76,14 +74,13 @@ private slots:
protected:
bool fromMap(const QVariantMap &map);
bool setupTarget(ProjectExplorer::Target *t);
private:
void addCxxModelFiles(const ProjectExplorer::FolderNode *node, QStringList &sourceFiles);
void updateCodeModels();
void importBuildConfigurations();
VcProjectBuildConfiguration *findBuildConfiguration(ProjectExplorer::Target *target, const QString &buildConfigurationName) const;
void allProjectFile(QStringList &allFiles) const;
VcManager *m_projectManager;
VcProjectFile *m_projectFile;
VcDocProjectNode *m_rootNode;

View File

@@ -28,8 +28,19 @@
**
****************************************************************************/
#include "vcmakestep.h"
#include "interfaces/ivisualstudioproject.h"
#include "interfaces/iconfiguration.h"
#include "interfaces/iconfigurations.h"
#include "interfaces/ifile.h"
#include "interfaces/ifilecontainer.h"
#include "vcprojectbuildconfiguration.h"
#include "vcprojectfile.h"
#include "vcprojectmanagerconstants.h"
#include "utils.h"
#include "vcprojectmodel/configurationcontainer.h"
#include "vcprojectmodel/vcdocumentmodel.h"
#include <coreplugin/mimedatabase.h>
#include <projectexplorer/buildinfo.h>
@@ -59,7 +70,8 @@ namespace Internal {
VcProjectBuildConfiguration::VcProjectBuildConfiguration(Target *parent) :
BuildConfiguration(parent, Core::Id(VC_PROJECT_BC_ID))
{
m_buildDirectory = static_cast<VcProject *>(parent->project())->defaultBuildDirectory();
QFileInfo info(static_cast<VcProjectFile *>(parent->project()->document())->documentModel()->vcProjectDocument()->filePath());
m_buildDirectory = info.canonicalPath() + QLatin1String("-build");
}
VcProjectBuildConfiguration::~VcProjectBuildConfiguration()
@@ -131,20 +143,46 @@ int VcProjectBuildConfigurationFactory::priority(const Kit *k, const QString &pr
QList<BuildInfo *> VcProjectBuildConfigurationFactory::availableBuilds(const Target *parent) const
{
QList<BuildInfo *> result;
result << createBuildInfo(parent->kit(),
parent->project()->projectDirectory());
VcProjectFile *vcProjectFile = qobject_cast<VcProjectFile *>(parent->project()->document());
QTC_ASSERT(vcProjectFile, return result);
IVisualStudioProject *vsProject = vcProjectFile->documentModel()->vcProjectDocument();
QTC_ASSERT(vsProject, return result);
QTC_ASSERT(vsProject->configurations(), return result);
QTC_ASSERT(vsProject->configurations()->configurationContainer(), return result);
for (int i = 0; i < vsProject->configurations()->configurationContainer()->configurationCount(); ++i) {
IConfiguration *config = vsProject->configurations()->configurationContainer()->configuration(i);
QTC_ASSERT(config, continue);
result << createBuildInfo(parent->kit(), config);
}
return result;
}
QList<BuildInfo *> VcProjectBuildConfigurationFactory::availableSetups(
const Kit *k, const QString &projectPath) const
{
Q_UNUSED(k);
QList<BuildInfo *> result;
// TODO: Populate from Configuration
BuildInfo *info = createBuildInfo(k,
Utils::FileName::fromString(VcProject::defaultBuildDirectory(projectPath)));
info->displayName = tr("Default");
result << info;
VcDocConstants::DocumentVersion docVersion = Utils::getProjectVersion(projectPath);
VcDocumentModel documentModel = VcDocumentModel(projectPath, docVersion);
IVisualStudioProject *vsProject = documentModel.vcProjectDocument();
QTC_ASSERT(vsProject, return result);
QTC_ASSERT(vsProject->configurations(), return result);
QTC_ASSERT(vsProject->configurations()->configurationContainer(), return result);
for (int i = 0; i < vsProject->configurations()->configurationContainer()->configurationCount(); ++i) {
IConfiguration *config = vsProject->configurations()->configurationContainer()->configuration(i);
QTC_ASSERT(config, continue);
result << createBuildInfo(k, config);
}
return result;
}
@@ -155,10 +193,29 @@ VcProjectBuildConfiguration *VcProjectBuildConfigurationFactory::create(Target *
QTC_ASSERT(info->kitId == parent->kit()->id(), return 0);
QTC_ASSERT(!info->displayName.isEmpty(), return 0);
VcProjectFile *vcProjectFile = qobject_cast<VcProjectFile *>(parent->project()->document());
QTC_ASSERT(vcProjectFile, return 0);
VcProjectBuildConfiguration *bc = new VcProjectBuildConfiguration(parent);
bc->setDisplayName(info->displayName);
bc->setDefaultDisplayName(info->displayName);
bc->setBuildDirectory(info->buildDirectory);
BuildStepList *buildSteps = bc->stepList(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD));
BuildStepList *cleanSteps = bc->stepList(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN));
QTC_ASSERT(buildSteps, return 0);
QTC_ASSERT(cleanSteps, return 0);
VcMakeStep *makeStep = new VcMakeStep(buildSteps);
QString argument(QLatin1String("/p:configuration=\"") + info->displayName + QLatin1String("\""));
makeStep->addBuildArgument(vcProjectFile->filePath());
makeStep->addBuildArgument(argument);
buildSteps->insertStep(0, makeStep);
makeStep = new VcMakeStep(cleanSteps);
argument = QLatin1String("/p:configuration=\"") + info->displayName + QLatin1String("\" /t:Clean");
makeStep->addBuildArgument(vcProjectFile->filePath());
makeStep->addBuildArgument(argument);
cleanSteps->insertStep(0, makeStep);
return bc;
}
@@ -203,15 +260,15 @@ bool VcProjectBuildConfigurationFactory::canHandle(const Target *t) const
}
BuildInfo *VcProjectBuildConfigurationFactory::createBuildInfo(const ProjectExplorer::Kit *k,
const Utils::FileName &buildDir) const
IConfiguration *config) const
{
BuildInfo *info = new BuildInfo(this);
info->typeName = tr("Build");
info->buildDirectory = buildDir;
info->kitId = k->id();
info->supportsShadowBuild = true;
ProjectExplorer::BuildInfo *buildInfo = new ProjectExplorer::BuildInfo(this);
buildInfo->displayName = config->fullName();
buildInfo->kitId = k->id();
buildInfo->supportsShadowBuild = true;
buildInfo->typeName = config->fullName();
return info;
return buildInfo;
}
} // namespace Internal

View File

@@ -74,7 +74,6 @@ class VcProjectBuildConfigurationFactory : public ProjectExplorer::IBuildConfigu
public:
explicit VcProjectBuildConfigurationFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(const ProjectExplorer::Target *parent) const;
QList<ProjectExplorer::BuildInfo *> availableBuilds(const ProjectExplorer::Target *parent) const;
QList<ProjectExplorer::BuildInfo *> availableSetups(const ProjectExplorer::Kit *k, const QString &projectPath) const;
bool canRestore(const ProjectExplorer::Target *parent, const QVariantMap &map) const;
@@ -89,7 +88,7 @@ public:
private:
bool canHandle(const ProjectExplorer::Target *t) const;
ProjectExplorer::BuildInfo *createBuildInfo(const ProjectExplorer::Kit *k,
const Utils::FileName &buildDir) const;
IConfiguration *config) const;
};
} // namespace Internal

View File

@@ -32,6 +32,7 @@
#include "vcprojectmanager.h"
#include "vcprojectmanagerconstants.h"
#include "vcschemamanager.h"
#include "utils.h"
#include "vcprojectmodel/vcprojectdocument_constants.h"
#include <QtXmlPatterns/QXmlSchema>
@@ -65,14 +66,7 @@ ProjectExplorer::Project *VcManager::openProject(const QString &fileName, QStrin
// check if project is a valid vc project
// versions supported are 2003, 2005 and 2008
VcDocConstants::DocumentVersion docVersion = VcDocConstants::DV_UNRECOGNIZED;
if (checkIfVersion2003(canonicalFilePath))
docVersion = VcDocConstants::DV_MSVC_2003;
else if (checkIfVersion2005(canonicalFilePath))
docVersion = VcDocConstants::DV_MSVC_2005;
else if (checkIfVersion2008(canonicalFilePath))
docVersion = VcDocConstants::DV_MSVC_2008;
VcDocConstants::DocumentVersion docVersion = Utils::getProjectVersion(canonicalFilePath);
if (docVersion != VcDocConstants::DV_UNRECOGNIZED)
return new VcProject(this, canonicalFilePath, docVersion);
@@ -87,82 +81,5 @@ void VcManager::updateContextMenu(Project *project, ProjectExplorer::Node *node)
m_contextProject = project;
}
bool VcManager::checkIfVersion2003(const QString &filePath) const
{
VcSchemaManager *schemaMgr = VcSchemaManager::instance();
QString vc2003Schema = schemaMgr->documentSchema(Constants::SV_2003);
if (vc2003Schema.isEmpty()) {
return false;
}
QFile schemaFile(vc2003Schema);
schemaFile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&schemaFile, QUrl::fromLocalFile(schemaFile.fileName()));
if (schema.isValid()) {
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
return true;
}
return false;
}
bool VcManager::checkIfVersion2005(const QString &filePath) const
{
VcSchemaManager *schemaMgr = VcSchemaManager::instance();
QString vc2005Schema = schemaMgr->documentSchema(Constants::SV_2005);
if (vc2005Schema.isEmpty())
return false;
QFile schemaFile(vc2005Schema);
schemaFile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&schemaFile, QUrl::fromLocalFile(schemaFile.fileName()));
if (schema.isValid()) {
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
return true;
}
return false;
}
bool VcManager::checkIfVersion2008(const QString &filePath) const
{
VcSchemaManager *schemaMgr = VcSchemaManager::instance();
QString vc2008Schema = schemaMgr->documentSchema(Constants::SV_2008);
if (vc2008Schema.isEmpty())
return false;
QFile schemaFile(vc2008Schema);
schemaFile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.load(&schemaFile, QUrl::fromLocalFile(schemaFile.fileName()));
if (schema.isValid()) {
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName())))
return true;
}
return false;
}
} // namespace Internal
} // namespace VcProjectManager

View File

@@ -51,11 +51,6 @@ public:
private slots:
void updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *node);
private:
bool checkIfVersion2003(const QString &filePath) const;
bool checkIfVersion2005(const QString &filePath) const;
bool checkIfVersion2008(const QString &filePath) const;
private:
ProjectExplorer::Project *m_contextProject;
VcProjectBuildOptionsPage *m_configPage;

View File

@@ -13,7 +13,8 @@ HEADERS = vcprojectmanagerplugin.h \
msbuildversionmanager.h \
vcprojectbuildoptionspage.h \
vcschemamanager.h \
menuhandler.h
menuhandler.h \
utils.h
SOURCES = vcprojectmanagerplugin.cpp \
vcprojectmanager.cpp \
@@ -26,7 +27,8 @@ SOURCES = vcprojectmanagerplugin.cpp \
msbuildversionmanager.cpp \
vcprojectbuildoptionspage.cpp \
vcschemamanager.cpp \
menuhandler.cpp
menuhandler.cpp \
utils.cpp
OTHER_FILES += \
VcProject.mimetypes.xml