ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup

This follow the rough pattern of recent *RunConfigurationFactory changes
for build and deploy configurations.

- Collapse the two lines of constructors similar to what
  890c1906e6 did for RunConfigurations
  * Deploy* was purely mechanical
  * Build* ctors are split in connects() in the ctor body
    to create "empty shell for clone" etc
    and build step additions in initialize() functions which
    are only used in the create() case.
  -- Allows to collapse the shared 'ctor()' functions, too.

- Move FooBuildConfigurationFactory::create() implementations
  to FooBuildConfiguration() constructor. That was a strange
  and unneeded ping-pong between factories and objects, and
  furthermore allows one level less of indirection (and for a
  later, left out here, some reduction of the
  FooBuildConfiguration interfaces that were only used to
  accommodate the *Factory::create() functions.

- Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(),
  but there wasn't one in the base classses. Have one there.

- Most canHandle() functions were checking simple restrictions on
  e.g. project or target types, specify those by setters in the
  constructors instead and check them in the base canHandle()

- clone() is generally replaced by a creation of a "shell object"
  and a fromMap(source->toMap()), implemented in the base, there
  are two cases left for Android and Qbs that needed(?) some extra
  polish

- generally use canHandle() in base implementation, instead
  of doing that in all Derived::canFoo()

- as a result, canCreate/create/canClone/clone reimplementations
  are not needed anymore, keep the base implementation for
  now (could be inlined into their only users later), but
  de-virtualize them.

- Combine Ios{Preset,DSym}BuildStepFactory. There was only one
  'dsym' build step they could create.

- Split the 'mangled' id into the ProjectConfiguration subtype
  specific constant identifier, and a QString extraId() bit.
  Only maintain the mangled id in saved settings.

- Make ProjectConfiguration::m_id a constant member, adapt
  all constructors of derived classe.

Not done in this patch:

- Finish possible cosmetic changes on top

- Add a way to specify restrictions to supported Qt versions
  (used in Android/Ios), as the base implementation does not
  depend on the qtsupport plugin

- Combine the QList<X> availableFoo() + createFoo(X) function
  pairs to somthing like a direct
   QList<struct { X; std::function<X()>; }> fooCreators()
  to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base)
  pingpong

- Remove the *Factories from the global object pool

- Do something about priority(). Falling back to plain
  qmake in android+qmake setup is not helpful.

Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
hjk
2017-11-29 12:28:40 +01:00
parent 9d3c5c6ff5
commit 53a151074a
174 changed files with 2042 additions and 4705 deletions

View File

