summaryrefslogtreecommitdiff
path: root/src/lib/tools
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@digia.com>2013-06-11 17:26:18 +0200
committerTobias Hunger <tobias.hunger@digia.com>2013-06-17 16:51:38 +0200
commitaa74bd71956464adc12249055f8f9e29fe3bd5ad (patch)
tree58edf8e65b1ec78fb3b9685b5d7235052eb1f0b0 /src/lib/tools
parent521f597c7ddd907b08e1691e0cb278c3460f5cee (diff)
downloadqbs-aa74bd71956464adc12249055f8f9e29fe3bd5ad.tar.gz
Move expanding of configuration to SetupProjectParameters
This allows Creator to call this explicitly which will then allow to compare the expanded settings with those used by the project before. Change-Id: I68aab208c4d1832c502667207054da2bcb8fa84b Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib/tools')
-rw-r--r--src/lib/tools/setupprojectparameters.cpp106
-rw-r--r--src/lib/tools/setupprojectparameters.h7
2 files changed, 113 insertions, 0 deletions
diff --git a/src/lib/tools/setupprojectparameters.cpp b/src/lib/tools/setupprojectparameters.cpp
index 4370722f8..2862690aa 100644
--- a/src/lib/tools/setupprojectparameters.cpp
+++ b/src/lib/tools/setupprojectparameters.cpp
@@ -28,6 +28,12 @@
****************************************************************************/
#include "setupprojectparameters.h"
+#include <logging/translator.h>
+#include <tools/profile.h>
+#include <tools/qbsassert.h>
+#include <tools/scripttools.h>
+#include <tools/settings.h>
+
namespace qbs {
namespace Internal {
@@ -50,6 +56,7 @@ public:
QStringList searchPaths;
QStringList pluginPaths;
QVariantMap buildConfiguration;
+ mutable QVariantMap buildConfigurationTree;
bool ignoreDifferentProjectFilePath;
bool dryRun;
bool logElapsedTime;
@@ -160,10 +167,109 @@ QVariantMap SetupProjectParameters::buildConfiguration() const
/*!
* Sets the collection of properties to use for resolving the project.
+ *
+ * Keys are expected to be in dotted syntax (e.g. Qt.declarative.qmlDebugging) that is
+ * used by "qbs config".
*/
void SetupProjectParameters::setBuildConfiguration(const QVariantMap &buildConfiguration)
{
+ // warn if somebody tries to set a build configuration tree:
+ for (QVariantMap::const_iterator i = buildConfiguration.constBegin();
+ i != buildConfiguration.constEnd(); ++i) {
+ QBS_ASSERT(i.value().type() != QVariant::Map, return);
+ }
d->buildConfiguration = buildConfiguration;
+ d->buildConfigurationTree.clear();
+}
+
+/*!
+ * \brief Returns the build configuration in tree form.
+ * \return the tree form of the build configuration.
+ */
+QVariantMap SetupProjectParameters::buildConfigurationTree() const
+{
+ if (!d->buildConfigurationTree.isEmpty() && !d->buildConfiguration.isEmpty())
+ return d->buildConfigurationTree;
+
+ QVariantMap result;
+ foreach (const QString &property, d->buildConfiguration.keys()) {
+ QStringList nameElements = property.split('.');
+ if (nameElements.count() > 2) { // ### workaround for submodules being represented internally as a single module of name "module/submodule" rather than two nested modules "module" and "submodule"
+ QStringList allButLast = nameElements;
+ allButLast.removeLast();
+ QStringList newElements(allButLast.join("/"));
+ newElements.append(nameElements.last());
+ nameElements = newElements;
+ }
+ Internal::setConfigProperty(result, nameElements, d->buildConfiguration.value(property));
+ }
+ d->buildConfigurationTree = result;
+ return result;
+}
+
+/*!
+ * \brief Expands the build configuration based on the given settings.
+ *
+ * Expansion is the process by which the build configuration is completed based on the given
+ * settings. E.g. the information configured in a profile is filled into the build
+ * configuration by this step.
+ *
+ * This method returns an Error. The list of entries in this error will be empty is the
+ * expansion was successful.
+ */
+Error SetupProjectParameters::expandBuildConfiguration(Settings *settings)
+{
+ Error err;
+
+ // Generates a full build configuration from user input, using the settings.
+ QVariantMap expandedConfig = d->buildConfiguration;
+
+ const QString buildVariant = expandedConfig.value(QLatin1String("qbs.buildVariant")).toString();
+ if (buildVariant.isEmpty())
+ throw Error(Internal::Tr::tr("No build variant set."));
+ if (buildVariant != QLatin1String("debug") && buildVariant != QLatin1String("release")) {
+ err.append(Internal::Tr::tr("Invalid build variant '%1'. Must be 'debug' or 'release'.")
+ .arg(buildVariant));
+ return err;
+ }
+
+ // Fill in buildCfg in this order (making sure not to overwrite a key already set by a previous stage)
+ // 1) Things specified on command line (already in buildCfg at this point)
+ // 2) Everything from the profile key
+ QString profileName = expandedConfig.value("qbs.profile").toString();
+ if (profileName.isNull()) {
+ profileName = settings->defaultProfile();
+ if (profileName.isNull()) {
+ const QString profileNames = settings->profiles().join(QLatin1String(", "));
+ err.append(Internal::Tr::tr("No profile given and no default profile set.\n"
+ "Either set the configuration value 'defaultProfile' to a "
+ "valid profile name\n"
+ "or specify the profile with the command line parameter "
+ "'profile:name'.\n"
+ "The following profiles are available:\n%1")
+ .arg(profileNames));
+ return err;
+ }
+ expandedConfig.insert("qbs.profile", profileName);
+ }
+
+ // (2)
+ const Profile profile(profileName, settings);
+ const QStringList profileKeys = profile.allKeys(Profile::KeySelectionRecursive);
+ if (profileKeys.isEmpty()) {
+ err.append(Internal::Tr::tr("Unknown or empty profile '%1'.").arg(profileName));
+ return err;
+ }
+ foreach (const QString &profileKey, profileKeys) {
+ if (!expandedConfig.contains(profileKey))
+ expandedConfig.insert(profileKey, profile.value(profileKey));
+ }
+
+ if (d->buildConfiguration != expandedConfig) {
+ d->buildConfigurationTree.clear();
+ d->buildConfiguration = expandedConfig;
+ }
+ return err;
}
/*!
diff --git a/src/lib/tools/setupprojectparameters.h b/src/lib/tools/setupprojectparameters.h
index 984b2c208..d996bcdf7 100644
--- a/src/lib/tools/setupprojectparameters.h
+++ b/src/lib/tools/setupprojectparameters.h
@@ -31,12 +31,17 @@
#include "qbs_export.h"
+#include <tools/error.h>
+
#include <QProcessEnvironment>
#include <QSharedDataPointer>
#include <QStringList>
#include <QVariantMap>
namespace qbs {
+
+class Settings;
+
namespace Internal { class SetupProjectParametersPrivate; }
class QBS_EXPORT SetupProjectParameters
@@ -62,6 +67,8 @@ public:
QVariantMap buildConfiguration() const;
void setBuildConfiguration(const QVariantMap &buildConfiguration);
+ QVariantMap buildConfigurationTree() const;
+ Error expandBuildConfiguration(Settings *settings);
bool ignoreDifferentProjectFilePath() const;
void setIgnoreDifferentProjectFilePath(bool doIgnore);