Commit f5d77071 authored by Tobias Hunger's avatar Tobias Hunger

Qbs: Allow for building products

Change-Id: Id6fcdbdb0c776458eb16c7fc6765046969c2658e
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 47800614
...@@ -193,6 +193,16 @@ QStringList QbsBuildConfiguration::changedFiles() const ...@@ -193,6 +193,16 @@ QStringList QbsBuildConfiguration::changedFiles() const
return m_changedFiles; return m_changedFiles;
} }
void QbsBuildConfiguration::setProducts(const QStringList &products)
{
m_products = products;
}
QStringList QbsBuildConfiguration::products() const
{
return m_products;
}
QbsBuildConfiguration *QbsBuildConfiguration::setup(ProjectExplorer::Target *t, QbsBuildConfiguration *QbsBuildConfiguration::setup(ProjectExplorer::Target *t,
const QString &defaultDisplayName, const QString &defaultDisplayName,
const QString &displayName, const QString &displayName,
......
...@@ -73,6 +73,9 @@ public: ...@@ -73,6 +73,9 @@ public:
void setChangedFiles(const QStringList &files); void setChangedFiles(const QStringList &files);
QStringList changedFiles() const; QStringList changedFiles() const;
void setProducts(const QStringList &products);
QStringList products() const;
signals: signals:
void qbsConfigurationChanged(); void qbsConfigurationChanged();
...@@ -96,6 +99,7 @@ private: ...@@ -96,6 +99,7 @@ private:
bool m_parsingError; bool m_parsingError;
Utils::FileName m_buildDirectory; Utils::FileName m_buildDirectory;
QStringList m_changedFiles; QStringList m_changedFiles;
QStringList m_products;
friend class QbsBuildConfigurationFactory; friend class QbsBuildConfigurationFactory;
friend class QbsBuildConfigurationWidget; friend class QbsBuildConfigurationWidget;
......
...@@ -102,6 +102,7 @@ bool QbsBuildStep::init() ...@@ -102,6 +102,7 @@ bool QbsBuildStep::init()
m_parser->appendOutputParser(parser); m_parser->appendOutputParser(parser);
m_changedFiles = bc->changedFiles(); m_changedFiles = bc->changedFiles();
m_products = bc->products();
connect(m_parser, SIGNAL(addOutput(QString,ProjectExplorer::BuildStep::OutputFormat)), connect(m_parser, SIGNAL(addOutput(QString,ProjectExplorer::BuildStep::OutputFormat)),
this, SIGNAL(addOutput(QString,ProjectExplorer::BuildStep::OutputFormat))); this, SIGNAL(addOutput(QString,ProjectExplorer::BuildStep::OutputFormat)));
...@@ -119,7 +120,7 @@ void QbsBuildStep::run(QFutureInterface<bool> &fi) ...@@ -119,7 +120,7 @@ void QbsBuildStep::run(QFutureInterface<bool> &fi)
qbs::BuildOptions options(m_qbsBuildOptions); qbs::BuildOptions options(m_qbsBuildOptions);
options.setChangedFiles(m_changedFiles); options.setChangedFiles(m_changedFiles);
m_job = pro->build(options); m_job = pro->build(options, m_products);
if (!m_job) { if (!m_job) {
m_fi->reportResult(false); m_fi->reportResult(false);
......
...@@ -96,6 +96,7 @@ private: ...@@ -96,6 +96,7 @@ private:
QVariantMap m_qbsConfiguration; QVariantMap m_qbsConfiguration;
qbs::BuildOptions m_qbsBuildOptions; qbs::BuildOptions m_qbsBuildOptions;
QStringList m_changedFiles; QStringList m_changedFiles;
QStringList m_products;
QFutureInterface<bool> *m_fi; QFutureInterface<bool> *m_fi;
qbs::BuildJob *m_job; qbs::BuildJob *m_job;
......
...@@ -179,11 +179,29 @@ void QbsProject::invalidate() ...@@ -179,11 +179,29 @@ void QbsProject::invalidate()
prepareForParsing(); prepareForParsing();
} }
qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts) qbs::BuildJob *QbsProject::build(const qbs::BuildOptions &opts, QStringList productNames)
{ {
if (!qbsProject() || isParsing()) if (!qbsProject() || isParsing())
return 0; return 0;
return qbsProject()->buildAllProducts(opts); if (productNames.isEmpty()) {
return qbsProject()->buildAllProducts(opts);
} else {
QList<qbs::ProductData> products;
foreach (const QString &productName, productNames) {
bool found = false;
foreach (const qbs::ProductData &data, qbsProjectData()->products()) {
if (data.name() == productName) {
found = true;
products.append(data);
break;
}
}
if (!found)
return 0;
}
return qbsProject()->buildSomeProducts(products, opts);
}
} }
qbs::CleanJob *QbsProject::clean(const qbs::CleanOptions &opts) qbs::CleanJob *QbsProject::clean(const qbs::CleanOptions &opts)
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
QStringList files(FilesMode fileMode) const; QStringList files(FilesMode fileMode) const;
qbs::BuildJob *build(const qbs::BuildOptions &opts); qbs::BuildJob *build(const qbs::BuildOptions &opts, QStringList products = QStringList());
qbs::CleanJob *clean(const qbs::CleanOptions &opts); qbs::CleanJob *clean(const qbs::CleanOptions &opts);
qbs::InstallJob *install(const qbs::InstallOptions &opts); qbs::InstallJob *install(const qbs::InstallOptions &opts);
......
...@@ -49,6 +49,8 @@ const char ACTION_REPARSE_QBS[] = "Qbs.Reparse"; ...@@ -49,6 +49,8 @@ const char ACTION_REPARSE_QBS[] = "Qbs.Reparse";
const char ACTION_REPARSE_QBS_CONTEXT[] = "Qbs.ReparseCtx"; const char ACTION_REPARSE_QBS_CONTEXT[] = "Qbs.ReparseCtx";
const char ACTION_BUILD_FILE_CONTEXT[] = "Qbs.BuildFileCtx"; const char ACTION_BUILD_FILE_CONTEXT[] = "Qbs.BuildFileCtx";
const char ACTION_BUILD_FILE[] = "Qbs.BuildFile"; const char ACTION_BUILD_FILE[] = "Qbs.BuildFile";
const char ACTION_BUILD_PRODUCT_CONTEXT[] = "Qbs.BuildProductCtx";
const char ACTION_BUILD_PRODUCT[] = "Qbs.BuildProduct";
// Ids: // Ids:
const char QBS_BUILDSTEP_ID[] = "Qbs.BuildStep"; const char QBS_BUILDSTEP_ID[] = "Qbs.BuildStep";
......
...@@ -77,6 +77,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString * ...@@ -77,6 +77,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
m_manager = new QbsManager(this); m_manager = new QbsManager(this);
m_projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance(); m_projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
const Core::Context projectContext(::QbsProjectManager::Constants::PROJECT_ID); const Core::Context projectContext(::QbsProjectManager::Constants::PROJECT_ID);
const Core::Context globalcontext(Core::Constants::C_GLOBAL);
Q_UNUSED(arguments); Q_UNUSED(arguments);
...@@ -100,10 +101,8 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString * ...@@ -100,10 +101,8 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
// PE Context menu for projects // PE Context menu for projects
Core::ActionContainer *mproject = Core::ActionContainer *mproject =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT); Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
// <debug> Core::ActionContainer *msubproject =
// Core::ActionContainer *msubproject = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
// Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
// </debug>
Core::ActionContainer *mfile = Core::ActionContainer *mfile =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT); Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
...@@ -129,7 +128,6 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString * ...@@ -129,7 +128,6 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER); mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER);
connect(m_buildFileContextMenu, SIGNAL(triggered()), this, SLOT(buildFileContextMenu())); connect(m_buildFileContextMenu, SIGNAL(triggered()), this, SLOT(buildFileContextMenu()));
const Core::Context globalcontext(Core::Constants::C_GLOBAL);
m_buildFile = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""), m_buildFile = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this); Utils::ParameterAction::AlwaysEnabled, this);
command = Core::ActionManager::registerAction(m_buildFile, Constants::ACTION_BUILD_FILE, globalcontext); command = Core::ActionManager::registerAction(m_buildFile, Constants::ACTION_BUILD_FILE, globalcontext);
...@@ -140,6 +138,22 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString * ...@@ -140,6 +138,22 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_buildFile, SIGNAL(triggered()), this, SLOT(buildFile())); connect(m_buildFile, SIGNAL(triggered()), this, SLOT(buildFile()));
m_buildProductContextMenu = new QAction(tr("Build"), this);
command = Core::ActionManager::registerAction(m_buildProductContextMenu, Constants::ACTION_BUILD_PRODUCT_CONTEXT, projectContext);
command->setAttribute(Core::Command::CA_Hide);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_buildProductContextMenu, SIGNAL(triggered()), this, SLOT(buildProductContextMenu()));
m_buildProduct = new Utils::ParameterAction(tr("Build Product"), tr("Build Product \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
command = Core::ActionManager::registerAction(m_buildProduct, Constants::ACTION_BUILD_PRODUCT, globalcontext);
command->setAttribute(Core::Command::CA_Hide);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDescription(m_buildFile->text());
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Shift+B")));
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_buildProduct, SIGNAL(triggered()), this, SLOT(buildProduct()));
// Connect // Connect
connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)), connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
this, SLOT(updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*))); this, SLOT(updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*)));
...@@ -148,12 +162,12 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString * ...@@ -148,12 +162,12 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
this, SLOT(buildStateChanged(ProjectExplorer::Project*))); this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateBuildFileAction())); this, SLOT(updateBuildActions()));
// Run initial setup routines // Run initial setup routines
updateContextActions(0, 0); updateContextActions(0, 0);
updateReparseQbsAction(); updateReparseQbsAction();
updateBuildFileAction(); updateBuildActions();
return true; return true;
} }
...@@ -187,10 +201,12 @@ void QbsProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node, ...@@ -187,10 +201,12 @@ void QbsProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node,
bool isBuilding = m_projectExplorer->buildManager()->isBuilding(project); bool isBuilding = m_projectExplorer->buildManager()->isBuilding(project);
bool isFile = m_currentProject && node && (node->nodeType() == ProjectExplorer::FileNodeType); bool isFile = m_currentProject && node && (node->nodeType() == ProjectExplorer::FileNodeType);
bool isProduct = m_currentProject && node && qobject_cast<QbsProductNode *>(node->projectNode());
bool isFileEnabled = isFile && node->isEnabled(); bool isFileEnabled = isFile && node->isEnabled();
m_reparseQbsCtx->setEnabled(!isBuilding && m_currentProject && !m_currentProject->isParsing()); m_reparseQbsCtx->setEnabled(!isBuilding && m_currentProject && !m_currentProject->isParsing());
m_buildFileContextMenu->setEnabled(isFileEnabled); m_buildFileContextMenu->setEnabled(isFileEnabled);
m_buildProductContextMenu->setEnabled(isProduct);
} }
void QbsProjectManagerPlugin::updateReparseQbsAction() void QbsProjectManagerPlugin::updateReparseQbsAction()
...@@ -200,12 +216,15 @@ void QbsProjectManagerPlugin::updateReparseQbsAction() ...@@ -200,12 +216,15 @@ void QbsProjectManagerPlugin::updateReparseQbsAction()
&& !m_currentProject->isParsing()); && !m_currentProject->isParsing());
} }
void QbsProjectManagerPlugin::updateBuildFileAction() void QbsProjectManagerPlugin::updateBuildActions()
{ {
bool visible = false; bool fileVisible = false;
bool enabled = false; bool fileEnabled = false;
bool productVisible = false;
bool productEnabled = false;
QString file; QString file;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) {
file = currentEditor->document()->fileName(); file = currentEditor->document()->fileName();
ProjectExplorer::SessionManager *session = m_projectExplorer->session(); ProjectExplorer::SessionManager *session = m_projectExplorer->session();
...@@ -214,14 +233,22 @@ void QbsProjectManagerPlugin::updateBuildFileAction() ...@@ -214,14 +233,22 @@ void QbsProjectManagerPlugin::updateBuildFileAction()
= qobject_cast<QbsProject *>(session->projectForFile(file)); = qobject_cast<QbsProject *>(session->projectForFile(file));
m_buildFile->setParameter(QFileInfo(file).fileName()); m_buildFile->setParameter(QFileInfo(file).fileName());
visible = project && node && qobject_cast<QbsBaseProjectNode *>(node->projectNode()); fileVisible = project && node && qobject_cast<QbsBaseProjectNode *>(node->projectNode());
fileEnabled = !m_projectExplorer->buildManager()->isBuilding(project)
enabled = !m_projectExplorer->buildManager()->isBuilding(project)
&& m_currentProject && !m_currentProject->isParsing(); && m_currentProject && !m_currentProject->isParsing();
if (QbsProductNode *productNode = qobject_cast<QbsProductNode *>(node->projectNode())) {
productEnabled = true;
productVisible = true;
m_buildProduct->setParameter(productNode->displayName());
}
} }
m_buildFile->setEnabled(enabled); m_buildFile->setEnabled(fileEnabled);
m_buildFile->setVisible(visible); m_buildFile->setVisible(fileVisible);
m_buildProduct->setEnabled(productEnabled);
m_buildProduct->setVisible(productVisible);
} }
void QbsProjectManagerPlugin::activeTargetChanged() void QbsProjectManagerPlugin::activeTargetChanged()
...@@ -244,7 +271,7 @@ void QbsProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *projec ...@@ -244,7 +271,7 @@ void QbsProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *projec
if (project == m_currentProject) { if (project == m_currentProject) {
updateReparseQbsAction(); updateReparseQbsAction();
updateContextActions(m_currentNode, m_currentProject); updateContextActions(m_currentNode, m_currentProject);
updateBuildFileAction(); updateBuildActions();
} }
} }
...@@ -279,6 +306,32 @@ void QbsProjectManagerPlugin::buildFile() ...@@ -279,6 +306,32 @@ void QbsProjectManagerPlugin::buildFile()
buildFiles(project, QStringList(file)); buildFiles(project, QStringList(file));
} }
void QbsProjectManagerPlugin::buildProductContextMenu()
{
QTC_ASSERT(m_currentNode, return);
QTC_ASSERT(m_currentProject, return);
buildProducts(m_currentProject, QStringList(m_currentNode->displayName()));
}
void QbsProjectManagerPlugin::buildProduct()
{
QbsProject *project = 0;
QbsProductNode *product = 0;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) {
const QString file = currentEditor->document()->fileName();
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
project = qobject_cast<QbsProject *>(session->projectForFile(file));
product = qobject_cast<QbsProductNode *>(session->nodeForFile(file)->projectNode());
}
if (!project || !product)
return;
buildProducts(project, QStringList(product->displayName()));
}
void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList &files) void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList &files)
{ {
QTC_ASSERT(project, return); QTC_ASSERT(project, return);
...@@ -296,6 +349,7 @@ void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList ...@@ -296,6 +349,7 @@ void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList
return; return;
bc->setChangedFiles(files); bc->setChangedFiles(files);
bc->setProducts(QStringList());
const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD); const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
...@@ -305,6 +359,33 @@ void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList ...@@ -305,6 +359,33 @@ void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList
bc->setChangedFiles(QStringList()); bc->setChangedFiles(QStringList());
} }
void QbsProjectManagerPlugin::buildProducts(QbsProject *project, const QStringList &products)
{
QTC_ASSERT(project, return);
QTC_ASSERT(!products.isEmpty(), return);
ProjectExplorer::Target *t = project->activeTarget();
if (!t)
return;
QbsBuildConfiguration *bc = qobject_cast<QbsBuildConfiguration *>(t->activeBuildConfiguration());
if (!bc)
return;
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
if (!pe->saveModifiedFiles())
return;
bc->setChangedFiles(QStringList());
bc->setProducts(products);
const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
const QString name = ProjectExplorer::ProjectExplorerPlugin::displayNameForStepId(buildStep);
pe->buildManager()->buildList(bc->stepList(buildStep), name);
bc->setProducts(QStringList());
}
void QbsProjectManagerPlugin::reparseCurrentProject() void QbsProjectManagerPlugin::reparseCurrentProject()
{ {
if (m_currentProject) if (m_currentProject)
......
...@@ -68,17 +68,20 @@ public: ...@@ -68,17 +68,20 @@ public:
private slots: private slots:
void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project); void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
void updateReparseQbsAction(); void updateReparseQbsAction();
void updateBuildFileAction(); void updateBuildActions();
void activeTargetChanged(); void activeTargetChanged();
void buildStateChanged(ProjectExplorer::Project *project); void buildStateChanged(ProjectExplorer::Project *project);
void parsingStateChanged(); void parsingStateChanged();
void buildFileContextMenu(); void buildFileContextMenu();
void buildFile(); void buildFile();
void buildProductContextMenu();
void buildProduct();
void reparseCurrentProject(); void reparseCurrentProject();
private: private:
void buildFiles(QbsProject *project, const QStringList &files); void buildFiles(QbsProject *project, const QStringList &files);
void buildProducts(QbsProject *project, const QStringList &products);
QbsManager *m_manager; QbsManager *m_manager;
ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer; ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer;
...@@ -86,7 +89,9 @@ private: ...@@ -86,7 +89,9 @@ private:
QAction *m_reparseQbs; QAction *m_reparseQbs;
QAction *m_reparseQbsCtx; QAction *m_reparseQbsCtx;
QAction *m_buildFileContextMenu; QAction *m_buildFileContextMenu;
QAction *m_buildProductContextMenu;
Utils::ParameterAction *m_buildFile; Utils::ParameterAction *m_buildFile;
Utils::ParameterAction *m_buildProduct;
Internal::QbsProject *m_currentProject; Internal::QbsProject *m_currentProject;
ProjectExplorer::Target *m_currentTarget; ProjectExplorer::Target *m_currentTarget;
......
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