@@ -27,12 +27,23 @@
#include "nimbuildconfigurationwidget.h"
#include "nimcompilerbuildstep.h"
#include "nimproject.h"
#include "nimbuildconfiguration.h"
#include "nimcompilerbuildstep.h"
#include "nimcompilercleanstep.h"
#include "nimproject.h"
#include "../nimconstants.h"
#include <projectexplorer/namedwidget.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <coreplugin/documentmanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildinfo.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildstep.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
@@ -40,9 +51,73 @@ using namespace Utils;
namespace Nim {
static FileName defaultBuildDirectory(const Kit *k,
const QString &projectFilePath,
const QString &bc,
BuildConfiguration::BuildType buildType)
{
QFileInfo projectFileInfo(projectFilePath);
ProjectMacroExpander expander(projectFilePath, projectFileInfo.baseName(), k, bc, buildType);
QString buildDirectory = expander.expand(Core::DocumentManager::buildDirectory());
if (FileUtils::isAbsolutePath(buildDirectory))
return FileName::fromString(buildDirectory);
auto projectDir = FileName::fromString(projectFileInfo.absoluteDir().absolutePath());
auto result = projectDir.appendPath(buildDirectory);
return result;
}
NimBuildConfiguration::NimBuildConfiguration(Target *target)
: BuildConfiguration(target, Constants::C_NIMBUILDCONFIGURATION_ID)
{}
{
}
void NimBuildConfiguration::initialize(const BuildInfo *info)
{
BuildConfiguration::initialize(info);
auto project = qobject_cast<NimProject *>(target()->project());
QTC_ASSERT(project, return);
// Create the build configuration and initialize it from build info
setBuildDirectory(defaultBuildDirectory(target()->kit(),
project->projectFilePath().toString(),
info->displayName,
info->buildType));
// Add nim compiler build step
{
BuildStepList *buildSteps = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
auto nimCompilerBuildStep = new NimCompilerBuildStep(buildSteps);
NimCompilerBuildStep::DefaultBuildOptions defaultOption;
switch (info->buildType) {
case BuildConfiguration::Release:
defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Release;
break;
case BuildConfiguration::Debug:
defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Debug;
break;
default:
defaultOption = NimCompilerBuildStep::DefaultBuildOptions::Empty;
break;
}
nimCompilerBuildStep->setDefaultCompilerOptions(defaultOption);
Utils::FileNameList nimFiles = project->nimFiles();
if (!nimFiles.isEmpty())
nimCompilerBuildStep->setTargetNimFile(nimFiles.first());
buildSteps->appendStep(nimCompilerBuildStep);
}
// Add clean step
{
BuildStepList *cleanSteps = stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
cleanSteps->appendStep(new NimCompilerCleanStep(cleanSteps));
}
}
NamedWidget *NimBuildConfiguration::createConfigWidget()
{
@@ -59,9 +134,6 @@ bool NimBuildConfiguration::fromMap(const QVariantMap &map)
if (!BuildConfiguration::fromMap(map))
return false;
if (!canRestore(map))
return false;
const QString displayName = map[Constants::C_NIMBUILDCONFIGURATION_DISPLAY_KEY].toString();
const QString buildDirectory = map[Constants::C_NIMBUILDCONFIGURATION_BUILDDIRECTORY_KEY].toString();
@@ -91,23 +163,6 @@ FileName NimBuildConfiguration::outFilePath() const
return step->outFilePath();
}
bool NimBuildConfiguration::canRestore(const QVariantMap &map)
{
return idFromMap(map) == Constants::C_NIMBUILDCONFIGURATION_ID;
}
bool NimBuildConfiguration::hasNimCompilerBuildStep() const
{
BuildStepList *steps = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
return steps ? steps->contains(Constants::C_NIMCOMPILERBUILDSTEP_ID) : false;
}
bool NimBuildConfiguration::hasNimCompilerCleanStep() const
{
BuildStepList *steps = stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
return steps ? steps->contains(Constants::C_NIMCOMPILERCLEANSTEP_ID) : false;
}
const NimCompilerBuildStep *NimBuildConfiguration::nimCompilerBuildStep() const
{
BuildStepList *steps = stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
@@ -118,5 +173,48 @@ const NimCompilerBuildStep *NimBuildConfiguration::nimCompilerBuildStep() const
return nullptr;
}
NimBuildConfigurationFactory::NimBuildConfigurationFactory()
{
registerBuildConfiguration<NimBuildConfiguration>(Constants::C_NIMBUILDCONFIGURATION_ID);
setSupportedProjectType(Constants::C_NIMPROJECT_ID);
setSupportedProjectMimeTypeName(Constants::C_NIM_PROJECT_MIMETYPE);
}
QList<BuildInfo *> NimBuildConfigurationFactory::availableBuilds(const Target *parent) const
{
// Retrieve the project path
auto project = qobject_cast<NimProject *>(parent->project());
QTC_ASSERT(project, return {});
// Create the build info
BuildInfo *info = createBuildInfo(parent->kit(), project->projectFilePath().toString(),
BuildConfiguration::Debug);
info->displayName.clear(); // ask for a name
info->buildDirectory.clear(); // This depends on the displayName
return {info};
}
QList<BuildInfo *> NimBuildConfigurationFactory::availableSetups(const Kit *k, const QString &projectPath) const
{
BuildInfo *debug = createBuildInfo(k, projectPath, BuildConfiguration::Debug);
BuildInfo *release = createBuildInfo(k, projectPath, BuildConfiguration::Release);
return {debug, release};
}
BuildInfo *NimBuildConfigurationFactory::createBuildInfo(const Kit *k, const QString &projectFilePath,
BuildConfiguration::BuildType buildType) const
{
auto result = new BuildInfo(this);
result->buildType = buildType;
result->displayName = BuildConfiguration::buildTypeName(buildType);
result->buildDirectory = defaultBuildDirectory(k, projectFilePath, result->displayName, buildType);
result->kitId = k->id();
result->typeName = tr("Build");
return result;
}
} // namespace Nim